问题
因为微基禁止了http转发,所以用443端口作为转发目的地失效了。

解决方案
所以在vps上将入口端口变成4443,所有访问4443的流量全部转至443. 反之亦然。
Shell
x
31
31
1
# 开启转发功能
2
sed -i.bak "s|(#)net.ipv4.ip_forward.*=.*0|net.ipv4.ip_forward = 1|g" /etc/sysctl.conf
3
grep -i 'net.ipv4.ip_forward.*=.*1' /etc/sysctl.conf
4
sysctl -p #使数据转发功能生效
5
6
# 外网访问4443端口的数据转发到443端口 - 这是双向的
7
iptables -t nat -A PREROUTING -p tcp --dport 11443 -j REDIRECT --to-ports 443
8
iptables -t nat -A PREROUTING -p tcp --dport 22443 -j REDIRECT --to-ports 443
9
iptables -t nat -A PREROUTING -p tcp --dport 33443 -j REDIRECT --to-ports 443
10
iptables -t nat -A PREROUTING -p tcp --dport 44443 -j REDIRECT --to-ports 443
11
iptables -t nat -A PREROUTING -p tcp --dport 55443 -j REDIRECT --to-ports 443
12
13
# save rules
14
iptables-save > /etc/iptables.rules.v4
15
16
# 确保重启后仍然有效
17
iptables-restore < /etc/iptables.rules.v4
18
cat > /etc/systemd/system/restore-iptables-rules.service <<EOF
19
[Unit]
20
Description = Apply iptables rules
21
After=network.target
22
23
[Service]
24
Type=oneshot
25
ExecStart=/bin/sh -c 'iptables-restore < /etc/iptables.rules.v4'
26
27
[Install]
28
WantedBy=multi-user.target
29
EOF
30
31
systemctl enable --now restore-iptables-rules.service
删除
Shell
xxxxxxxxxx
1
7
1
ubuntu中iptables重启生效:
2
查看nat规则,并显示行号
3
iptables -t nat --list --line-number
4
5
删除一条nat 规则 删除SNAT规则
6
iptables -t nat -D POSTROUTING 1
7
iptables -t nat -D POSTROUTING 7
