LINUX – IP aliasing

To quote mighty Wikipedia: “IP aliasing is associating more than one IP address to a network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose”

Debian, Ubuntu

To perform IP aliasing in Debian based system (assuming you’re using eth0), edit /etc/network/interfaces as follows:

auto eth0:1
iface eth0:1 inet static
address 10.0.0.10
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1

auto eth0:2
iface eth0:2 inet static
address 10.0.0.11
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.1

In the above example we create two virtual NICs out of eth0: eth0:1 10.0.0.10) and eth0:2 (10.0.0.11).

CentOS, RHEL, Fedora and similar

In CentOS, rename /etc/sysconfig/network-scripts/ifcfg-enp0s3 as ifcfg-enp0s3:1 and make a copy as ifcfg-enp0s3:2, and then just change the following lines, respectively:

DEVICE="enp0s3:1"
IPADDR=10.0.0.10

and

DEVICE="enp0s3:2"
IPADDR=10.0.0.11

Once done, restart the network service:

systemctl restart networking