dhclient dry-run - need to know the def gateway without installing the def route

alessandro macuz alessandro.macuz at gmail.com
Tue Apr 8 13:03:00 UTC 2014


2014-04-07 22:46 GMT+02:00 Sten Carlsen <stenc at s-carlsen.dk>:

>
> On 07/04/14 22.23, alessandro macuz wrote:
>
> 2014-04-07 21:15 GMT+02:00 Simon Hobson <dhcp1 at thehobsons.co.uk>:
>
>> alessandro macuz <alessandro.macuz at gmail.com> wrote:
>>
>> > I could deduce the gateway from the DHCP server IP address because
>> normally they coincide but that would be my assumption.
>>
>>  You've heard the expression that "assume" makes an "ass" out of "u" and
>> "me", well your assumption is badly wrong. In home and small networks it is
>> likely to be true (not mine though). But once you get to business networks
>> then its more likely that the DHCP server is not at the same IP address as
>> the router.
>>
>  However, I'm still not quite sure why you are doing things the long way
>> round. What's specifically wrong with using the route that comes with the
>> lease ? Or more to the point, what's wrong with dealing with it when you
>> get it ? And BTW - have you considered the possibility of getting different
>> answers to your two queries ?
>>
>
>  Sorry maybe I should have added more details but there is only one
> defaut gateway on the network of that interface and hence the dry-run
> returns always the same IP address. As to the second reply it will
> configure the interface.
>
>  Why I want to run a dry-run? Because eventually I need to install some
> routes pointing to the only gateway on the network. On the system there is
> another interface that gets the IP dinamically and two default routes are
> not OK
>
> I suggest you look at: /sbin/dhclient-scripts
>
> It contains the following code, I think a small modification to this will
> do your job:
> ~~~~~~~~~~~~~~~~~~~~~
> add_default_gateway() {
>     router="${1}"
>
>     if is_router_reachable ${router} ; then
>         metric=""
>         if [ $# -gt 1 ] && [ ${2} -gt 0 ]; then
>             metric="metric ${2}"
>         fi
>         ip -4 route replace default via ${router} dev ${interface}
> ${metric}
>         if [ $? -ne 0 ]; then
>             logmessage "failed to create default route: ${router} dev
> ${interface} ${metric}"
>             return 1
>         else
>             return 0
>         fi
>     fi
>
>     return 1
> }
>


Thanks Sten,

I don't see such add_default_gateway() function in my Ubuntu 12.04.4 but I
do see

            for router in $new_routers; do
                if [ "$new_subnet_mask" = "255.255.255.255" ]; then
                    # point-to-point connection => set explicit route
                    ip -4 route add ${router} dev $interface >/dev/null 2>&1
                fi

                # set default route
                ip -4 route add default via ${router} dev ${interface} \
                    ${metric_arg} >/dev/null 2>&1
            done

when $reason is set to BOUND or RENEW or REBIND or REBOOT or TIMEOUT.

Eventually I realized I have access to the DHCP server (openwrt) and the
trick may be not to send the default route and at the same time to use the
option 121 (client must explicitly request it)

http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2006q2/000818.html

I'll give it a try.

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-users/attachments/20140408/d045556a/attachment.html>


More information about the dhcp-users mailing list