For years, RHEL/CentOS administrators have relied on interface alias files (like ifcfg-eth0:1) to configure additional IP addresses. A typical alias file would contain:
DEVICE=eth0:1 BOOTPROTO=static IPADDR=192.168.1.100 NETMASK=255.255.255.0 ONBOOT=yes
Red Hat's documentation now recommends using the ip
command from iproute2 package instead. The basic syntax for adding an IP address is:
ip addr add 192.168.1.100/24 dev eth0
However, this change isn't persistent across reboots. Here's how to make it permanent.
Even when using ip
command, we still need the network-scripts infrastructure for persistence. Create or modify these files:
# /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.1.10 NETMASK=255.255.255.0 IPADDR1=192.168.1.100 PREFIX1=24
For more advanced configurations, create a rule file in /etc/sysconfig/network-scripts/rule-eth0
:
from 192.168.1.100 table 100
And a corresponding route file in /etc/sysconfig/network-scripts/route-eth0
:
192.168.2.0/24 via 192.168.1.1 table 100
After making changes, restart networking and verify:
service network restart ip addr show eth0
You should see all configured IP addresses listed under the eth0 interface.
When migrating from alias files to this method:
- Remove old ifcfg-eth0:X files
- Consolidate all IPs into the main interface file
- Test connectivity before rebooting
- Update any firewall rules referencing specific aliases
Traditional RHEL/CentOS systems have long relied on ifcfg-ethX:Y
files in /etc/sysconfig/network-scripts/
to configure IP aliases. While this method still works, Red Hat's documentation explicitly recommends using the modern ip
command from iproute2 for managing multiple IP addresses on a single interface.
The ip
command provides more flexibility than the legacy aliasing method. Instead of creating virtual interfaces like eth0:1
, we add secondary addresses directly to the main interface:
# Temporary addition (won't survive reboot)
sudo ip addr add 192.168.1.100/24 dev eth0
To persist these configurations across reboots in RHEL/CentOS 6, we need to modify network configuration files:
- Create or edit
/etc/sysconfig/network-scripts/ifcfg-eth0
:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
IPADDR1=192.168.1.100
NETMASK1=255.255.255.0
For more dynamic configurations, you can add ip commands to /etc/rc.local
(make sure it's executable):
#!/bin/sh
ip addr add 192.168.1.100/24 dev eth0
ip addr add 192.168.1.101/24 dev eth0
exit 0
After configuring, test with:
# Check current IP addresses
ip addr show eth0
# Test connectivity
ping -c 4 192.168.1.100
- The network service must be restarted for changes to take effect:
service network restart
- The
IPADDR1
notation only works in RHEL/CentOS 6 and later - For multiple addresses, increment the number (IPADDR2, IPADDR3, etc.)