The officially official Devuan Forum!

You are not logged in.

#1 2025-03-16 13:01:04

hacksenwerk
Member
From: Europe
Registered: 2022-02-10
Posts: 24  

[HowTo] dhcp & udhcpc - Timeout for network connections

I want to have dhcp to try to establish a network connection at boot time, but when there is no ethernet cable plugged in, or no wlan card, it takes up to 60 seconds before dhcp gives up.

So let's decrease the timeout.

Edit

/etc/dhcp/dhclient.conf

Search for the line

#timeout 60;

uncomment it and change it to the value (amount of amount of seconds) you like.
For example:

timeout 15;

That's it.

Note 1: If the dhcp server did not offer an ip address before the time out runs down. you wont get an established network connection!

Note 2: udhcpc can be a replacement for isc-dhcp-client and isc-dhcp-common. I noticed, that it times out very quickly by default, when it can not find any of the interfaces defined in /etc/network/interfaces

Thanks to ralph.ronnquist (rrq) for helping with the timeout issue and mentioning udhcpc in IRC.

Last edited by hacksenwerk (2025-03-16 14:55:41)

Offline

#2 2025-03-16 16:13:04

RedGreen925
Member
Registered: 2024-12-07
Posts: 95  

Re: [HowTo] dhcp & udhcpc - Timeout for network connections

I want to have dhcp to try to establish a network connection at boot time, but when there is no ethernet cable plugged in, or no wlan card, it takes up to 60 seconds before dhcp gives up.

I use this with my laptop.

root@9600k:~# cat bin/lenovo_etc_network_interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The first card in the system added for devuan method of networking
# the pre-up is for stopping the annoying delay when the network cable is not connected.

auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp
        pre-up ip link set eth0 up && sleep 1
        pre-up [ $(cat /sys/class/net/eth0/carrier) -eq 1 ]

Forget where I got it when searching on the problem but it works perfectly every time it boots.

Offline

#3 2025-03-18 13:04:02

hacksenwerk
Member
From: Europe
Registered: 2022-02-10
Posts: 24  

Re: [HowTo] dhcp & udhcpc - Timeout for network connections

That's the important part I guess:

pre-up [ $(cat /sys/class/net/eth0/carrier) -eq 1 ]

But I don't understand it.
Where does the -eq option belongs to?
To the pre-up?

Last edited by hacksenwerk (2025-03-18 13:04:27)

Offline

#4 2025-03-18 14:40:56

delgado
Member
Registered: 2022-07-14
Posts: 229  

Re: [HowTo] dhcp & udhcpc - Timeout for network connections

[ $(cat /sys/class/net/eth0/carrier) -eq 1 ]
is a logical expression. True, if the ethernet-cable is connected.

Offline

Board footer