这个设置有什么问题?主机和客户机都是 CentOS 6.5
具体来说,我无法在客人上运行 yum。
我可以顺利地与客户机进行 ping 操作,包括 ping mirrorlist.centos.org
如果我从主机 iptables 中删除端口 80 规则(见下文),yum 就可以正常工作。但我需要该规则,以便我可以将客户机用作可公开访问的 Web 服务器。
yum 更新输出:
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
12: Timeout on http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os: (28, 'connect() timed out!')
Error: Cannot find a valid baseurl for repo: base
Guest 的 IP 是 192.168.122.47,我下面设置的 ssh 端口转发可以正常工作,但是 yum 却不行。
访客 iptables 已被禁用。
主机 iptables:
# Generated by iptables-save v1.4.7 on Sat May 10 15:54:24 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:560]
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sat May 10 15:54:24 2014
# Generated by iptables-save v1.4.7 on Sat May 10 15:54:24 2014
*mangle
:PREROUTING ACCEPT [4:316]
:INPUT ACCEPT [4:316]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:560]
:POSTROUTING ACCEPT [4:560]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Sat May 10 15:54:24 2014
# Generated by iptables-save v1.4.7 on Sat May 10 15:54:24 2014
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 792 -j DNAT --to-destination 192.168.122.47:22
-A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.122.47:80
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE
COMMIT
# Completed on Sat May 10 15:54:24 2014
答案1
你进行了过度 NAT;你进行的 NAT 不仅仅是在将连接绑定到端口 80,但出去绑定的也是如此。修改 NAT 规则以指定流量必须从外部传入,例如
-A PREROUTING -p tcp -m tcp -i eth0 --dport 80 -j DNAT --to-destination 192.168.122.47:80
并且它将停止匹配(和干扰)到外部网络服务器的合法出站流量。