Add static route on Ubuntu 14.04 server
15,112
post-up route add -net XXX.XXX.XXX.XXX netmask 255.255.255.255 gw 172.16.0.1 remove post-up and change it to "up"
up route add -net XXX.XXX.XXX.XXX netmask 255.255.255.255 gw 172.16.0.1 after that, ifdown em1:0 and ifup em1:0 or u can restart networking.service cheer.
Related videos on Youtube
Author by
James
Updated on September 18, 2022Comments
-
James over 1 year
I have set up Ubuntu 14.04 server on a machine and configured /etc/network/interfaces with two gateways. The default one is em1 which is fine, but I need traffic to a specific IP address on the internet to be sent via the other gateway. The following command works from the command line:
sudo route add -net XXX.XXX.XXX.XXX netmask 255.255.255.255 gw 172.16.0.1
but adding it to /etc/network/interfaces does not work on reboot:
# 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 iface lo inet loopback # The primary network interface auto em1 iface em1 inet static address 10.0.2.251 netmask 255.255.255.0 gateway 10.0.2.1 dns-nameservers 8.8.8.8 8.8.4.4 auto em1:0 iface em1:0 inet static address 172.16.1.6 netmask 255.255.0.0 gateway 172.16.0.1 dns-nameservers 8.8.8.8 8.8.4.4 post-up route add -net XXX.XXX.XXX.XXX netmask 255.255.255.255 gw 172.16.0.1
Can anyone help?
-
Eddie Dunn over 8 yearsJust for grins can you try it with a 30 bit (255.255.255.252) mask? I just found this: askubuntu.com/questions/560616/… that indicates it may be a problem with the 32 bit mask specifically. Not a fix but maybe more focus on the problem.
-
James over 8 yearsNo dice. I changed the netmask but route complained route: netmask doesn't match route address
-
Eddie Dunn over 8 yearsWell you would need to make it match for the network too. without knowing more of the IP I can;t tell what that should be.
-
Zoredache over 8 yearsTry putting it in the
iface em1:0
block, and try changing yourpost-up
to anup
. You might also want to try the iproute syntax ofip route add x.x.x.x/32 via 172.16.0.1
instead.
-