Adding additional IPs Print

  • 22

The quickest way to add an IP address on Linux Systemd systems is to use the ip command, for example, to add the IP 1.23.456.789 with a /28 netmask to device eth0, you would do;

   ip addr add 1.23.456.789/28 brd + dev eth0

However, this would be a quick and dirty solution if the IP was temporary and did not need to persist a reboot.

For IPs to persist a reboot, we need to edit the network cards (NIC). In order to do that, we need to verify which interface is in use which can also be done with the ip a command.

As can be seen, the interface device is eth0.

CentOS/RHEL

On rhel distributions, IP addresses are added in files in the following directory:

/etc/sysconfig/network-scripts;ifcfg-ethx

Make a copy of ifcfg-eth0 for each IP you wish to add and name them ifcfg-eth0:x, as shown below.

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:2

The contents of each new copied file will now need to be altered. Change the DEVICE, IPADDR and NETMASK fields accordingly

DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=1.23.456.789
NETMASK=255.255.255.240

Once you’ve added the values to your configuration file, bring the interface up with the ifup command.

ifup eth0:0
ifup eth0:1

Try to get SSH access to the server using the newly-added IP address to make sure it has been correctly added and is properly working.


Ubuntu

On Ubuntu, all the network config is typically stored in one file: /etc/network/interfaces

This file should already exist as it’ll have your existing network configuration in place.

Additional IP addresses should be added underneath the existing configuration with the following syntax:

   auto eth0:1
   iface eth0:1 inet static
      address 1.23.456.789
      netmask 255.255.255.240
gateway 1.23.456.701

Once you’ve added the values to your configuration file, bring the interface up with the ifup command.

ifup eth0:0
ifup eth0:1
Try to get SSH access to the server using the newly-added IP address to make sure it has been correctly added and is properly working.





Was this answer helpful?

Back