I want to use Ubuntu 10.10 Server in a classroom, a computer lab whose bandwidth is provided by a local cable ISP. That's no problem, though the school network has an IP printer that I want to use. I cannot reach the printer through the cable Internet. But, I have two network cards.

How is it possible to use both networks at once?

eth0 (static is plugged into a four-port router, On the public side of the four-port router is Internet provided by the cable company. I also have the classroom workstations plugged into a switch. The switch is plugged into the four-port router. The whole classroom is wired into the cable Internet.

The other NIC, eth1, could it be plugged into an Ethernet jack in the wall? It uses the school network, and I might receive by DHCP an IP address like, with the printer on maybe

I was thinking about installing the printer on the server so that it could be shared with the workstations. But how does this work? Can I just plug eth1 into the school network and access both LANs?

Thanks for any insight.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

auto eth1
iface eth1 inet dhcp
  • Is the dhcp server for eth1 supplying default route info? – belacqua Feb 5 '11 at 22:18
  • Yes, it is giving a default route. – user8290 Feb 6 '11 at 13:45
  • Here is a related post: 2 internet connections on a single PC – Lucio Feb 25 '13 at 19:53

I'm assuming you don't have any routes set locally on the Ubuntu box.

If your target IP address shares address space with the directly connected interface, it should by default route to the correct IP.

You will be able to see what networks your interfaces 'own' with ip route show.
For example,

$ ip route show dev eth0  proto kernel  scope link  src  metric 1 

In this case, a 192.168.1.x/24 address (eth0) would be the gateway for the the same 192.168.1.x/24. A 10.x.x.x address will be the gateway for all 10.x.x.x that fall under its subnet mask. This is actually what you see in bacon's answer. It shows a ping test where the gateway and target IP addresses are in the same network -- the network masks match exactly. is within the same /24 network (as indicated by the network mask) as the interface.

The only problem would be confusion over other subnets -- the interface connecting to the outbound ISP path would need to be the 'gateway of last resort' for all routes that aren't directly connected.

You can get this to work, but you should do a quick test to make sure you can reach the resources you need. You might find that you need to use route add to add a default route.

  • I do have a default route, which I added in the question. So the trick is to remove the default route? – user8290 Feb 5 '11 at 13:37
  • @christoper Actually, the default route should be there. The subnets of the private IP space interfaces 192.168.x.x and 10.x.x.x should match first on any traffic going to their subnets, and traffic that doesn't match should then use the default route, because there is no better explicit route set. – belacqua Feb 5 '11 at 22:09

I did a quick test setup here at home, with a network and a network (the first my usual lan over ehternet the second my phone over wireless.) I have no problem pinging to either network, so i would expect the computer to be able to find printers on both networks since it automatically takes the correct network interface. I'm 99% confident you will have no problem at all. (don't sew me in case of the other 1%) please let us know if it's working :-)

two lan's both pings work

  • Were you using DHCP for both interfaces? – user8290 Feb 5 '11 at 13:40
  • Yes, they are both dhcp. – bacon Feb 5 '11 at 15:11

Just to complete the other answers: in case your PC is unable to connect to your device, you can “force” the network device to use for a particular address and/or subnet by adding a route, without messing with default routes.

Here are my routes before adding a specific route for one of my devices on Wi-Fi:

# Note: ro is a shorthand for route.
$ ip -4 ro
default via dev eth0  proto static dev eth0  proto kernel  scope link  src  metric 1 dev wlan0  proto kernel  scope link  src  metric 9

Notice that they both use the same subnet and that pinging (the device on the Wi-Fi network only) fails (not sure if that's normal).

Using sudo ip -4 ro add dev wlan0, I added a route specifying that wlan0 should be used for

I am now able to connect to that host using the wlan0 interface, while everything else still goes through eth0 (which is much faster!). Deleting the newly added route is as simple as replacing add by del.

It seems that it is also possible to manage routes from the graphical network manager, although using the command line is much faster.

Your Answer

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