palswim Asked: 2018-12-13 11:57:30 +0800 CST2018-12-13 11:57:30 +0800 CST 2018-12-13 11:57:30 +0800 CST 使用 NetworkManager 在连接到以太网时禁用 Wifi 772 当我通过以太网(有线)连接到网络时,如何禁用我的 Wifi 无线电,但如果我没有有线连接,则启用 Wifi 连接?本质上,我想要我的有线/无线连接状态的 XOR 开关。 networkmanager wifi 1 个回答 Voted Best Answer palswim 2018-12-13T11:57:30+08:002018-12-13T11:57:30+08:00 我找到了一个由 Ilija Matoski 编写的脚本来完成这个任务,它属于/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh. #!/bin/sh name_tag="wifi-wired-exclusive" syslog_tag="$name_tag" skip_filename="/etc/NetworkManager/.$name_tag" if [ -f "$skip_filename" ]; then exit 0 fi interface="$1" iface_mode="$2" iface_type=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f2) iface_state=$(nmcli dev | grep "$interface" | tr -s ' ' | cut -d' ' -f3) logger -i -t "$syslog_tag" "Interface: $interface = $iface_state ($iface_type) is $iface_mode" enable_wifi() { logger -i -t "$syslog_tag" "Interface $interface ($iface_type) is down, enabling wifi ..." nmcli radio wifi on } disable_wifi() { logger -i -t "$syslog_tag" "Disabling wifi, ethernet connection detected." nmcli radio wifi off } if [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "down" ]; then enable_wifi elif [ "$iface_type" = "ethernet" ] && [ "$iface_mode" = "up" ] && [ "$iface_state" = "connected" ]; then disable_wifi fi 此外,要禁用此切换操作,您可以创建文件/etc/NetworkManager/.wifi-wired-exclusive(例如 via touch)。
我找到了一个由 Ilija Matoski 编写的脚本来完成这个任务,它属于
/etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh
.此外,要禁用此切换操作,您可以创建文件
/etc/NetworkManager/.wifi-wired-exclusive
(例如 viatouch
)。