![为什么 iptables 会阻止通过 ssh 连接到我的虚拟机?](https://linux22.com/image/229623/%E4%B8%BA%E4%BB%80%E4%B9%88%20iptables%20%E4%BC%9A%E9%98%BB%E6%AD%A2%E9%80%9A%E8%BF%87%20ssh%20%E8%BF%9E%E6%8E%A5%E5%88%B0%E6%88%91%E7%9A%84%E8%99%9A%E6%8B%9F%E6%9C%BA%EF%BC%9F.png)
我有一个运行 ssh 服务器的 kali 虚拟机,我想阻止通过 ssh 到这台机器的所有流量(除了我自己的电脑),为此我有这个 iptables 规则。
┌──(root㉿kali)-[/home/kali]
└─# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- DESKTOP-JMUOD0E.home anywhere tcp dpt:ssh
DROP tcp -- anywhere anywhere tcp dpt:ssh
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
┌──(root㉿kali)-[/home/kali]
└─# iptables -L -n -v --line-numbers
Chain INPUT (policy ACCEPT 419 packets, 33340 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT 6 -- * * 192.168.1.71 0.0.0.0/0 tcp dpt:22
2 0 0 DROP 6 -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 332 packets, 42224 bytes)
num pkts bytes target prot opt in out source destination
┌──(root㉿kali)-[/home/kali]
└─# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:de:55:8d brd ff:ff:ff:ff:ff:ff
inet 192.168.1.24/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
valid_lft 86249sec preferred_lft 86249sec
inet6 fe80::5a15:2c68:b1af:e663/64 scope link noprefixroute
valid_lft forever preferred_lft forever
我做错了什么?因为如果最后一条规则处于活动状态,但该规则具有我电脑的 IP,我的电脑无法进入...
我认为是因为我的虚拟机和nat的适配器,你们觉得呢?