2

I'm trying to figure out how to configure wpa_supplicant to:

  1. First try to connect to a selection of preconfigured wifi networks as a DHCP client, and if that fails
  2. Set up a wifi access point using wpa_supplicant's AP mode as a fallback, using dnsmasq as a DHCP server.

I know that wpa_supplicant.conf can be set up to fallback to AP mode. The thing I'm not sure about, is how to automatically switch from being a DHCP client to being a DHCP server. Can wpa_supplicant do this automatically?

Unfortunately, the other questions I've found do not relate specifically to dnsmasq.

0
  1. Make sure you have the Debian version of wpa_supplicant installed (specifically, you need the wpa_action script with it's dependencies which can be found here). If you're using Raspbian, you have this already. If you're using something like Arch or Buildroot, you'll need to install those scripts manually.

  2. Set up dnsmasq to run it's DHCP server all the time (there is no real need to disable it when it's not being used). It needs to run at startup, and use a dnsmasq.conf like this:

# Listen on this specific port instead of the standard DNS port
# (53). Setting this to zero completely disables DNS function,
# leaving only DHCP and/or TFTP.
port=0

interface=wlan0
dhcp-authoritative
dhcp-leasefile=/tmp/dhcp.leases
dhcp-range=10.0.0.2,10.0.0.10,24h
#subnet mask
dhcp-option=1,255.0.0.0

# Do not send gateway to client
dhcp-option=3
# Disable DNS
dhcp-option=6
  1. Make your /etc/wpa_supplicant/wpa_supplicant.conf something like this:
ctrl_interface=DIR=/var/run/wpa_supplicant

network={
    ssid="yourSSID"
    key_mgmt=WPA-PSK
    psk="yourpasscode"
    priority=1
    id_str="dhcp_client"
}

network={
    ssid="Hotspot"
    mode=2
    key_mgmt=WPA-PSK
    psk="password"
    frequency=2437
    id_str="dhcp_server"
}
  1. And make your /etc/network/interfaces something like this:
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet manual
  wpa-driver nl80211
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface dhcp_server inet static
  address 10.0.0.1
  netmask 255.0.0.0

iface dhcp_client inet dhcp
  • Old style Debian ifupdown is deprecated. What operating system do you use? Does it work together with dhcpcd? – Ingo Jul 7 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.