如何使用 netplan 禁用 WiFi 接口?

如何使用 netplan 禁用 WiFi 接口?

我的netplan配置/etc/netplan/wireless.yaml似乎适用于我的 WiFi-USB 适配器,但我似乎仍然可以看到本机界面。我更愿意将其关闭。目前,sudo ifconfig wlp0s20f3 down使用配置似乎无法在重新启动后保留:

# See also: https://netplan.io/reference
network:
  version: 2
  renderer: networkd
  wifis:
    wlx7ca7b0babcf7:
      dhcp4: yes
      dhcp6: no
      addresses: [192.168.7.12/24] 
      gateway4: 192.168.7.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      access-points:
        "my_network":
          password: "my_password"

我该如何调整 netplan 配置以保持本机 WiFi 接口关闭?这是否只能在其他地方配置为永久关闭?

附加信息

$ cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

注意我有一个连接到的 LAN:

$ sudo lshw -C network
  *-network                 
       description: Wireless interface
       product: Intel Corporation
       vendor: Intel Corporation
       physical id: 14.3
       bus info: pci@0000:00:14.3
       logical name: wlp0s20f3
       version: 00
       serial: 0c:dd:24:1c:52:55
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=iwlwifi driverversion=5.3.0-7629-generic firmware=48.4fa0041f.0 ip=10.53.189.39 latency=0 link=yes multicast=yes wireless=IEEE 802.11
       resources: irq:16 memory:d3510000-d3513fff
  *-network
       description: Ethernet interface
       product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0.1
       bus info: pci@0000:26:00.1
       logical name: ethA
       version: 12
       serial: 80:fa:5b:7a:b1:cc
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 firmware=rtl8411-2_0.0.1 07/08/13 latency=0 link=no multicast=yes port=MII
       resources: irq:16 ioport:4000(size=256) memory:d3215000-d3215fff memory:d3210000-d3213fff
  *-network:0
       description: Ethernet interface
       physical id: 1
       logical name: ethA.200
       serial: 80:fa:5b:7a:b1:cc
       capacity: 1Gbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=802.1Q VLAN Support driverversion=1.8 firmware=N/A link=no multicast=yes port=MII
  *-network:1
       description: Wireless interface
       physical id: 2
       bus info: usb@1:3
       logical name: wlx7ca7b0babcf7
       serial: 7c:a7:b0:ba:bc:f7
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=rtl88x2bu multicast=yes wireless=unassociated

/etc/netplan/01-network-manager-all.yaml包含内容:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

也可以看看

https://unix.stackexchange.com/a/111258/32951

答案1

将您的设置/etc/network/interfaces为:

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown
#
auto wlp0s20f3
iface wlp0s20f3 inet manual
     pre-up ifconfig $IFACE down
     pre-down ifconfig $IFACE down
     down ifconfig $IFACE down

笔记:你可能必须sudo apt install ifupdown


将您的设置/etc/netplan/wireless.yaml为:

network:
  version: 2
  renderer: networkd
  wifis:
    wlx7ca7b0babcf7:
      addresses: [192.168.7.12/24]
      gateway4: 192.168.7.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      access-points:
        "my_network":
          password: "my_password"

sudo netplan --debug generate

sudo netplan apply

reboot

答案2

只需在此处添加即可,以防有人从 Google 登陆。

我并不是想用 Netplan 专门禁用 Wifi,只是在现代 Ubuntu 中使用 Netplan 以任何方便的方式禁用它。

事实证明,我发现的最佳方法是配置 NetworkManager 以忽略 wifi 接口。我无法仅使用 Netplan 来做到这一点。

我找到了有关如何做到这一点的信息这里

基本上添加一个文件/etc/NetworkManager/conf.d/99-unmanaged-devices.conf

内容如下:

[keyfile]
unmanaged-devices=interface-name:ethWifi

(将 ethWifi 替换为您的 wifi 设备的名称。)

然后使用以下命令重新启动 NetworkManager:

systemctl reload NetworkManager

并且Wifi接口已关闭,无法再次连接。

相关内容