1

My computer is running Ubuntu Server 14.04, and is connected to two networks at the same time (i.e., local network A with IP 192.168.1.30, which has access to Internet; and another local network B with IP 10.73.9.30, which does not have an Internet access). Most traffic should go through network A, however, I also need my computer to communicate with other computers in the network B (e.g., 10.84.1.8 -- yes, actually not in the same subnet of network B). I have set metric in the /etc/network/interfaces file so that I can set two gateways, but it seems that only the first gateway works, and computers in other subnet of network B (i.e., 10.84.1.8) cannot access my computer (10.73.9.30) at all.

Interestingly, computers in the same subnet of network B (e.g., 10.73.9.3) can access my computer without any problem, and 10.84.1.8 can also access 10.73.9.3 (which is only connected to network B). Therefore, I think the cause of the network issues on my computer is that it is connected to two networks. Here is my /etc/network/interfaces file:

auto lo
iface lo inet loopback

auto em1
iface em1 inet static
metric 0
address 192.168.1.30
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1

auto em2
iface em2 inet static
metric 1
address 10.73.9.30
netmask 255.255.255.0
gateway 10.73.9.1

How can I make the computer use 10.73.9.1 as the default gateway for 10\.*\.*\.* IP addresses?

  • There cannot be two default gateways for the same host. – Rishav Ambasta May 2 '16 at 12:21
2

You'll need to add a route to 10.0.0.0/8:

route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.73.9.1 dev em2 (untested)

To make it permanent add it to your interfaces config in the em2 section:

up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.73.9.1 dev em2

Just for understanding: Your computer knows where to send packets in your local net. For everything else, he needs routes. The default route is used if there isn't a more specific route. Now you have told him to send all packets for that subnet over a different router, that probably knows where to send the packets. (or knows who else might know.)

  • Wow... it works! Thanks so much! Just wondering whether I need to do it again after rebooting? Which file has this new route be written to? @Jakob Lenfers – Runner May 2 '16 at 14:33
  • I updated my answer with information about that. – Jakob Lenfers May 2 '16 at 14:39

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.