Linux – second ip address on the same interface but on a different subnet

centoslinuxnetworkingredhatrouting

Is it possible in CentOS 5.7 64bit to have a second IP address on one interface (eg. eth0) – alias interface configuration – in a different subnet?

Here is the original config for eth0

more etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme BCM5721 Gigabit Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.91.255
HWADDR=00:1D:09:FE:DA:04
IPADDR=192.168.91.250
NETMASK=255.255.255.0
NETWORK=192.168.91.0
ONBOOT=yes

And here is the config for eth0:0

more etc/sysconfig/network-scripts/ifcfg-eth0:0
# Broadcom Corporation NetXtreme BCM5721 Gigabit Ethernet PCI Express
DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=10.10.191.255
DNS1=10.10.15.161
DNS2=10.10.18.36
GATEWAY=10.10.191.254
HWADDR=00:1D:09:FE:DA:04
IPADDR=10.10.191.210
NETMASK=255.255.255.0
NETWORK=10.39.191.0
ONPARENT=yes

How would the resolv.conf file should change since there are two different gateways?
Any other change needed?

Best Answer

Is it possible to have a second IP address on one interface (eg. eth0) - alias interface configuration - in a different subnet?

Sure, nothing stopping you from doing that. The network interfaces will see broadcasts for the other both subnets, but that probably won't make a big difference unless you have a really busy network.

How would the resolv.conf file should change since there are two different gateways? Any other change needed?

You cannot have 2 default gateways. Remove a gateway from one of those interfaces. Having 2 like that simply isn't going to do anything useful. Only one of the gateways will be used.

DNS resolution (resolv.conf) really has nothing to do with your routing configuration. On Linux DNS resolution is system wide and really has nothing to do with the interface configuration at all. Just place a couple valid DNS servers in your resolv.conf. If you need something more advanced to send some requests to different upstream servers you may need to install something like DNSMasq.

Related Topic