woodea2
Posts: 1
Joined: Fri Jun 29, 2018 3:13 pm

Two internet connections

Fri Jun 29, 2018 3:25 pm

Hello everyone,
I was looking for a similar problem but I did't find.

I have one raspberry pi 2 with ethernet port and wlan (via usb). I connect ethernet to lan network with access to internet and wireless to another local network with internet. The external IP's are diffrent. I would like to get remote access to raspberry form two internet connections at the same time.

Now i can connect to the first but now to second. When i change default gateway i can connect via second network but still not with one network in the same time.

My route looks like:

Image

Anyone help me?

User avatar
DougieLawson
Posts: 35373
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Two internet connections

Fri Jun 29, 2018 3:57 pm

The 172.16.0.1 gateway has a lower metric value so the kernel will always pick that ahead of the 192.168.5.1 gateway. It gets a lower metric because eth0 is usually faster than wlan0.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pksato
Posts: 295
Joined: Fri Aug 03, 2012 5:25 pm
Location: Brazil

Re: Two internet connections

Fri Jun 29, 2018 5:22 pm

Hi,
For output connection route metric and routing table are enough.
But, for input, can have a problem, connection from second interface return using same routing decision as output, on most case client reject the connection assuming that is a spoofed connection. Or redirection just not work.
To solve it is necessary to ensure that connection coming from a interface return from its self. Routing from source coming to rescue.
Assuming wlan0 as secondary connection. and 192.168.5.55 as wlan0 ip.

Code: Select all

Name a routing table
# echo "201 wlan" >>/etc/iproute2/rt_tables
copy relevant routing from main to new table
# ip route add 192.168.5.0/24 dev wlan0 proto kernel scope link src 192.168.5.55 table wlan
# ip route add default via 192.168.5.1 table wlan
Insert a source routing rule
# ip rule add from 192.168.5.55/24 lookup table wlan
A trick, use  ip route show to list main routing table
You can copy a entire line to add command of ip route add
To list a routing tabel of wlan
# ip route show table wlan
To list routing rules
# ip rule list
Before change routing table, copy result of these tree commands.
traceroute 8.8.8.8
traceroute -i eth0 8.8.8.8
traceroute -i wlan0 8.8.8.8

And repeat after changes.

Return to “Troubleshooting”