Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My system has 3 interfaces. These are eth0, eth1 and usb0.

eth0 is linked to my router and is the line I want to be used by default. eth1 is un used. usb0 is a 3G phone that's tethered.

My issue is that I wan't to be able to access the internet via both eth0 and usb0 at the same time. Currently as soon as I change the gateway to match each interface, the other connection no longer responds.

I have tried adding metric values on my interfaces file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0 usb0
iface lo inet loopback
        allow-hotplug eth0 usb0

# The primary network interface
iface eth0 inet static
        address 192.168.1.67
        netmask 255.255.255.0
        broadcast 192.168.1.254
        network 192.168.1.0
        post-up route add default gw 192.168.1.254 metric 1
        pre-down route del default gw 192.168.1.254


iface usb0 inet static
        address 192.168.42.86
        netmask 255.255.255.0
        broadcast 192.168.42.254
        network 192.168.42.0
        post-up route add default gw 192.168.42.129 metric 2
        pre-down route del default gw 192.168.42.129

Unfourtunately when it starts up, only the usb0 is actually accessible. When I check the routes, I can see that there is no gateway for the eth0.

~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.42.129  0.0.0.0         UG    0      0        0 usb0
0.0.0.0         192.168.42.129  0.0.0.0         UG    2      0        0 usb0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.42.0    0.0.0.0         255.255.255.0   U     0      0        0 usb0

And when I try to access the internet via each of them. eth0 gives me the following:

~# ping -I eth0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.67 eth0: 56(84) bytes of data.
From 192.168.1.67 icmp_seq=1 Destination Host Unreachable
From 192.168.1.67 icmp_seq=2 Destination Host Unreachable
From 192.168.1.67 icmp_seq=3 Destination Host Unreachable
From 192.168.1.67 icmp_seq=4 Destination Host Unreachable
From 192.168.1.67 icmp_seq=5 Destination Host Unreachable
From 192.168.1.67 icmp_seq=6 Destination Host Unreachable
^C
--- 8.8.8.8 ping statistics ---
7 packets transmitted, 0 received, +6 errors, 100% packet loss, time 6030ms

However, usb0 has internet access.

~# ping -I usb0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.42.86 usb0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=43 time=188 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=43 time=127 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=43 time=108 ms
64 bytes from 8.8.8.8: icmp_req=4 ttl=43 time=98.3 ms
64 bytes from 8.8.8.8: icmp_req=5 ttl=43 time=96.9 ms
64 bytes from 8.8.8.8: icmp_req=6 ttl=43 time=165 ms
64 bytes from 8.8.8.8: icmp_req=7 ttl=43 time=226 ms
^C
--- 8.8.8.8 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6002ms
rtt min/avg/max/mdev = 96.981/144.575/226.027/46.357 ms

I can't see where I'm going wrong, and on some occasions, though not often, I get the following appearing in my ping:

64 bytes from 8.8.8.8: icmp_req=3 ttl=43 time=132 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=43 time=672 ms (DUP!)
64 bytes from 8.8.8.8: icmp_req=3 ttl=43 time=1212 ms (DUP!)

Any assistance would be greatly appreciated.

share|improve this question
    
1) route is obsolete, use ip route 2) the keyword you need is "policy routing". The setup has been described multiple time here or on SuperUser. –  BatchyX Sep 2 '13 at 21:20
    
It won't let me add that as a tag unfortunately. I had done a lot of searching and while I found similar things, nothing that quite covered the issues that I was having, though that may have been down not knowing exactly what to search for. –  loony383 Sep 3 '13 at 11:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.