Home > RedHat > Multiple DHCP interfaces on CentOS

Multiple DHCP interfaces on CentOS

I can feel you inside me
You’re not stronger than me
I won’t let you
No, you can’t have me!
(Iced Earth – Jekyll & Hyde)

Today I encountered interesting problem. I had one interface (eth0) in VirtualBox testing machine, which was bridged to host interface and being configured by dhclient (DHCP). Default route was being provided by DHCP server.

Now, I wanted to add another interface (eth1), with type NAT. NAT interface in VirtualBox gets it’s IP address by built-in DHCP server.

So I now had two interfaces – eth0 & eth1 both getting addresses from DHCP, and to make the matters worse – from different servers. Because of the linear nature of network init script in CentOS 5, eth0 starts up first, and eth1 second. Problem is that dhclient run for second interface overwrites default route set by the dhclient of the first interface.

One obvious solution was to rename interface eth0 to eth2, which would change the order of startup and in this case eth2 (ex eth0) interface would overwrite default route set by the eth1. But this is a hack, and I love to do things by the book. Advantage of doing things this way is that you can automate and script more predictably than if you hack too much with the system.

Fortunately, there is a way to do this a little smarter than brute-force renaming. Secret is GATEWAYDEV variable that can be set in /etc/sysconfig/network file. That variable says to network init script which interface should set up default gateway. So, all I had to do is:

# echo "GATEWAYDEV=eth0" >> /etc/sysconfig/network
# service network restart

And that’s it!

Advertisements
  1. zuzik
    March 11, 2015 at 5:11 am

    Thank you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: