How to set up additional IP addresses?

Modified on Sat, 14 Sep at 9:36 PM

Network configuration in Debian/Ubuntu


1 # Add an address to the interface. It will be lost after reboot. 
2 $
 ip addr add 10.1.0.1/24 dev eth0


You can manually specify it in the configuration file: 

nano /etc/network/interfaces/interfaces.d/50-cloud-init (For Debian)


# This file is generated from information provided by the datasource.  Changes
# so it will not persist across an instance reboot.  To disable cloud-init
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
auto lo
iface lo inet loopback
    dns-nameservers 8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
    dns-search justhost.ru

auto eth0
iface eth0 inet static
   
 address 192.168.3.10/24
   
 address 192.168.5.140/24  # Additional IP
    gateway 192.168.3.1

# control-alias eth0
iface eth0 inet6 static
   
 address 2605:e440:1::1:2e6/64
    gateway 2605:e440:1::1


After adding the additional IP address on the network interface, save the file with ctrl + X key combination. 


And enter the command:

$ systemctl restart networking


An additional IP address has been added to the Debian network interface. 


nano /etc/netplan/*.yaml (For Ubuntu)


# This file is generated from information provided by the datasource.  Changes
# so it will not persist across an instance reboot.  To disable cloud-init
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 
2
    ethernets:
        eth0:
            addresses:
            - 192.168.3.10/24
            - 2605:e440:1::1:23/64
            - 192.168.5.140/24 # Additional IP
            gateway4: 
192.168.3.1
            gateway6: 
2301:e320:1::1
            match:
                mac address: 
33:24:43:76:2f:11
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                - 2001:4860:4860::8888
                - 2001:4860:4860::8844
                search:
                - justhost.ru
            set-name: 
eth0


After adding an additional IP address to the network interface, save the file with the ctrl + X key combination. 


You can check the saved settings file with the command:


$ netplan try 


Then, if all is well, apply the settings on the fly:


$ netplan apply 



Network configuration in CentOS.


# Add an address to the interface. It will be lost after reboot.
ip addr add 10.1.0.1/24 dev eth0 
ip -6 addr add 2a00:b700:1::2/64 dev eth0


You can manually specify it in the configuration file. The configuration of network interfaces is stored in /etc/sysconfig/network-scripts/ifcfg-ethX. 

X is the number of the physical interface.


Example file /etc/sysconfig/network-scripts/ifcfg-eth0


How to start editing the file: write the command "nano" before the file itself. Example: nano /etc/sysconfig/network-scripts/ifcfg-eth0 


Additional addresses (aliases) are configured in the ifcfg-ethX:Y files. 

X is the physical interface number, Y is the alias number (numbering from 0).



(ONLY FOR INSTALLING 2,3,4 addresses(and IPV6)! NOT REQUIRED WHEN CONFIGURING A SINGLE IPV6 )


Example file: /etc/sysconfig/network-scripts/ifcfg-eth0:1  


How to start editing the file: write the command "nano" before the file itself. Example: nano /etc/sysconfig/network-scripts/ifcfg-eth0:1


DEVICE=eth0:1
BOOTPROTO=static
IPADDR=
192.168.3.10
NETMASK=
255.255.255.0
ONBOOT=
yes


After adding the additional IP address on the network interface, save the file with ctrl + X key combination. 


And enter the command:


$ systemctl restart networking

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article