Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

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.

share|improve this answer
    
I was wondering, do I need to specify a gateway per ifcfg-eth0 and one per ifcfg-eth0:0 ? [since each of then are supposed to be on a different subnets? –  fptstl Jul 9 '12 at 20:23
add comment

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.

share|improve this answer
add comment

Normally /etc/resolv.conf file is a configuration file for DNS related option (nameserver, search domain, ecc). In a Red-Hat based distribution I will suggest you to create two files:

/etc/sysconfic/network-script/route-eth0  
/etc/sysconfic/network-script/route-eth0:0  (I have not ever seen this)

In each of one you could defined all the route option for the specific interface. The rule that you put in these will be loaded at boot. The default gateway is advisable to be placed in /etc/sysconfig/network file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.