The cart is empty

In modern networking environments, there may be a need to configure multiple IPv4 addresses on a single device. This can be useful for servers hosting multiple services or routing different data streams through various IP addresses. This guide will show you how to add additional IPv4 addresses to Linux in a few simple steps.

Step 1: Check the Current Network Interface Configuration

Before adding a new IP address, it is essential to verify the current network interface setup. Use the following command to do this:

ip addr show

This command will display the current status of all network interfaces on your device. It will show you which interfaces are active and which IP addresses are currently assigned to them.

Step 2: Add an Additional IPv4 Address

To add a new IPv4 address to an existing network interface, use the following command:

sudo ip addr add 192.168.1.100/24 dev eth0

In this command, replace 192.168.1.100/24 with the desired IP address and subnet mask, and eth0 with the name of the network interface to which you want to add the IP address.

Step 3: Verify the Added IP Address

After adding the new IPv4 address, it is important to verify that it has been successfully assigned. You can do this by running the command:

ip addr show dev eth0

If everything was successful, you should see the new IP address listed alongside the existing addresses assigned to the eth0 interface.

Step 4: Permanent IP Address Configuration

IP address configuration using the ip addr add command is temporary. These changes will be lost after a system reboot. To make the IP address addition permanent, you need to edit your system's configuration files. For distributions like Ubuntu or Debian, edit the /etc/network/interfaces file as follows:

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

    post-up ip addr add 192.168.1.101/24 dev eth0
    post-up ip addr add 192.168.1.102/24 dev eth0
    

In this example, we are permanently adding two additional IP addresses (192.168.1.101 and 192.168.1.102) to the eth0 interface. Make sure to adapt these settings to fit your specific needs.

Step 5: Restart the Network Interface

After editing the configuration files, you need to restart the network services for the changes to take effect. You can do this using the following command:

sudo systemctl restart networking

Now all IP addresses should be permanently assigned and available after each system reboot.

Conclusion

Adding additional IPv4 addresses to Linux is a straightforward process that can be done in several ways. This guide has shown you how to add IP addresses both temporarily and permanently. For greater flexibility, you can use various scripts that automate the addition of IP addresses based on specific network needs. With this approach, you can easily manage multiple IP addresses on a single device and customize your network interface as required.