Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Dual-homed DHCP Gateway Selection

  1. #1

    Default 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.

    --bd

  2. #2
    Join Date
    Jun 2008
    Location
    Taiwan
    Posts
    150

    Default Re: Dual-homed DHCP Gateway Selection

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

    Below is script:

    #!/bin/sh
    ifdown eth0
    ifdown eth1
    ifup eth0
    ifup eth1
    route delete -inet 192.168.1.x network 255.255.255.0 gw 192.168.1.1
    Regards,
    Bryan Yu
    http://lifestory.moqin.com/

  3. #3

    Default Re: Dual-homed DHCP Gateway Selection

    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:

    sfile=/var/lib/dhcpcd/dhcpcd-eth1.info
    gw=`grep GATEWAY $sfile`
    gw=`echo $gw | awk -F "=" '{print $2}'`
    route del -net 0.0.0.0
    route add -net 0.0.0.0 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. ;-)

    --bd

  4. #4
    Join Date
    Jun 2008
    Location
    Taiwan
    Posts
    150

    Default Re: Dual-homed DHCP Gateway Selection

    /etc/init.d/after.local
    This file is workable.
    You can see /etc/init.d/rc to obtain more information.
    Regards,
    Bryan Yu
    http://lifestory.moqin.com/

  5. #5

    Default Re: Dual-homed DHCP Gateway Selection

    /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.

    --bd

  6. #6
    Join Date
    Jun 2008
    Location
    Taiwan
    Posts
    150

    Default Re: Dual-homed DHCP Gateway Selection

    Did you add #!/bin/sh in your head of script?
    Regards,
    Bryan Yu
    http://lifestory.moqin.com/

  7. #7

    Default Re: Dual-homed DHCP Gateway Selection

    Quote Originally Posted by df6269 View Post
    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.

    --bd

  8. #8
    Join Date
    Jun 2008
    Location
    Taiwan
    Posts
    150

    Default Re: Dual-homed DHCP Gateway Selection

    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}'
    Regards,
    Bryan Yu
    http://lifestory.moqin.com/

  9. #9

    Default Re: Dual-homed DHCP Gateway Selection

    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...

    --bd

  10. #10

    Default Re: Dual-homed DHCP Gateway Selection

    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:

    DHCLIENT_SET_DEFAULT_ROUTE="yes|no"

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

    --bd

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •