How to reset wlan0 on RasPi

Peter Walsh wrote 05/06/2019 at 17:57 0 points

I'm having trouble resetting the Wifi on my RasPi.

I have a RasPi running the most recent Raspbian stretch (version 9) full.

On boot, the system successfully contacts my router to get a DHCP lease:

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.132  netmask 255.255.255.0  broadcast 192.168.1.255

Sometime later, my program takes down DHCP and starts an access point using CreateAP:

systemctl stop dhcpcd
systemctl stop dnsmasq

create_ap -n --redirect-to-localhost wlan0 some-ssid

This puts wlan0 into AP mode, using the subnet 192.168.12.1

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.12.1  netmask 255.255.255.0  broadcast 192.168.12.255

This is correct behaviour for create_ap: the 192.168.12.1 is its default IP address, and the AP shows up when scanned by other devices. Other devices can connect to the RasPi and access data.

Later on, the system shuts down the AP and tries to reconnect to my local Wifi:

create_ap --stop wlan0

systemctl start dnsmasq

systemctl start dhcpcd

At this point, wlan0 remains set to the ip address 192.168.12.1:

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.12.1  netmask 255.255.255.0  broadcast 192.168.12.255

Reboot *will* reset wlan0 to the proper IP address (a lease offered by the router), but no amount of fiddling will get wlan0 to reset without a reboot.

What commands do I need to give to get the wlan0 to reset to the original configuration and get a DHCP lease from my local wifi?

Things I've tried:

stopping/resstarting dhcpcd, dnsmasq, hostapd, and avahi_demon

service networking restart

ifconfig wlan0 up/down

route del -net 192.168.12.0 ...

dhclient -v correctly connects to my router and gets a valid lease, but the wlan0 device does not take up the offered data.

Note that create_ap generates local config files (in /tmp) for the demons it runs, so it is *not* changing any config files on the system - I've checked. Also, the system connects as normal on a reboot, so any changed system config file problems would crop up there.

Any thoughts?