Sometimes you might have a situation where you would want to have access to two or more networks simultaneously using the same computer. Linux needs to be configured to allow this via something called routes…
In this short tutorial I’ll explain how to setup custom routes to allow you to be able to access multiple networks from two or more different LAN or Wifi connections at the same time.
The Networking Problem
In Windows you can have multiple networks without bridging them together and still have access to both networks from the same computer, Linux on the other hand will allow you to have multiple networks but will not allow you to use both of them at the same time by default. Thus, to resolve this issue we need to setup routes.
Using routes to allow access to two or more networks
For this tutorial i would use the network 192.168.10.0 as my primary network and 192.168.2.0 as my secondary network. By default without any configuration Linux Mint will use only my primary network and I will not be able to access any PC or resource on the secondary network.
For more information go look at our Setting up a Network guide
For this setup we will use the Linux Mint Cinnamon Network Manager, From the desktop in the bottom right hand corner near the time left click on the network icon and select the Network settings option. The Linux Network Manager window will open listing your available networks.
In the picture below you can see I have two LAN (Local Area Network) Adapters that are both on different networks.
Lets configure custom networking routes for each networking adapter
Select your Ethernet or Wifi connection from the list on the left in the Linux Network Manager, in my case its the second one in the list called enp7s0.
Next select the Gear Icon to configure this network adapters settings then select the IPv4 section in the list.
In my case I configured to use a static IP address but you can leave it to DHCP if you want your router to manage the IP addresses. The DNS is set to auto or you can specify your DNS server IP as well.
Lets configure custom routes for the Primary LAN Network Adapter
Scroll down a little and look for the Routes section. By default, your routes will or should be empty. Since we are going to priorities this Network Interface we will need to setup its route as I did below. we use 192.168.10.0 as the address to specify the network we wish to route to. the netmask most commonly used for home and small business networks are 255.255.255.0 or 24. the Gateway is your Network’s router address and the Metric is the priority the network will be used. In my case its the primary one so i set the metric to the value of 1 as seen below.
Apply and Close this configuration. Next we will edit the secondary Network interface.
Back on the main Network Manager Screen select your secondary network and like before, once selected click on the gear icon to edit the second LAN adapter’s settings. In my case its the LAN Interface adapter called enp6s0
Lets configure custom routes for the Secondary LAN Network Adapter
Again, select the IP4 section in the left hand side list, make sure the Automatic Routes setting is set to Disabled.
Now, we need to specify that this adapter will route to the primary adapter. set the address again to 192.168.10.0, with the netmask of either 255.255.255.0 or 24
The Gateway should be the primary routers IP address and the metric is set to the value if 2. Remember we configures the primary LAN interface to have a metric of 1.
Once this is done you can apply and close this window.
To make sure the settings apply you need to either restart the PC or disable and enable all network interfaces.
In a situation where you have multiple networks and wish to use them all at the same time you will need to setup and configure routes in Linux.
Metric score is used to tell Linux which interface order it would follow and can be used to specify which interface is the primary LAN interface you wish to use.
Thus enabling you to use two or more networks and access both of them and their resources at the same time.