Configuring Multiple IP Addresses on a Single Network Interface in CentOS
Note: The multiple IP addresses must be in the same subnet to avoid multi-gateway issues. For example, if the subnet is 192.168.1.0/24 with gateway 192.168.1.1, you can assign IP addresses like 192.168.1.2 through 192.168.1.254.
To configure multiple IP addresses on a single network interface in CentOS, follow these steps:
1. Check Current Network Configuration
First, view the current network configuration to identify your interface name (e.g., eth0, ens33).
ip addr
2. Edit Network Configuration
CentOS 7 and later use nmcli (NetworkManager command-line tool) or direct editing of configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-<interface>). For newer versions, nmcli is recommended.
Using nmcli to Configure Multiple IPs
-
View existing connecsions:
nmcli con show -
Add an IP address to an existing connection:
nmcli con mod <connection-name> +ipv4.addresses <IP-address>/<prefix>For example, to add IP
192.168.1.100/24to connectionens33:nmcli con mod ens33 +ipv4.addresses 192.168.1.100/24 -
Apply the changes:
nmcli con up <connection-name>Example:
nmcli con up ens33
Editing Configuration Files (Traditional Method)
For CentOS 7 and earlier, or if you prefer direct editing:
- Edit the interface configuration file, e.g.,
/etc/sysconfig/network-scripts/ifcfg-ens33. - Add multiple IP addresses using the following syntax:
DEVICE=eth0 BOOTPROTO=static ONBOOT=yes IPADDR0=192.168.1.101 NETMASK0=255.255.255.0 GATEWAY0=192.168.1.1 IPADDR1=192.168.1.102 NETMASK1=255.255.255.0 GATEWAY1=192.168.1.1 IPADDR2=192.168.1.103 NETMASK2=255.255.255.0 GATEWAY2=192.168.1.1 - Save the file and restart the network service or reboot:
Alternatively, restart the interface:systemctl restart network # or reboot: systemctl rebootifdown eth0 && ifup eth0
3. Verify Configuration
Use ip addr or ifconfig to verify that the new IP addresses are active.
Notes:
- For CentOS 7 and later, prefer
nmclior NetworkManager over manual configuration files to avoid issues. - For newer distributions like CentOS Stream or Fedora, refer to the latest documentation and use modern tools like
nmcli.