30

I've brought down a network interface with ifconfig wlan0 down, but every few hours or so, the wlan0 interface comes back up and I can't figure out why.

I don't restart the machine, never changed /etc/network/interface. I guess my question is, how would I go about just "permanently" disabling wlan0. Do I use /etc/network/interface? I already have ifconfig wlan0 down in my rc.local.

4 Answers 4

36

Method #1 - from NetworkManager's Applet

Try disabling the wireless networking under the Network Applet that's accessible from under the icons in the upper right of your desktop.

                                                    ss #!

NOTE: The networking applet's icon looks like a triangle wedge. The image above is pointing to is as arrow #1. If you click it you should see a menu slide out from where you can disable wireless permanently, arrow #2.

Method #2 - /etc/network/interfaces

From the file /etc/network/interfaces you can specify that NetworkManager shouldn't control the wlan0 interface. To do so simply add this line to the above mentioned file:

iface wlan0 inet manual

Then restart NetworkManager:

$ sudo service network-manager restart

References

1
  • 2
    Method 1 only works if you have only one wifi card...
    – xuhdev
    Jan 8, 2015 at 22:55
5

I had to do something similar to this but wanted the device to not come up at all. We have physically covered up an ethernet port in a linux based device and so it shouldn't appear at all.

I did this with udev rules.

This udev rule will tell linux to remove the pci device when a network device which has the ID_NET_NAME_ONBOARD of eno2 is added. Add it to e.g. /etc/udev/rules.d/90-disable-eno2.rules.

ACTION=="add", SUBSYSTEM=="net", ENV{ID_NET_NAME_ONBOARD}=="eno2", RUN+="/bin/sh -c 'echo 1 > /sys$DEVPATH/device/remove'"

The magic environment variables like ID_NET_NAME_ONBOARD are set by udev here. I have copied some examples from the comment in that file below.

PCI Ethernet card with firmware index "1":
    ID_NET_NAME_ONBOARD=eno1
    ID_NET_NAME_ONBOARD_LABEL=Ethernet Port 1

PCI Ethernet card in hotplug slot with firmware index number:
    /sys/devices/pci0000:00/0000:00:1c.3/0000:05:00.0/net/ens1
    ID_NET_NAME_MAC=enx000000000466
    ID_NET_NAME_PATH=enp5s0
    ID_NET_NAME_SLOT=ens1

PCI Ethernet multi-function card with 2 ports:
    /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/enp2s0f0
    ID_NET_NAME_MAC=enx78e7d1ea46da
    ID_NET_NAME_PATH=enp2s0f0
    /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.1/net/enp2s0f1
    ID_NET_NAME_MAC=enx78e7d1ea46dc
    ID_NET_NAME_PATH=enp2s0f1

PCI wlan card:
    /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0
    ID_NET_NAME_MAC=wlx0024d7e31130
    ID_NET_NAME_PATH=wlp3s0

USB built-in 3G modem:
    /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.6/net/wwp0s29u1u4i6
    ID_NET_NAME_MAC=wwx028037ec0200
    ID_NET_NAME_PATH=wwp0s29u1u4i6

USB Android phone:
    /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/net/enp0s29u1u2
    ID_NET_NAME_MAC=enxd626b3450fb5
    ID_NET_NAME_PATH=enp0s29u1u2

s390 grouped CCW interface:
    /sys/devices/css0/0.0.0007/0.0.f5f0/group_device/net/encf5f0
    ID_NET_NAME_MAC=enx026d3c00000a
    ID_NET_NAME_PATH=encf5f0

When testing your rules you will need to run a command like the following to make sure everything is matching and syntax is correct.

# Find the path marked "P" with this command.
udevadm info --path=/sys/class/net/eno2

# Test with this command with the path from above
udevadm test --action="add" /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/eno2 2>&1 | less
1
  • Used lshw to determine the network interface logical name as ens32 and from udevadm info --path=/sys/class/net/ens32 determined ID_NET_NAME_SLOT environment variable and used that as in your answer. Worked. +1
    – rusty
    Jan 13 at 6:10
2

You can permanently disable a network interface using systemd. For example if you want to disable wlan0:

$ systemctl | grep wlan0
sys-devices-platform-soc-XXX.auto-net-wlan0.device loaded active plugged   /sys/devices/platform/soc/XXX.auto/net/wlan0
sys-subsystem-net-devices-wlan0.device             loaded active plugged   /sys/subsystem/net/devices/wlan0                                                                     
[email protected]                       loaded active running   WPA supplicant daemon (interface-specific version)                                                   

Next take them one by one, check out what they do:

$ systemctl status [email protected][email protected] - WPA supplicant daemon (interface-specific version)
   Loaded: loaded (/lib/systemd/system/wpa_supplican[email protected]; disabled; vendor preset: enabled)
   Active: active

Stop and disable them:

$ sudo systemctl stop [email protected]
$ sudo systemctl disable [email protected]

Disabling [email protected] for example will have the effect that the wlan0 interface will not attempt to connect to the wireless network.

2
  • I think this is the most up to date answer. That is if systemd init is used.
    – 71GA
    Dec 6, 2021 at 10:02
  • even on the pi, where systemd is used, this doesn't work :-(
    – Sam
    Oct 29, 2022 at 5:54
0

You could also consider blacklisting the network controller from loading:

  1. Find the ethernet controller: lspci -k
  2. Note the module name and append to the blacklist file: echo blacklist [module-name] >> /etc/modprobe.d/blacklist.conf
  3. Run update-initramfs -u
  4. Reboot to apply changes.

This will stop the system from loading the network card, but please keep in mind that it will disable all network controllers that use the same driver.

To undo this, simply comment or remove the entries and run step 3 and 4 again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .