0

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?

  • Just 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. – Eddie Dunn Nov 23 '15 at 15:07
  • No dice. I changed the netmask but route complained route: netmask doesn't match route address – James Nov 23 '15 at 15:30
  • Well 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. – Eddie Dunn Nov 23 '15 at 15:41
  • 2
    Try putting it in the iface em1:0 block, and try changing your post-up to an up. You might also want to try the iproute syntax of ip route add x.x.x.x/32 via 172.16.0.1 instead. – Zoredache Nov 23 '15 at 17:36
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.