In CentOS/RHEL systems, you can assign multiple IP addresses to a single physical interface using interface aliases (e.g., eth0:0). This is particularly useful when you need to host services on different subnets without additional hardware. Here's how to properly configure eth0:0 on a different subnet while maintaining the primary eth0 configuration: Primary Interface (eth0):
# /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=static IPADDR=192.168.91.250 NETMASK=255.255.255.0 GATEWAY=192.168.91.1 ONBOOT=yes
Alias Interface (eth0:0):# /etc/sysconfig/network-scripts/ifcfg-eth0:0 DEVICE=eth0:0 BOOTPROTO=static IPADDR=10.10.191.210 NETMASK=255.255.255.0 # Notice no gateway here - more on this below ONPARENT=yes
The critical consideration is routing. While you can technically specify different gateways in each ifcfg file, this often causes routing conflicts. Instead: 1. Keep only the primary gateway in the main interface 2. Add specific routes for the secondary subnet:# /etc/sysconfig/network-scripts/route-eth0:0 10.10.191.0/24 via 10.10.191.254 dev eth0:0
For /etc/resolv.conf, you have two approaches: Option 1: Use DNS servers that can resolve both networksnameserver 8.8.8.8 nameserver 8.8.4.4
Option 2: Use conditional forwarding (requires dnsmasq or similar)server=/10.10.191.0/24/10.10.15.161 server=/192.168.91.0/24/192.168.91.1
After configuration:# ifup eth0:0 # ip addr show # route -n # ping -I eth0 192.168.91.1 # ping -I eth0:0 10.10.191.254
Common issues to check: - Make sure ONPARENT=yes is set in alias configurations - Verify no conflicting gateways - Check SELinux context if connections fail
In CentOS 5.7 (and most Linux distributions), you can indeed assign multiple IP addresses to a single physical interface using interface aliases. The key requirement is that these IPs must belong to different subnets - which is exactly what you're attempting with eth0 (192.168.91.0/24) and eth0:0 (10.10.191.0/24).
Your current configuration looks technically correct, but let's examine some potential improvements:
# Original eth0 config DEVICE=eth0 BOOTPROTO=static IPADDR=192.168.91.250 NETMASK=255.255.255.0 GATEWAY=192.168.91.1 # Recommended to specify primary gateway ONBOOT=yes # Improved eth0:0 config DEVICE=eth0:0 BOOTPROTO=static IPADDR=10.10.191.210 NETMASK=255.255.255.0 # NETWORK and BROADCAST are optional in modern configs ONPARENT=yes
The critical consideration is routing. While you can specify multiple gateways in interface configs, Linux will only use one default gateway (typically the one defined in the primary interface). For proper routing between subnets:
# View current routes route -n # Add specific route for secondary subnet route add -net 10.10.191.0 netmask 255.255.255.0 gw 10.10.191.254 dev eth0:0 # Make persistent by adding to /etc/rc.local echo "route add -net 10.10.191.0 netmask 255.255.255.0 gw 10.10.191.254 dev eth0:0" >> /etc/rc.local
Your /etc/resolv.conf should contain nameservers that can resolve for both networks. A typical configuration might look like:
nameserver 10.10.15.161 nameserver 10.10.18.36 nameserver 192.168.91.1 # Add primary network DNS if needed options rotate timeout:1 attempts:2
After making changes, restart networking and verify:
service network restart # Check interfaces ifconfig -a # Test connectivity ping -I eth0 192.168.91.1 ping -I eth0:0 10.10.191.254 # Check routing ip route show traceroute 10.10.15.161
For more complex scenarios, consider these approaches:
- Using policy-based routing for advanced multi-gateway setups
- Implementing network namespaces for complete network isolation
- Using bonding/teaming for redundancy and load balancing
Remember that interface aliasing is different from VLAN tagging (802.1Q) which creates logically separate networks on the same physical interface.