Introduction
In this article, we will discuss how to route traffic using static IP and DHCP on Ubuntu 22.04 with two network interfaces: eno1 and wls4. By the end of this article, you will have a solid understanding of how to configure your Ubuntu system to route traffic using static IP and DHCP.
Prerequisites
Before we begin, make sure you have the following:
- A physical computer running Ubuntu 22.04
- Two network interfaces: eno1 and wls4
- eno1 configured with a public static IP address (e.g., xxx.xxx.xxx.xx)
- wls4 configured to use DHCP
Static IP Configuration for eno1
To configure a static IP address for eno1, follow these steps:
- Open the terminal and enter the following command to edit the network interfaces file:
sudo nano /etc/network/interfaces
- Add the following lines to the file, replacing xxx.xxx.xxx.xx with your static IP address:
auto eno1
iface eno1 inet static
address xxx.xxx.xxx.xx
netmask 255.255.255.0
gateway xxx.xxx.xxx.1
- Save and close the file.
- Restart the networking service by entering the following command:
sudo systemctl restart networking
DHCP Configuration for wls4
To configure wls4 to use DHCP, follow these steps:
- Open the terminal and enter the following command to edit the network interfaces file:
sudo nano /etc/network/interfaces
- Add the following lines to the file:
auto wls4
iface wls4 inet dhcp
- Save and close the file.
- Restart the networking service by entering the following command:
sudo systemctl restart networking
Routing Traffic
Now that we have configured eno1 with a static IP address and wls4 to use DHCP, we can move on to routing traffic. To do this, we will use the ip command.
First, we need to identify the network interfaces that are connected to the internet. To do this, enter the following command:
ip route
This will display a list of network interfaces and their corresponding IP addresses. Look for the interface that has a gateway address. This is the interface that is connected to the internet.
Next, we need to add a route for the other network interface. To do this, enter the following command, replacing eno1 and xxx.xxx.xxx.yy with the appropriate values:
sudo ip route add xxx.xxx.xxx.yy/24 via xxx.xxx.xxx.xx dev eno1
This will add a route for the other network interface to use eno1 to reach the specified subnet.
In this article, we have discussed how to route traffic using static IP and DHCP on Ubuntu 22.04 with two network interfaces: eno1 and wls4. We have covered the following key concepts:
- Configuring a static IP address for eno1
- Configuring wls4 to use DHCP
- Routing traffic using the
ipcommand