我有一台包含多个容器的主机。我想从主机 ping 到容器,反之亦然。目前 ping 只能从容器内部到主机,例如:
root@c1313s02:~# vzctl enter 112
entered into CT 112
root@orbit:/# ping 192.168.1.21
PING 192.168.1.21 (192.168.1.21) 56(84) bytes of data.
64 bytes from 192.168.1.21: icmp_req=1 ttl=64 time=0.036 ms
64 bytes from 192.168.1.21: icmp_req=2 ttl=64 time=0.039 ms
64 bytes from 192.168.1.21: icmp_req=3 ttl=64 time=0.037 ms
^C
--- 192.168.1.21 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.036/0.037/0.039/0.005 ms
root@orbit:/# exit
logout
exited from CT 112
尝试从主机 ping 到容器,不起作用:
root@c1313s02:~# ping -c 3 192.168.1.13
PING 192.168.1.13 (192.168.1.13) 56(84) bytes of data.
--- 192.168.1.13 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms
有时 IPTables 日志会显示:
Mar 25 11:11:13 c1313s02 kernel: IN=venet0 OUT= MAC= SRC=192.168.1.13 DST=192.168.1.21 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=1977 PROTO=ICMP TYPE=0 CODE=0 ID=64315 SEQ=18
我如何更新我的 IPTables 规则以允许从主机 ping 到容器?
答案1
我发现 proxmox 服务器创建了一个名为 的设备venet0
。所以现在我的 IPtables 如下所示:
...
$IPT -P INPUT DROP
$IPT -P OUTPUT DROP
...
$IPT -A INPUT -i venet0
现在我可以从容器 ping 到 VZ 主机,反之亦然。