Sometimes you need to add an alias on the interface. In CentOS 8 add second IP can be done in several ways.
1 ifconfig
2 /etc/sysconfig/network-scripts/
Adding an alias with ifconfig
To get started, let’s look at the available interfaces in the system using ifconfig:
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.17 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::596e:2b87:da14:f0e8 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:57:a3:0e txqueuelen 1000 (Ethernet)
RX packets 110694 bytes 148771849 (141.8 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 41723 bytes 4715357 (4.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 6672 (6.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 6672 (6.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
In the example, this is eth0. To add a second IP address to CentOS 8 via ifconfig, just run the command:
ifconfig eth0:0 192.168.88.150 netmask 255.255.255.0 up
where eth0 – interface
:0 – number of alias
192.168.88.150 – IP
255.255.255.0 – mask
Check with ifconfig:
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.17 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::596e:2b87:da14:f0e8 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:57:a3:0e txqueuelen 1000 (Ethernet)
RX packets 110937 bytes 148795841 (141.9 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 41821 bytes 4728135 (4.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.150 netmask 255.255.255.0 broadcast 192.168.88.255
ether 00:15:5d:57:a3:0e txqueuelen 1000 (Ethernet)
To remove an alias, just down the interface (not eth0, but eth0: 0!):
ifconfig eth0:0 down
It should be noted that with this you may in CentOS 8 add second IP address, but it is not saved and after the system reboot the alias will disappear. To avoid this, we will use the second method.
CentOS 8 add second IP through the configuration file
By analogy with the main interface, we create a configuration file for the alias:
nano /etc/sysconfig/network-scripts/ifcfg-eth0:0
And configure the settings:
DEVICE=eth0:0
BOOTPROTO=static
IPADDR=192.168.88.150
NETMASK=255.255.255.0
ONBOOT=yes
In order to raise the alias, you must run the command:
ifconfig eth0 up
Yes, it is the main interface. When trying to run ifup eth0: 0 we get an error:
Error: unknown connection '/etc/sysconfig/network-scripts/ifcfg-eth0:0'.
By executing ifconfig eth0 up and ifconfig eth0 down && ifconfig eth0 up you can control / reload the interfaces. But I couldn’t manage separately eth0:0. If anyone knows how – write in the comments.