dhcpcd-discuss

Re: Replace DHCP default gateway with static route

Roy Marples

Tue Apr 03 23:38:52 2018

Ah it should be $new_routers

On 04/04/2018 00:35, Alex K. wrote:
Hello Roy and thank you!

That the $routers I was probably after and wasn't been able to find.

I'll test it and reply, what finally came out of it.

Alex.


בתאריך יום ד׳, 4 באפר' 2018, 2:28, מאת Roy Marples ‏<roy@xxxxxxxxxxxx <mailto:roy@xxxxxxxxxxxx>>:

    Hi Alex

    On 04/04/2018 00:05, Alex K. wrote:
     > I've been looking for days to achieve the following - replace the
     > default gateway DHCPCD got from the network, with a static route
    (toward
     > a particular subnet only), using the router IP address we got
    within the
     > basic DHCP offer, as that route next hop.
     >
     > Basically, replacing the "regular" default route DHCP put, with a
    static
     > route. Obviously keeping the rest of information DHCP got (our IP
     > address and such).
     >
     > After digging for days, I haven't been able to make working
     > configuration/hook. Therefore, any suggestion will be gladly
    appreciated.

    dhcpcd does not offer such functionality. Assumning you're using Linux,
    I would script a dhcpcd.exit-hook like so.
    (This is untested and just typed here, hopefully enough for an idea)

    if $if_up; then
             ip r d default dev $interface
             set -- $routers
             while [ -n "$1" ]; do
                     ip r a 1.2.3.4/16 <http://1.2.3.4/16> via $1 dev
    $interface && break
                     shift
             done
    elif $if_down; then
             ip r d 1.2.3.4/16 <http://1.2.3.4/16> dev $interface
    fi

    Good luck

    Roy


References:
Replace DHCP default gateway with static routeAlex K.
Re: Replace DHCP default gateway with static routeRoy Marples
Re: Replace DHCP default gateway with static routeAlex K.
Archive administrator: postmaster@marples.name