默认情况下(我猜)Ubuntu 会在我断开 VPN 连接时切断我的互联网连接,这很好,除非你不想要它,并且每次都必须重新连接(停止并启动)你的连接。我该如何配置它,以便在断开特定 VPN 连接后它不会阻止我的流量?
答案1
解决此问题的一种方法是为网络管理器创建一个调度脚本,它将自动为您执行此操作。
/etc/NetworkManager/dispatcher.d/80-ppp-vpn-down
使用下列内容创建:
#!/usr/bin/env bash
##
# The environment contains more information about the interface and the connection:
# DEVICE_IFACE - The interface name of the control interface of the device
main() {
local interface="$1"
local event="$2"
if [[ "${interface}" =~ "ppp"* && "${event}" == "vpn-down" ]]; then
local connection
connection="$(nmcli -t -f NAME,DEVICE connection show --active | awk -F: '/'"${DEVICE_IFACE}"'/ {print $1}')" || return 1
nmcli connection down id "${connection}"
nmcli connection up id "${connection}"
fi
}
main "$@"
exit $?
确保它也可执行:
chmod +x /etc/NetworkManager/dispatcher.d/80-ppp-vpn-down