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.

Jeremiah Rose
  • 259
  • 2
  • 11
  • Is there a reason why you want to switch off the access point when you have a client connection? – Ingo Jun 30 '19 at 08:42
  • Nope, I just I figure it will be easier to do it that way – Jeremiah Rose Jun 30 '19 at 12:53
  • 1
    @jake has just made a setujp for this. You may have a look at it: [Automatically Create Hotspot if no Network is Available](https://raspberrypi.stackexchange.com/q/100195/79866). – Ingo Jul 02 '19 at 21:34
  • 3
    Possible duplicate of [Automatically Create Hotspot if no Network is Available](https://raspberrypi.stackexchange.com/questions/100195/automatically-create-hotspot-if-no-network-is-available) – Dmitry Grigoryev Jul 05 '19 at 08:14

1 Answers1

1
  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
Jeremiah Rose
  • 259
  • 2
  • 11
  • Old style **Debian ifupdown** is deprecated. What operating system do you use? Does it work together with **dhcpcd**? – Ingo Jul 07 '19 at 09:59