Solved How to toggle off/on network (wireless and ethernet)

Hi

I am using a T440P laptop with FREEBSD 12.2p4 and DWM. So, I want to be able to easily toggle on and off all network to my laptop.
What are the command to temporarily disable internet? And commands to renable it?

Currently, I just comment out the ifconfig_wlan0 and ifconfig_em0 in /etc/rc.conf. But that requires a reboot.

Code:
ifconfig_em0="DHCP"
wlans_iwm0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"

What is the proper way to disable or enable internet network?

Thanks!
 
I comment out the lines in /etc/rc.conf. If I have ethernet plugged in, once the thing boots up I can just dhclient <interface-name>. I also have a little script, that I can run when I boot up, if I want wireless. This is mostly in one location, so the config file is the default in /etc/wpa_supplicant.conf.
My wireless card is iwm0.
Code:
sudo ifconfig wlan create wlandev iwm0
sudo wpa_supplicant -B -iwlan0 -c /etc/wpa_supplicant.conf
sudo dhclient wlan0
My /etc/wpa_supplicant.conf file is set to my home network.

If you have a bunch of different locations where you use wireless, you could make a few different scripts, pointing to the configurations for each location.
 
Usually there's no need to have multiple wpa_supplicant.conf(5) files, since wpa_supplicant.conf(5) can have multiple network={...} WLAN networks. You can en/disable them on demand with wpa_cli(8) or any of the graphical tools I mentioned above. I can report that wpa_gui(8) works ok.

To switch between different usage scenarios, e.g. office/home, you can use alfio(8) to manage profiles. Honestly I don't know how good it is, never used up to now; it's on my TODO list.
 
Y'know, it's been so long since I've needed and used that feature (mid 2000's) that I'd forgotten. Yes, Mjolnir is right, rather than multiple conf files, you can use multiple network entries.
 
Y'know, it's been so long since I've needed and used that feature (mid 2000's) that I'd forgotten. Yes, Mjolnir is right, rather than multiple conf files, you can use multiple network entries.
Commenting out a setting in a config file has the invaluable advantage that the previous value is saved in the file. sysrc(8) doesn't offer that; you can either delete a variable (-x), or set it to new value, but then it's old value is gone. Concerning the use-case profiles: for simple setups, it might be overkill to rely on an extra tool, as it might have bugs & adds extra complexity. Then of course it's reasonable to do by-feet e.g. comment out/in etc.
 
I did acpiconf -i0 to show the power usage.
After I turned off wifi using service netif stop (as suggested by bsduck), my t440p consumes about 500mW less power than before.
(From about 13,000 mW to 12,500 mW)

So, does service netif stop actually stop all hardware and software wifi related activity?

Or is there another command to turn off wifi hardware?

I am trying to maximize battery life when I don:t need wifi.
 
Back
Top