I have 2 connections: wlan0 (gw: 192.168.1.1) and eth0 (gw: 192.168.2.1).
My default connection is wlan0, but I wanted some websites load through my eth0, so I set up routing for those websites/IPs like this:
route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
This works, however is not permanent (disappears after reboot). I tried to put this code in /etc/network/interfaces
like this:
up route add -net 31.135.208.0/21 gw 192.168.2.1 dev eth0
but when I restart Ubuntu, it starts without networking (it crashes). I also put these lines into that file:
auto eth0
address 192.168.2.125
gateway 192.168.2.1
netmask 255.255.255.0
but still system boots without networking.
Currently I have put route
command into /etc/rc.local
, it works, but it is not permanent, because when I restart/re-connect my eth0 (for some reason), routing disappears.
Some notes:
I have long list of IPs to route.
My router, which I connected eth0 is set to DHCP.
I tried to connect eth0 both static and DHCP way.
Thanks for you help!
[ "$IFACE" != "eth0" ] || exit 0
before the route add lines. – Greg Oct 15 '13 at 10:06ps faux | grep -i network
,cat /etc/NetworkManager/dispatcher.d/01ifupdown | grep run-parts
andnm-tool
– chaos Oct 16 '13 at 08:36/etc/network/interfaces
is wrong. Second, for your concern it isn't recommended to use/etc/network/interfaces
for managing this interface because every time you replug the cable, you need to/etc/init.d/networking restart
to tun the if-up.d script to set the routes again. So, delete everything in the interfaces file relating to the eth0 interface. Then, do a/etc/init.d/networking restart
and/etc/init.d/network-manager restart
and make sure that "Enable Networking" is checked in the NM-Applet. – chaos Oct 17 '13 at 07:27/etc/network/interfaces
I have following only:auto lo iface lo inet loopback
There is nothing relating to eth0.. – Azamat Oct 17 '13 at 22:03