Ubuntu System: Configuring Ethernet Interface (eth0) with Static Address Ignoring Default Route Provided by DHCP Server
In a typical Ubuntu system, the Ethernet interface (eth0) is connected to a router that acts as a DHCP server, providing a default route. However, there might be situations where you want to set eth0 to use a static IP address and ignore the default route provided by the DHCP server.
Understanding the Concepts
Before we proceed, let's understand the key concepts involved:
- DHCP (Dynamic Host Configuration Protocol): A network protocol used on Internet Protocol (IP) networks for automatically assigning IP addresses and other communication parameters to devices connected to the network using a client-server architecture.
- Static IP Address: An IP address that is manually configured and does not change automatically.
- Default Route Provided by DHCP Server: The default route is the path to the Internet. When a device is connected to a network, the DHCP server provides the default route to the device, which is typically the IP address of the router.
Configuring Ethernet Interface with Static Address
To configure the Ethernet interface (eth0) with a static IP address, follow the steps below:
- Open the terminal.
- Edit the network interfaces file by running the following command:
sudo nano /etc/network/interfaces
This will open the network interfaces file in the Nano text editor. Scroll down to the section that looks like this:
# The primary network interface
auto eth0
iface eth0 inet dhcp
Replace the contents of this section with the following:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Make sure to replace the IP addresses and netmask with the appropriate values for your network.
- Save and close the file by pressing Ctrl + X, then Y, and then Enter.
- Restart the networking service by running the following command:
sudo systemctl restart networking
Ignoring Default Route Provided by DHCP Server
To ignore the default route provided by the DHCP server, follow the steps below:
- Edit the network interfaces file again by running the following command:
sudo nano /etc/network/interfaces
Scroll down to the section that looks like this:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Add the following line to the end of this section:
up route del default gw 192.168.1.1
This will delete the default route provided by the DHCP server.
- Save and close the file by pressing Ctrl + X, then Y, and then Enter.
- Restart the networking service by running the following command:
sudo systemctl restart networking
In this article, we have covered the following topics:
- Understanding the key concepts involved in configuring the Ethernet interface with a static IP address and ignoring the default route provided by the DHCP server.
- Configuring the Ethernet interface with a static IP address.
- Ignoring the default route provided by the DHCP server.