# dhclient vs udhcpc

## joanandk

Hi,

As many of you know, there are multiple possibilities to get dhcp client script on the machine:

a) using dhcpcd

b) using the built in udhcpc

I have found no documentation on the udhcpc. So far I have seen that udhcpc cannot be invoked as a command, but by restarting the network interface via the init.d script.

Has someone a deeper insight? What other advantages are there with the "external" dhcp-client script?

Does udhcpc have support for dhcp-hooks (I have not seen any support)?

What is your recommendation? Installing dhcpcd on new systems or make use of udhcpc?

Thanks.

----------

## krinn

udhcpc is busybox implementation of dhcp

while dhcpcd is roy marples implementation of dhcp

these aren't facts ; it's only base on my thinking: "busybox tools are simple and functional and aim to stay tiny, dhcpcd is made by roy marples: it then could only be top tool".

So for me, if you want "i need a client to ask dhcp server an ip", udhcpc should do the work, but if you want extra features, dhcpcd is there.

----------

## UberLord

udhcpc is a very small DHCP client that provides a very limited (but also the most useful) set of DHCP options to a shell script which then configures the address, routing and DNS.

On Gentoo it's available via the net.* DHCP modules. It does have a hook script of sorts, but it's just one script that Gentoo supplies with no way of extending it.

udhcpc is only available on Linux.

dhcpcd is quite larger (well, 220k on NetBSD i386) but decodes all RFC DHCP options and allows custom ones to be made as well.

It configures the address and routing internally and then sends everything else to a shell script for futher configuration such as DNS. You can roll your own hook scripts easily.

man page here.

On Gentoo it's available via the net.* DHCP modules OR available as it's own init script (this is the preferred way).

dhcpcd also works on BSD, QNX and Solaris platforms.

It's also the tool of choice on Android (although an old version)

dhcpcd also does a lot lot more than udhcpc - static IPv4, IPv4LL, ARP DaD, IPv6 (static and RS), DHCPv6, DHCP4/6 authenticaton and a whole load more stuff.

This could all be compiled out to reduce the overall size to under 100k.

It also works very well with >1 interface (say wired and wireless) on the same subnet.

There's a whole truck of other things dhcpcd does that no other does. Generally if there is something it cannot do, just ask and usually it gets implemented.

----------

## krinn

See, my resume wasn't bad:  "it then could only be top tool"  :Smile: 

----------

## joanandk

Thanks you both.

The link is superb from UberLord. I have used /lib/dhcp/dhcp-hooks/99_custom upto now, but /etc/dhcpcd.enter-hook is more backup-friendly and will be migrating soon.

BR

----------

## joanandk

Hi Guys,

I was using /etc/dhcpcd.exit-hook to determine if we are in the intranet. If not openvpn is started. This is not working (openvpn is started but fails to connect and times out). Do you know how I could make it work?

```
# VPN-Interface

VPNIF="tap0"

# LAN-Network

VPNET="172.16.1"

# VPN script

VPPGM="/etc/init.d/net.tap0"

# Functions

start_vpn(){

        NETWORK=$(echo "$new_ip_address" | cut -d. --fields=1,2,3)

        if [ "$NETWORK" != "$VPNET" ]; then

                $VPPGM start &

        else

                $VPPGM stop &

        fi

}

if [ "$interface" == "$VPNIF" ]; then

        logger "DHCPcD: The interface belongs to VPN. Starting LAN services ..."

        exit 1

fi

if [ ! -f "$VPPGM" ]; then

        logger "DHCPcD: Script for VPN not found. Exiting ..."

        exit 1

fi

case "${reason}" in

        BOUND|RENEW|REBIND)

                start_vpn

                ;;

        EXPIRE|FAIL|STOP|TIMEOUT)

                $VPPGM stop &

        ;;

esac

```

I have tried with dhcpcd.enter-hook, that failed too, and I thought it was due to resolv.conf not getting ready for openvpn. The net.tap0 has dependency to openvpn, so executing net.tap0 calls openvpn.

Manually I can start net.tap0 and it works.

Thanks.

----------

