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, which has access to Internet; and another local network B with IP, 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., -- 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., cannot access my computer ( at all.

Interestingly, computers in the same subnet of network B (e.g., can access my computer without any problem, and can also access (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

auto em2
iface em2 inet static
metric 1

How can I make the computer use 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

You'll need to add a route to

route add -net netmask gw dev em2 (untested)

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

up route add -net netmask gw 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.