Question

Motivation: I run wpa_supplicant without a network managing tool because I don't want to force new DHCP leases when my old ones work. This way I can get onto an old network very fast (as soon as wpa_supplicant establishes the lower network layers) if the DHCP lease has not expired.

Problem: But when the DHCP lease has expired, or if my IP address is from another network, I do need to call upon DHCP. I currently use dhclient, but dhcpcd is another option here. The problem is, even though these DHCP clients run in the background, they don't automatically realize that I need a new IP address, since I've got an old, invalid one.

Question: Is there a way to very quickly determine if I'm in need of DHCP? E.g. as a reaction to wpa_supplicant or as a response to contacting the standard gateway and realizing a connection isn't available. I can easily run sudo dhclient wlan0, and it gives me the address in one second. But what can I do to automate this process, when necessary?

Making unnecessary DHCP requests is not out of the question, but flooding the DHCP server is.

Elaborate question: For those of you who use wpa_supplicant directly, how do you DHCP?

Was it helpful?

Solution

Run dhcpcd again whenever you attach to a new network. If you have an existing lease it should be confirmed quickly.

If you object to typing in "dhclient" or "dhcpcd" everytime, you could automate it with a shell script. It could look something like

#!/bin/sh
dhcpcd wlan0 &
wpa_supplicant -d -c/etc/wpa_supplicant.conf -iwlan0

dhcpcd will say it is "waiting for carrier" until wpa_supplicant brings up the wireless link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top