How to configure IP Aliasing in CentOS?

From LHYcloud Docs
Jump to navigation Jump to search

System Requirements

  1. Operating System: CentOS or Fedora 25 and earlier
  2. An additional IP address or block
  3. root access to the server
  4. Basic networking and administration knowledge

Prerequisites

  • Deploy a new CentOS 7/8 or Fedora 25 and earlier server

Configuring IP Aliasing

We will be assuming the following things in these docs:

Primary IP Address: 192.168.2.1
Additional IP Address: 192.168.2.2
Network Interface: eth0
  1. Log in to the server as the root user via SSH or VNC access.
  2. Run the command ip addr show to view the current network interfaces and their configurations.
  3. You can either make a temporary link which will be reset after a system reboot or make a permanent link instead. (Permanent Link is recommend on LHYcloud servers or any remote server)

Making a temporary IP Aliasing link:

  1. Run the command ip addr add [alias_IP]/[subnet_mask] dev [interface] to add an IP alias to the desired interface. For example:
ip addr add 192.168.2.1/32 dev eth0

Repeat this step for each additional IP address or subnet you want to add as an alias.

To know more about your Subnet Mask, you can refer to this RIPE cheatsheet.

Making a permanent IP Aliasing link:

  • Make a copy of the source file /etc/sysconfig/network-scripts/ifcfg-[interface] so that you can use it as a template:
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
  • You can now modify the [interface]:0 file in order to replace the IP Address or subnet:
nano /etc/sysconfig/network-scripts/ifcfg-eth0:0
  • Edit the following details in the file and remove rest of the lines: (Device name, Additional IP Address, Subnet mask)
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=none # For some network configurations, it may be "static"
IPADDR=192.168.2.2
NETMASK=255.255.255.255
  • Save and exit the configuration file. If you have more IP addresses or subnets, you can create more network files using the same template like [interface]:1 or [interface]:0 .
  • Restart the network services with the command systemctl restart network. (If you are unsure about your setup and wondering if the link will come UP or the whole network will go down, use the following command instead ifup eth0:0)
  • Verify that the IP aliases are now active on the server by running the command ip addr show.