196

Got a Pi 3 which will always use ethernet, so trying to figure out how to disable the WiFi such that it does not even turn on after a reboot.

If I do an ifconfig I see the wlan0 device. I can do ifconfig wlan0 down but it will come back up again after a reboot.

I tried commenting out anything about wlan0 (and wlan1) in /etc/network/interfaces but that has not made a difference.

eth0 is not commented out so it can be used.

SDsolar
  • 2,308
  • 8
  • 24
  • 43
Evan
  • 2,062
  • 2
  • 10
  • 8
  • Did you comment out the `wlan1` in that file as well? – Patrick Cook Mar 08 '16 at 06:23
  • Yes. Only left lo and eth0. – Evan Mar 08 '16 at 06:24
  • 2
    What is the setting for `wlan0` in `/etc/network/interfaces`? If it is `auto` change it to `manual` followed by `ifdown wlan0`. – ott-- May 29 '16 at 20:07
  • Related: [Disable power on Wifi and Bluetooth interfaces during boot?](http://raspberrypi.stackexchange.com/q/53149/968) – Wolf Oct 19 '16 at 19:11
  • Thanks, @ott. You just reminded me how to have the internal one stop grabbing a DHCP address while the USB WLAN unit connects with static. I just commented out the wpa_supplicant line and added ifdown wlan0 - Thanks again. – SDsolar Jul 17 '17 at 08:18

11 Answers11

334

To completely disable the onboard WiFi from the firmware on the Pi3 / Pi4, add

dtoverlay=disable-wifi

in /boot/config.txt.

This is documented here. Please be sure to use an up to date firmware, this feature was added in January 2017.

There is also an overlay for disabling onboard bluetooth : disable-bt. If you want to disable both wifi and bluetooth, you need to add these 2 lines :

dtoverlay=disable-wifi
dtoverlay=disable-bt

NOTE : If you are using an old 'Pi3 only' firmware, you need to prefix the overlay name with pi3-. See this issue

Ludovic Ronsin
  • 3,456
  • 2
  • 9
  • 5
  • 31
    Correct. `/boot/config.txt` is the cleanest possible way to disable WiFi, and other peripherals. – Andrejs Cainikovs Mar 14 '17 at 12:50
  • 8
    Yes! The accepted answer will get you there, but this is a much better way. – Clay Mar 23 '17 at 11:01
  • How would you use this method to disable ethernet? – Daniel Harris May 23 '17 at 17:30
  • For me this also seems the safest method because to re-enable the WiFi would require a restart. Right? – CousinCocaine Dec 14 '17 at 08:17
  • 8
    At the time that I wrote my answer (the current accepted one) I did not know of this way, nor do I know if it was even an option at that time. This is a far superior method than the one described in my answer. – Patrick Cook Jul 02 '18 at 02:45
  • 5
    The overlay did not exist at the time you wrote your answer. As stated in my response, this was added on January 2017. So don't worry, you were right ! – Ludovic Ronsin Jul 02 '18 at 13:39
  • How do you disable both the wifi and bluetooth? `dtoverlay` variable will get overwritten? – deanresin Dec 16 '18 at 05:38
  • 3
    @deanresin Please see updated response. TL;DR; The way the dtoverlay configuration works can be seen as a sequence of command. They are executed in the order they are encountered. So you can declare it more than once. Overlay parameters, if any, are set with `dtparam=...` 'command' and refer to previous declared `dtoverlay`. For more info see official documentation at https://www.raspberrypi.org/documentation/configuration/device-tree.md#part3 – Ludovic Ronsin Dec 17 '18 at 10:23
  • Make sure to not put spaces around `=` between the option `dtoverlay` and its value `disable-wifi` as `dtoverlay = disable-wifi` will NOT work. – Lars Blumberg Apr 22 '20 at 09:20
  • 3
    Works great! As a followup for anyone using Ubuntu on the Raspberry Pi, `config.txt`is located in `/boot/firmware/config.txt`. – ws6079 Nov 30 '20 at 12:32
  • @ws6079 Same goes for Debian. – Phill Healey Jan 11 '21 at 19:38
  • `dtoverlay=disable-wifi` also disabled my bluetooth, which I don't desire in my application. Seems to be common issue: https://www.raspberrypi.org/forums/viewtopic.php?t=284221 Disabling wifi with `rfkill block wifi` worked in my case. – bkakilli Feb 16 '21 at 21:24
  • This worked for me on a Pi Zero 2 W with Raspbian Buster, where I wanted to replace the onboard WiFi with a more powerful USB WiFi dongle & antenna. It was the only changed needed, the USB WiFi dongle became wlan0. And it did not disable my Bluetooth, which I am using. – Uilleann Dec 21 '22 at 00:07
50

See Ludovic Ronsin's answer above about using dtoverlay, a method added in January 2017.

This post seems to be talking about this. The answer talks about disabling the drivers by editing the file /etc/modprobe.d/raspi-blacklist.conf and adding:

blacklist brcmfmac
blacklist brcmutil

Alternatively, you could use crontab -e and add:

@reboot sudo ifdown wlan0

So that command runs at each boot.

Hope this helps, I'm still waiting for my Pi 3 to arrive.

Seamus
  • 20,552
  • 3
  • 31
  • 67
Patrick Cook
  • 6,335
  • 6
  • 36
  • 63
  • 6
    The blacklist method worked for me. Just created a `/etc/modprobe.d/local-blacklist.conf` file, instead of appending to an existing file. – Evan Mar 08 '16 at 06:47
  • 1
    As far as I know, the blacklist method is closer to administratively down'ing the interface. It does not completely power down the interface. –  Aug 05 '16 at 20:51
  • 4
    @Patrick Cook Second method worked for me but I needed to run that command as root: `sudo crontab -e` – Matthias Herrmann Mar 21 '17 at 08:38
  • 2
    I like using the crontab to do it. As a matter of style I would edit the root crontab instead of any other user, and leave out `sudo`. For stretch, you need to use `ip link set wlan0 down` instead of `ifdown` – trey-jones Jun 13 '18 at 17:51
  • 4
    If you are using debian stretch and ifdown returns **unknown interface wlan0** then use: `sudo ifconfig wlan0 down` instead. If it still doesn't work, use `ifconfig` to list all available network interfaces. – mat Sep 08 '18 at 17:04
  • To reanabme it, this worked for me: ip link set wlan0 down – Ηλίας Aug 25 '20 at 00:29
34

You can use

sudo iwconfig wlan0 txpower off

This should disable the wifi adapter.

Use sudo iwconfig wlan0 txpower on to enable it again.

Reference: https://manpages.debian.org/buster/wireless-tools/iwconfig.8.en.html

clel
  • 3
  • 2
yavuzaksan
  • 441
  • 4
  • 2
  • no , actually it does permanenty close the adapter until you made it back on again – yavuzaksan Jul 30 '16 at 14:25
  • I'll take your word for that then. In future you might want to include more explanation in your answer, since this got automatically flagged yesterday as "low quality" (due I think to length and lack of formatting) by the system, which is when I noticed it. In itself that sort of doesn't matter; I dismissed the flag. However, a moderator can dismiss a flag (not act on it) as "helpful", and if it was a "low quality" flag, that automatically gets you a downvote... – goldilocks Jul 30 '16 at 14:44
  • ...I didn't do that, but one of the other mods probably did out of habit (or because they agreed the answer as originally posted did not indicate much effort being made), which is how you got one down vote (automatic) and one up (from me), since flags are sometimes left for review by multiple mods. Note I don't like this "automatic downvote" policy and have actually complained on [S.E. Meta](http://meta.stackexchange.com/) about it to no avail (the justification is that actual people flag things as low quality but "forget" to also downvote). – goldilocks Jul 30 '16 at 14:44
  • This worked on my PI3 and it is permanent until you re-enable the wifi. :) – ThN Feb 14 '17 at 14:02
  • 2
    @yavuzaksan I can't seem to turn it back on, now. – Erutan409 Mar 10 '17 at 05:28
  • 8
    @Erutan409 to re-enable the wifi adapter you should write two times "sudo iwconfig wlan0 txpower auto". but as a say you should write it two times otherwise it wont work (i believe there is some glitch in the firmware) – yavuzaksan Mar 11 '17 at 06:25
  • I don't know how well this answers the OP, but it was just the answer I was looking for. To turn it back on use `sudo iwconfig wlan0 txpower on`. `auto` and `fixed` are for power control, not the radio. http://manpages.ubuntu.com/manpages/trusty/man8/iwconfig.8.html – JDavis Jan 24 '18 at 22:09
  • This is the only one that worked for me – Joris Mans Nov 10 '19 at 11:18
  • This one worked for me: `sudo ip link set wlan0 up` – Ηλίας Aug 25 '20 at 00:35
11

We have measured the RF from the Pi 3 (when used as a WiFi hotspot) and confirmed that this statement disables the Pi's WiDi transmitter when used as a hot spot:

sudo ifconfig wlan0 down

You can also easily create a clickable button on the taskbar to do this. Instructions are found here: http://orbisvitae.com/ubbthreads/ubbthreads.php?ubb=showflat&Number=81166#Post81166

Russ
  • 121
  • 1
  • 3
9

I modified the rc.local using command sudo nano /etc/rc.local, and added ifconfig wlan0 down in it. However, if Ethernet is not connected or IP is not assigned to wired interface then the WiFi is on. This gives a backup way to connect the RasPi when running headless.

Install ethtool with sudo apt-get install ethtool.

Then copy the script below to sudo nano /etc/rc.local right before exit 0, so the last lines look like this:

# Disable WiFi if wired.
logger "Checking Network interfaces..."
if ethtool eth0 | egrep "Link.*yes" && ifconfig eth0 | grep "inet"; then
  logger 'Disabling WiFi...'
  ifconfig wlan0 down
else
  logger 'WiFi is still enabled: Ethernet is down or ethtool is not installed.'
fi

exit 0

Then save using CTRL + X and reboot. It seems to work for me, as after reboot ifconfig does not give wlan0.

7

You can also use the rfkill command to disable or enable the Wi-Fi interface(s). This is how the interface is disabled by Raspberry Pi OS (Raspbian) with a new installation before the country has been configured in the Wi-Fi settings (e.g using raspi-config). You can disable the Wi-Fi interface(s):

sudo rfkill block wifi

Enable it like this:

sudo rfkill unblock wifi

And check the current state of the interfaces:

rfkill list

If you want enable/disable specific interfaces use the index shown by rfkill list to the un/block command. For example, you can usually just block the built-in WiFi interface like this (if this doesn't always control the correct interface see this question for more details):

rfkill block wifi 0

The rfkill state will be maintained across reboots as it is reinstated on bootup by the systemd-rfkill service.

Pierz
  • 814
  • 10
  • 8
5

Apart from blacklisting which has the risk of a lockout in case you need to reboot and no ethernet is available, you can also unload the kernel module as follows:

sudo modprobe -r -v brcmfmac

But I'm not sure unloading the device drivers is a good idea as I fear the wlan0 device may still draw power and even more so if the device drivers' power management features are not loaded, currently I keep drivers loaded and simply make sure the default route via wlan0 is disabled:

sudo ip route del default via <Gateway IP> dev wlan0

This will make sure all traffic will go via eth0 and (hopefully) be more stable and so forth for example for the ntp daemon.

Patrick B.
  • 312
  • 1
  • 7
  • 21
3

I use the following command wpa_cli terminate, I have that command in my /etc/rc.local

MadAntrax
  • 921
  • 7
  • 8
  • 1
    This disables the WPA client, so you basically shut down wireless connectivity entirely. Don't do it. – Zimano Oct 30 '17 at 11:28
3

I'm using my pi as an access point (wifi hotspot). This works for me:

# Turn off
sudo service hostapd stop && sudo service isc-dhcp-server stop && sudo ifconfig wlan0 down && sudo service isc-dhcp-server start

And to turn it back on without restarting the pi, run this:

# Turn on
sudo service isc-dhcp-server stop && sudo ifconfig wlan0 up && sudo service hostapd start && sudo service isc-dhcp-server start
nmrugg
  • 131
  • 3
2

Other solution is to edit /etc/network/interfaces file, comment/remove lines about Wi-Fi connection (wlan0) and add line:

iface wlan0 inet manual
pbies
  • 288
  • 4
  • 13
-4

The easiest way to disconnect from a Wifi network on Pi 3 is to enter some useless password! Click on your Wifi network, it will again ask for password but this time enter random text and you will be disconnected.

  • 7
    There is a difference between having an interface enabled, a device enabled (which this question is about), and having an interface connected to a network, which is what you are talking about. I do not think the OP is concerned about that. – goldilocks Jul 18 '16 at 16:22
  • @goldilocks Well if Wifi is disconnected this way then it will always use Ethernet and that is what OP is asking for. – Chinmay Sarupria Jul 18 '16 at 16:26
  • Or edit using `sudo nano /etc/wpa_supplicant/wpa_supplicant.conf` for those wanting to use this method. – 101 Oct 19 '16 at 09:21
  • @ChinmaySarupria Just because a path exists doesn't make it a good idea to go down it under any circumstance. – Phill Healey Jan 11 '21 at 19:42