Dual-homed DHCP Gateway Selection

Running openSUSE 10.3, dual-homed as follows:

eth0 - LAN
eth1 - WAN (ISP)

Both NICs are using DHCP. Via DHCP assignments, the default route assigned is from my LAN DHCP server. My ISP also assigns a gateway, but it doesn’t stick and I have to manually reconfigure routing after each boot. This machine is my internet firewall so I need the gateway to use my ISP’s setting.

Is there a way to get the gateway from my ISP to take precendence? I don’t want to configure it statically via the Default Gateway option as my ISP sometimes changes their setup which could make a static configuration invalid.


You can add a script in /etc/init.d/after.local.
Here is example:
LAN Network: 192.168.1.x
LAN Gateway:

Below is script:

ifdown eth0
ifdown eth1
ifup eth0
ifup eth1
route delete -inet 192.168.1.x network gw

Yeah, I thought of writing a script right after I posted. I wrote one that works a treat, but apparently after.local isn’t the right place for it as it doesn’t kick in after booting. Guess I’ll have to do some digging re: where it should go. In the meantime, here’s the script:

gw=grep GATEWAY $sfile
gw=echo $gw | awk -F "=" '{print $2}'
route del -net
route add -net gw $gw

Oh, and the reason I didn’t think of a script earlier is because I have a SLES 9 machine with the same NIC config, and the gateway from its eth1 is the one that sticks. I just can’t figure out how I got that to work. :wink:


This file is workable.
You can see /etc/init.d/rc to obtain more information.

/etc/init.d/after.local works if I change runlevels, which is what the rc file indicates should happen. It does not seem to execute as part of the boot process however, which is where I need it.


Did you add #!/bin/sh in your head of script?

No, I had not included that. But I just added it as the first line of the script and the script still doesn’t execute during the boot process.


The after.local script can’t execute during the boot process that is strangeness.
I have never seen that.
Do you define the same variable of script?

gw=grep GATEWAY $sfile
gw=`echo $gw | awk -F “=” ‘{print $2}’

Well, this turns out to be a matter of patience. The script is running after all – I was testing for it too soon after bootup. If I logged in immediately after booting and then ran the route command, the eth0 gateway was listed, so I presumed the script wasn’t running. In reality, it had not run yet, and if I waited another 15 seconds or so, the script would run and the route would change.

So, thanks for your help and sorry I took us down the wrong path!

If I ever figure out how I got this working on SLES 9 without the script workaound, I’ll post back…


OK, I finally figured out a more proper solution to this problem…

In the /etc/sysconfig/network/ifcfg-* files, enter the following as appropriate for the interface being configured:


Setting this to “no” on my private interface and to “yes” on the public interface solved the issue for me.


That’s a good news.
Your problem can be fixed by yourself.