使用两个 Internet 连接运行 Debian 10。
主连接断开并定期恢复。
什么时候wlan0
倒下我怎么能enp0s6f1u2
接手?互联网继续在本地机器上运行,但不适用于网络上的其他设备,因为wlan0
它已硬编码到我的iptables
脚本中。
我怎么说iptables
:输出伪装到默认路由所在的任何接口?
/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
iface enp0s10 inet manual
### WiFi for access point
allow-hotplug wlx00e032800384
iface wlx00e032800384 inet manual
pre-up ip link set dev wlx00e032800384 address 02:e0:32:80:03:80
### Bridge: internal network
auto br0
iface br0 inet static
# bridge_ports enp0s10 wlx00e032800384
bridge_ports enp0s10 ap_wep ap_open
address 192.168.1.31
netmask 255.255.255.0
### WiFi to Internet: physical plus virtual for each network defined in wpa_supplicant.conf
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
# wpa-ssid RWB
# wpa-psk MYWIFI3518
allow-hotplug RWB
iface RWB inet dhcp
metric 1
### 4G to Internet (failover)
auto enp0s6f1u2
allow-hotplug enp0s6f1u2
iface enp0s6f1u2 inet dhcp
metric 9999
iptables
脚本
#!/bin/sh
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
# Squid transparent proxy for HTTP (not HTTPS)
iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j DNAT --to 192.168.1.31:3128
iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j REDIRECT --to-port 3128
# IP masquerade
iptables -A FORWARD -o wlan0 -i br0 -s 192.168.1.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
# echo 1 > /proc/sys/net/ipv4/ip_forward
iptables-save > /etc/iptables/rules.v4
一些ip route
当两个接口都启动时:
# ip route
default via 192.168.43.40 dev wlan0 metric 1
default via 192.168.42.129 dev enp0s6f1u2 metric 9999
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.31
192.168.42.0/24 dev enp0s6f1u2 proto kernel scope link src 192.168.42.221
192.168.43.0/24 dev wlan0 proto kernel scope link src 192.168.43.7
何时wlan0
下降:
# ip route
default via 192.168.42.129 dev enp0s6f1u2 metric 9999
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.31
192.168.42.0/24 dev enp0s6f1u2 proto kernel scope link src 192.168.42.221