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

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?


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.


As already mentioned there is nothing wrong to have two different subnet on one network and it will work as long you are connected to the same switch/switch group for both networks and you don't have any VLAN rules applied to it or any other security zones.

Regardless of how many IP addresses/subnets you have there is always only one default gateway. A default gateway is used when an IP address does not match any other routes in the routing table. So in your example for every request which are not part of 192.168.91.0/24 or 10.10.191.0/24 network will be redirected to the default gateway.

But if you wish you can still add manual routes. So let's say that you have a third private network 10.10.200.0/24, which is accessible through 10.10.191.0/24. You need to add a static route:

ip route add 10.10.200.0/24 via 10.10.191.254 dev eth0:0

Resolv.conf has nothing to do with the gateway and is used for DNS resolvs. Have a read here for more information.