I'm trying to configure my wireless network to use gateway 10.0.1.252 when accessing IP addresses that start with 10.0.0.
I followed a few explanations on how to do it with the interfaces file but without success.
This is the content of my initial /etc/network/interfaces file:
auto lo
iface lo inet loopback
After several hours searching and reading I made it look like this:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth1
iface eth1 inet static
address 10.0.1.171
netmask 255.255.255.0
broadcast 10.0.1.255
gateway 10.0.1.254
# static route
up route add -net 10.0.0.0/24 gw 10.0.1.252 dev eth1
Mentioned configuration works after I restart networking and until I restart Ubuntu. After I restart Ubuntu, I lose network manager and cannot connect to Internet or intended addresses 10.0.0.x.
What am I doing wrong, or is there a simpler way of setting a permanent route in newer versions of Ubuntu?
Just to mention I'm configuring wireless connection, because I do not use wired one.
UPDATE 1: (~$ ifconfig)
eth0 Link encap:Ethernet HWaddr 00:24:81:64:9a:5c
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:17
eth1 Link encap:Ethernet HWaddr 00:21:00:d8:25:45
inet addr:10.0.1.171 Bcast:10.0.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:ff:fed8:2545/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:17
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:284 errors:0 dropped:0 overruns:0 frame:0
TX packets:284 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:21280 (21.2 KB) TX bytes:21280 (21.2 KB)
UPDATE 2: (~$ route -n)
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 10.0.1.252 255.255.255.0 UG 0 0 0 eth1
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth1
0.0.0.0 10.0.1.254 0.0.0.0 UG 100 0 0 eth1
UPDATE 3:
I realised that there is a problem with this code:
iface eth1 inet static
address 10.0.1.171
netmask 255.255.255.0
broadcast 10.0.1.255
gateway 10.0.1.254
If I comment it out I get network manager and Internet access, but not my desired route.
Best Answer
If you've configured the network through ifupdown (i.e. in
/etc/network/interfaces
), and it works when you start networking manually but not after a fresh boot, one possibility is that your setup is bringing up the network correctly, and then some other system component reconfigures the network. The obvious suspect is Network Manager. Make sure that in/etc/NetworkManager/nm-system-settings.conf
, under[ifupdown]
, you havemanaged=false
. (It's the default, at least under Ubuntu 10.04, but maybe that changed in 10.10 or you changed it in previous experiments with Network Manager.)If you want to stick with Network Manager, you can tell it to add the extra route. As of Ubuntu 10.04 (other distributions might not set up Network Manager in the same way), Network Manager executes the ifupdown scripts in
/etc/network/if-*.d/
. The role of these scripts is similar to theup
,down
,pre-up
andpost-down
directives in/etc/network/interfaces
(which Network Manager does not execute). Comment out all mentions ofeth1 from
/etc/network/interfaces` so that Network Manager will manage this interface.The scripts are documented in the interfaces(5) man page. They are executed in an environment containing information about the connection being started or stopped, in particular
$IFACE
is the interface name. So put the following script in/etc/network/if-up.d/zzzz-milan-wireless-route
:Make it executable:
chmod 755 /etc/network/if-up.d/zzzz-milan-wireless-route
. The next time Network Manager brings up the network, you should have your default route.