![我的 iptables 规则有什么问题导致 SSH 连接断开?](https://linux22.com/image/744878/%E6%88%91%E7%9A%84%20iptables%20%E8%A7%84%E5%88%99%E6%9C%89%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98%E5%AF%BC%E8%87%B4%20SSH%20%E8%BF%9E%E6%8E%A5%E6%96%AD%E5%BC%80%EF%BC%9F.png)
我正在尝试在我的 VPS 上设置 iptable 规则,以便它将我的 IP 地址列入白名单并丢弃来自所有其他 IP 地址的所有数据包。但是,当我尝试这样做时,我失去了 SSH 连接。
我尝试通过为我的 IP 地址编写两个 ACCEPT 规则来实现这一点。然后更改 INPUT、OUTPUT 和 FORWARD 链以断开所有连接。
root@user:~# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root@user:~# iptables -A INPUT -s [my_ip] -j ACCEPT
root@user:~# iptables -A OUTPUT -s [my_ip] -j ACCEPT
root@user:~# iptables -P FORWARD DROP
root@user:~# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- [my_ip] anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- [my_ip] anywhere
root@user:~# iptables -P INPUT DROP
root@user:~# iptables -P OUTPUT DROP
Connection reset by [VPS_ip] port 22
PS C:\Users\user_2> ssh root@[VPS_ip]
ssh: connect to host [VPS_ip] port 22: Connection timed out
答案1
以下行:
root@user:~# iptables -A OUTPUT -s [my_ip] -j ACCEPT
本来应该:
root@user:~# iptables -A OUTPUT -d [my_ip] -j ACCEPT