13

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?

4 Answers 4

5

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.

1
  • 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, 2012 at 20:23
4

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.

0

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.

This is incorrect. While it is acceptible on RHEL/CentOS systems to handle Ethernet interfaces in several files, routing is handled differently. Routes for a specific interface must be collectively placed into a single file for that interface. In other words, if you need custom routes for eth0:1, eth0:2 and eth0:3, they must all be placed in:

/etc/sysconfig/network-script/route-eth0

Nothing like :1 can be appended to the filename.

A previous answer suggested creating a file for the new interface:

/etc/sysconfig/network-scripts/ifcfg-eth0:1 

This is correct, but you should not place the GATEWAY= directive in it. This will result in several default gateways being created which causes routing to misbehave. Leave the GATEWAY= option out and add the required route to:

/etc/sysconfig/network-script/route-eth0
1
  • 1
    It looks like you are trying to comment on another answer rather than answer the question. You should edit your answer to focus on answering the question.
    – kasperd
    Mar 31, 2016 at 20:03
0

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/sysconfig/network-script/route-eth0  
/etc/sysconfig/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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .