8

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 192.168.1.254) is plugged into a four-port router, 192.168.1.1. 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 10.140.10.100, with the printer on maybe 10.120.50.10.

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?

auto lo
iface lo inet loopback

auto eth0 iface eth0 inet static address 192.168.1.254 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1

auto eth1 iface eth1 inet dhcp

Alexis Wilke
  • 2,787

4 Answers4

3

I did a quick test setup here at home, with a 10.0.1.0 network and a 192.168.43.0 network (the first my usual LAN over Ethernet 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 sue me in case of the other 1%).

two LAN's both pings work

Alexis Wilke
  • 2,787
bacon
  • 158
3

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
192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.22  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. 192.168.43.102 is within the same /24 network (as indicated by the 255.255.255.0 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.

belacqua
  • 23,540
1

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 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 192.168.0.254 dev eth0  proto static 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.20  metric 1 
192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.15  metric 9

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

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

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.

Alexis Wilke
  • 2,787
Léo Lam
  • 1,012
  • 3
  • 12
  • 27
0

I believe the issue you may be having here is that a large institutional network like a school may well use multiple subnets. By default, the second network interface will only become the preferred route for the subnet assigned to you by DHCP.

You should check what the subnet mask being assigned to your eth1 interface by DHCP is by using the following command:

ip addr show dev eth1

To check if the printer belongs to the same subnet you are being assigned by DHCP you can use the following online checker:

https://tehnoblog.org/ip-tools/ip-address-in-cidr-range/

Simply enter the IP address of your school's printer in the first box and the IP address including the /number part from the above command into the second box.

If this tool says that the printer IP address is not in the CIDR range then this is the problem you are having and you will need to manually add a static route via the eth1 interface.

To do this you can figure out the gateway you need to use on the school network by checking the default route the DHCP server is assigning you with the following command.

ip route show dev eth1

Then to add a route to the printer you can use the following command:

ip route add [printerip] via [schoolgateway] dev eth1

You can save yourself doing this every time as /etc/network/interfaces allow you to configure commands to be run when the network interface is brought up using the up option followed by the command to run. This option may be included multiple times if you need to run more than one command eg if you need to add more than one route. Here is an example with one command:

auto eth1
iface eth1 inet dhcp
up ip route add [printerip] via [schoolgateway] dev eth1

Note this will only add a route for the printer and if you need to access other internal services on the school network you may need a broader route or several routes. If this is the case I would suggest checking with your school's IT department as they should be able to inform you what addresses ranges should be routable on the school network and which gateway to use for each address range. You can then add these using as many of the following commands as you need:

ip route add {NETWORK/MASK} via {GATEWAYIP} dev eth1

Again make this automatic by adding them to the end of your /etc/network/interfaces configuration for eth1 in the following form:

up ip route add {NETWORK/MASK} via {GATEWAYIP} dev eth1