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:


Anyone help me?

User avatar
Posts: 40534
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Two internet connections

Fri Jun 29, 2018 3:57 pm

The gateway has a lower metric value so the kernel will always pick that ahead of the gateway. It gets a lower metric because eth0 is usually faster than wlan0.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

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

Re: Two internet connections

Fri Jun 29, 2018 5:22 pm

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 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 dev wlan0 proto kernel scope link src table wlan
# ip route add default via table wlan
Insert a source routing rule
# ip rule add from 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 -i eth0
traceroute -i wlan0

And repeat after changes.

Return to “Troubleshooting”