I’m not a Linux guru by any standards, at best I am an experienced noob. Nonetheless, I have heard of the famed power of the terminal.
So a couple of years back when I was faced with a situation where I only had access to the terminal on a Pi running Raspbian, and I needed to turn on the WiFi radio, I thought this should be easy, right?
Well, the procedure is actually easy, it’s just that the documentation was difficult to find.
What happened is I had setup the Pi using a monitor and keyboard, and while I had access to the Raspbian GUI, I turned off the WiFi radio for some reason. I then left the house with the Pi with the intention of using of headless while I was out and about through Ethernet.
However, at some point I needed access to WiFi to update the Pi or something, and I wasn’t going to achieve this through the Ethernet cable. Unfortunately, I did not have access to the GUI on my headless setup since the computer I was using didn’t have VNC Viewer and I also couldn’t download it for reasons I do not recall. Thus at that point in time my only option was to turn on the WiFi radio through terminal.
So I got to googling to find the one command that would allow me to turn on the WiFi radio. Long story short, I didn’t find what I was looking for online. I even went as far as asking seeking assistance from guys with more Linux mileage than I, but didn’t get an answer. At that point I chose to leave the issue as an open mystery, as it wasn’t a rabbit hole worth going down.
Years later (yes literally years later), I was facing some troubles with setting up Pentoo to use with a HackRF and by chance I finally came to the solution that had escaped me many years earlier. Talk about killing a bird with two stones.
If ever you find yourself in a similar situation, this is what you need to turn on WiFi on the Pi when running Raspbian (or other debian based linux distributions I guess):
rfkill unblock wifi
And if you want to turn it off you simply enter:
rfkill block wifi
That’s it; rfkill is the key to your problems.
rfkill can actually be used to turn control both WiFi and Bluetooth. So you can actually go into “airplane mode” by typing
rfkill block all
And both WiFi and Bluetooth will be off. Of course to turn them back on you simply type
rfkill unblock all
To check on the status of WiFi or Bluetooth you type
And it will list your wireless interfaces along with their states.
From the picture above you see that rfkill list provides a list of the available wireless interfaces: WiFi and Bluetooth in this case. It’s also evident that there are items listed as soft blocked and hard blocked. The block and unblock command can only control when the interface is soft blocked. Hard blocking is done through hardware when there is a physical switch that can turn WiFi/Bluetooth on or off, in this case if your interface is hard blocked rfkill unblock will not work, you have to use your switch.
You could read more on rfkill here. But that’s basically how to turn WiFi, and Bluetooth as a bonus, on and off on Raspbian through the terminal.