How can I keep a wireless card's radio powered off by default?
Solution 1
There are at least two Upstart jobs that affect the default wireless state:
-
/etc/init/rfkill-restore.conf
restores the soft block state for all radios to what they were at last shutdown, as recorded in/var/lib/rfkill/saved-state
. -
/etc/init/network-manager.conf
starts Network Manager which in turn restores its idea of wireless state from/var/lib/NetworkManager/NetworkManager.state
.
If you look at those two job configurations you will find that they have no temporal relationship, which seems like a design flaw to me. I'm guessing this race condition is rarely a problem because /etc/init/rfkill-restore.conf
is much simpler and has fewer start conditions.
All the solutions to enforcing a wireless-off default that I've seen try to use /etc/rc.local
, including the "modern" solution that @Lekensteyn and @rubo77 came up with. Unfortunately, that solution does not work for me on either of two laptops I have tried. This is not particularly surprising because /etc/rc.local
also has no temporal relationship that I can find to either of /etc/init/rfkill-restore.conf
and /etc/init/network-manager.conf
. Throwing in a lengthy sleep in /etc/rc.local
prior to issuing an rfkill block wifi
is an ugly workaround for this race condition mess, but it works if the delay is long enough.
A better solution would be for us to impose our desired states in /var/lib/rfkill/saved-state
and /var/lib/NetworkManager/NetworkManager.state
before those two Upstart jobs are even permitted to run. We can achieve this by creating our own Upstart job. In actual fact, we'll need two job configuration files to achieve the timing we need.
Our first job configuration does the actual file modifications we need. It will run as early as possible and will only run once. Create /etc/init/radio-silence.conf
with this content:
# radio-silence - Ensure radio silence on startup
#
# Override default startup behaviour of radios to ensure they are all
# disabled until the user deliberately enables them. This job requires
# radio-silence-wait to delay start of any services that may depend on
# resources manipulated by this job.
description "Disable all radios by default"
start on local-filesystems
pre-start script
sed -i -re "s/^(.+[[:space:]]+)[01][[:space:]]*\$/\11/" /var/lib/rfkill/saved-state
sed -i -re "s/^(WirelessEnabled=).*\$/\1false/" /var/lib/NetworkManager/NetworkManager.state
end script
As I prefer total radio silence when my laptop starts, I soft block all radios, not just wireless, but you can modify the first sed
in the above to limit this job's impact to whichever wireless devices you wish to soft block.
Our second job configuration is responsible for ensuring that neither of the rfkill-restore
and network-manager
jobs will start before radio-silence
has completed the file modifications. Create /etc/init/radio-silence-wait.conf
as follows:
# radio-silence-wait - Helper task for radio-silence
#
# Delays the start of all jobs that may depend on resources manipulated
# by radio-silence job. Avoids the need to modify job configuration of
# those other jobs.
description "Assist radio-silence by delaying jobs it affects"
start on (starting rfkill-restore or starting network-manager)
stop on (started radio-silence or stopped radio-silence)
instance $JOB
normal exit 0 2
task
script
status radio-silence | grep -q "start/running" && exit 0
start radio-silence || true
sleep infinity
end script
With this solution I am no longer seeing race condition problems, although I have not addressed the theoretical race between rfkill-restore
and network-manager
.
For more detail on how these jobs work together to achieve our temporal goal, refer to my question and answer, "How do I create a single-execution Upstart job guaranteed to complete before two other jobs begin?"
Solution 2
"Modern" solution using Network Manager: simply uncheck the Wireless Enabled option at the Network Manager applet (KDE: Network Management). The command nmcli nm wifi off
is equivalent. Continue reading if you sporadically enable Wi-Fi, but would like to revert it to disabled on reboot.
The wireless state is remembered in the file /var/lib/NetworkManager/NetworkManager.state
. To disable Wi-Fi at boot, ensure that the key WirelessEnabled
stays at false
. You could do that by editing the init script of Network Manager, or by using the /etc/rc.local
trick below. The command you need is:
sed s/^WirelessEnabled=true/WirelessEnabled=false/ -i /var/lib/NetworkManager/NetworkManager.state
rfkill block wifi
Put this before exit 0
(as described below). The rfkill block wifi
command is still needed due to a race with startup of Network Manager (NM). Once NM has started, changes to the state file have no effect.
(old answer that involves editing file /etc/rc.local
with an explanation of the rfkill
command)
A bit hacky, but it should work. A wireless card can be disabled using the rfkill
command. All devices used by rfkill can be shown using rfkill list
. Sample output:
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
Hard blocked
is dependend on a hardware setting, e.g. a wireless switch on a notebook. Soft blocked
can be controlled by the OS (Ubuntu).
How does it work? It does not have a manpage, running rfkill
provides a help text in this case:
Usage: rfkill [options] command
Options:
--version show version (0.4)
Commands:
help
event
list [IDENTIFIER]
block IDENTIFIER
unblock IDENTIFIER
where IDENTIFIER is the index no. of an rfkill switch or one of:
<idx> all wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm
Ah, now we get somewhere. You need to run rfkill block wifi
as root to disable the wireless device. (wlan is an alias of wifi, see the source code of rfkill).
Now, if you want to disable the wireless functions at boottime, add the command to /etc/rc.local by running sudo nano /etc/rc.local
. Use the arrow keys / page up/down keys to navigate to the line before exit 0
and add rfkill block wifi
, so that the file end like this:
# By default, this script does nothing
rfkill block wifi
exit 0
When finished, press Ctrl + X, then press Y to save it and press Enter to accept the filename.
If you decide to activate the device later, run: sudo rfkill unblock wifi
. Do not forget to remove the line from /etc/rc.local if you decide to use the wireless card.
Solution 3
Note : If you use tlp
, please read the entire answer.
All answers to this question are pretty old now and don't work on newer Ubuntu releases which use systemd. froage's answer worked for me on 14.04 but doesn't work on 16.04.
Systemd uses systemd-rfkill.service
to save the rfkill switch state during shutdown and restore it on every boot.
You have to pass a kernel command line parameter to restore rfkill switch state on every boot.
- open
/etc/default/grub
with your preferred text editor. - add
systemd.restore_state=1
as a parameter toGRUB_CMDLINE_LINUX
. That line should now readGRUB_CMDLINE_LINUX="systemd.restore_state=1"
. You can add it toGRUB_CMDLINE_LINUX_DEFAULT
as well. Either of them works. See this question for more details.
This will ensure that the rfkill state gets restored on each boot. Make sure to turn bluetooth and wifi off before restarting.
Issues with tlp
:
Update : These issues were present in tlp 0.8-1
which is available in 16.04 repositories. After updating to tlp 0.9-1
using linrunner ppa, ALL isssues were solved.
Original answer:
tlp
masks/disables systemd-rfkill.service
to "avoid conflicts and assure proper operation of TLP's radio device switching options". ( Source-1 , Source-2 )
This means passing the kernel parameter won't work for you.
Here is a little snippet (around line no. 195) from tlp's default configuration file (/etc/default/tlp
).
# Restore radio device state (Bluetooth, WiFi, WWAN) from previous shutdown
# on system startup: 0=disable, 1=enable.
# Hint: the parameters DEVICES_TO_DISABLE/ENABLE_ON_STARTUP/SHUTDOWN below
# are ignored when this is enabled!
RESTORE_DEVICE_STATE_ON_STARTUP=0
# Radio devices to disable on startup: bluetooth, wifi, wwan.
# Separate multiple devices with spaces.
#DEVICES_TO_DISABLE_ON_STARTUP="bluetooth wifi wwan"
# Radio devices to enable on startup: bluetooth, wifi, wwan.
# Separate multiple devices with spaces.
#DEVICES_TO_ENABLE_ON_STARTUP="wifi"
-
As you can see the option to
RESTORE_DEVICE_STATE_ON_STARTUP
is disabled by default. But enabling that option does not help.Even after you enable the option to
RESTORE_DEVICE_STATE_ON_STARTUP
, disable wifi and bluetooth (usingrfkill block all
) and keep restarting, somehow WiFi get enabled on every 2nd or 3rd boot. There is no guarantee that on next boot WiFi will be disabled. Surprisinglytlp
manages to keep bluetooth disabled on every boot. -
Same goes for 2nd option in the snippet,
DEVICES_TO_DISABLE_ON_STARTUP
, which is also disabled by default. Enabling it doesn't work either.Network Manger
shows that WiFi is disabled butrfkill list
doesn't show any soft-block on WiFi.Note : I have read the line
"Hint: the parameters DEVICES_TO_DISABLE/ENABLE_ON_STARTUP/SHUTDOWN below are ignored when this is enabled!"
.I disabled
RESTORE_DEVICE_STATE_ON_STARTUP
before enablingDEVICES_TO_DISABLE_ON_STARTUP
to avoid conflicts. - Similarly the other options provided
tlp-rdw
don't work as expected.
Solution for tlp
users :
Update : Update to tlp 0.9-1
using linrunner ppa.
Original Answer:
Enabling
DEVICES_TO_DISABLE_ON_STARTUP
and setting it to disable Bluetooth and WiFi may work for you.( It worked for this person )This question here on askubuntu. It is similar to an older answer to this question. But please note that I haven't tried it myself. It may or may not work.
Other sources : systemd-rfkill , tlp-configuration
Solution 4
The easiest way to disable your wireless card is to right-click on the NetworkManager indicator (small icon on top-right on the panel), and untick the Enable Wireless
. This brings down (ifconfig wlan0 down
) the interface and it does not perform scanning anymore.
Related videos on Youtube
Comments
-
RusGraf over 1 year
My desktop's PCI wireless card is always scanning for available wireless networks, but I only rarely use it. Can I keep the radio turned off until I need it?
-
RusGraf over 13 yearsChecking this menu item does not affect the default behavior. The next time I turn on the computer, the wireless radio is active again.
-
RusGraf about 13 yearsThanks. I don't understand why, but it looks like I don't need to use sudo for rfkill to work.
-
Lekensteyn about 13 yearsYou do not need sudo in
/etc/rc.local
as the script is run with root permissions. It's very unlikely you can disable wifi without root permissions. If I tryrfkill block wifi
orrfkill unblock wifi
, I get "Can't open RFKILL control device: Permission denied". -
RusGraf about 13 yearsOn both my ThinkPad X60 and my desktop with a PCI wireless card, running
$ rfkill block wifi
causes the NetworkManager applet to display "Wireless is disabled" and$ iwconfig
to displayTx-Power=off
.$ rfkill unblock wifi
undoes this effect. -
gertvdijk about 11 yearsWhile this will bring the interface down, it won't save as much power as disabling the radio using
rfkill
. -
rubo77 almost 10 yearsAt my Ubuntu 14.04 it stays off as desired after a reboot if I turn it of in the network manager applet
-
Lekensteyn almost 10 years@rubo77 That is a possibility, recent Network Manager versions allow to toggle the wifi state too. You can try to add the
rfkill list > /etc/wifi-state.txt
command to see if the command actually had any effect. -
rubo77 almost 10 yearsI checked and rebooted, it seems like right after the call in rc.local it is bocked:
1: phy0: Wireless LAN Soft blocked: yes Hard blocked: no
- but it seems to be unblocked shortly after again - lets discuss it here: Turn off the Wireless card on each boot -
rubo77 almost 10 yearsI solved it with a delay: It seems like in Ubuntu 14.04 you need to wait some seconds before you disable wifi in
/etc/rc.local
. Use this instead:/bin/sleep 10 && rfkill block wifi
-
Lekensteyn almost 10 years@rubo77 That is a horrible hack, racing against some service (Network-Manager?). What is wrong with the Network Manager option to disable Wi-Fi?
-
rubo77 almost 10 yearsCause then you always have to think about turning the wifi off yourself. Either after boot or at the end of a session where you exceptional needed the wifi once. I would be glad about a less "hacky" solution
-
rubo77 almost 10 yearsThe new "modern" solution doesn't always work: every now and then my laptop still unexpectedly boots with wifi enabled. (I am in chat again)
-
rubo77 almost 10 yearsI think we have to use advanced logging for the upstart sequence to find out, which service is re-enabling and unblocking wifi after the first rfkill blocks it And why the
sed
command on the NetworkManager state file dows not always work -
rubo77 almost 10 yearsI tested it twice: if you add both lines to your
rc.local
it works to disable wifi:sed s/^WirelessEnabled=true/WirelessEnabled=false/ -i /var/lib/NetworkManager/NetworkManager.state
andrfkill block wifi
-
froage over 9 yearsEven the "modern" solution including both
sed
andrfkill
lines does not work for me on either of two laptops. What I see in/var/log/syslog
hints that Network Manager starts up, reads/var/lib/NetworkManager/NetworkManager.state
and that between that read and its configuration of the wireless device, the commands in/etc/rc.local
are run. That's too late for thesed
to achieve anything and too early for therfkill
to achieve anything. Adding asleep 10
prior to therfkill
is a crude workaround, but I've posted an alternative answer to this question that I think is better. -
Patrick Dark over 4 yearsI tried your answer involving the modifications of both
GRUB_CMDLINE_LINUX
andGRUB_CMDLINE_LINUX_DEFAULT
plus the (unmentioned)sudo update-grub
command and I couldn't get it to work in Pop_OS! 19.10 (which is based on Ubuntu 19.10). According tosystemctl status systemd-rfkill
, this service is already being run on every boot and, since the default value is1
, there should be no need for this effort. Based on the info atman systemd-rfkill
, remembering the radio state "at early boot" should be the default behavior, which leads me to believe that this component is somehow broken.