我正在使用linode.com,他们提供了一个私人IP分配给每个VPS的能力。 我试图做的是设置每个节点的防火墙,以允许从networking上的其他节点访问,但我似乎没有太大的成功。
例如,我试图允许从server2访问server1:1337,两者的设置如下:
server1: ifcfg-eth0: DEVICE="eth0" IPADDR="1.1.1.1" NETMASK="255.255.255.0" ifcfg-eth0:0: DEVICE="eth0:0" IPADDR="192.168.132.96" NETMASK="255.255.128.0" server2: ifcfg-eth0: DEVICE="eth0" IPADDR="1.1.1.2" NETMASK="255.255.255.0" ifcfg-eth0:0: DEVICE="eth0:0" IPADDR="192.168.132.97" NETMASK="255.255.128.0"
和server1上的IPTables规则集:
#----- # Flush all current rules from iptables# #----- iptables -F iptables -F -t nat #----- #----- # Set access for localhost #----- iptables -A INPUT -i lo -j ACCEPT # !! Tried to allow all nodes on the subnet access to everything, but still didn't work !! iptables -A INPUT -s 192.168.132.0/17 -j ACCEPT #----- #----- # Accept packets belonging to established and related connections #----- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #----- # !! Tried to allow access to the port directly !! iptables -A INPUT -i eth0:0 -p tcp -s 192.168.132.0/17 --dport 1337 -j ACCEPT #----- # Lock everything down #----- iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT ACCEPT #-----
我偶然发现了几个旧的论坛,指出iptables不能使用-i eth0:0调用,因为虚拟设置共享父设置,但我无法完全确认。
– 编辑 –
我也添加了私有子网(192.168.132.0/17)到server2,但仍然无法连接。
感谢来自linode技术支持的意见和一些信息的build议,我能够解决连接问题。
为了解决这个问题,我需要确保server1和server2都有iptables的私有子网项。
iptables -A INPUT -s 192.168.132.0/17 -j ACCEPT
在两台服务器上都input完成后,我可以telnet到服务器2:1337(从server1),并通过iptables监视字节/数据包,看看数据包是否被接受:
$ -> telnet 192.168.132.97 1337 Trying 192.168.132.97... Connected to 192.168.132.97. Escape character is '^]'. $ -> iptables -L -vn Chain INPUT (policy DROP 337 packets, 18695 bytes) pkts bytes target prot opt in out source destination 56 30019 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 53 40539 ACCEPT all -- * * 192.168.128.0/17 0.0.0.0/0
现在的问题是,我正在使用nginx作为负载平衡器,它使用server2 dns条目,我假设默认为公共ip,这不是iptables规则集的一部分,也不应该,否则我必须进入在私人networking上的每一个IP允许访问端口1337.然而这个问题是另一个问题,因为OP已经解决。
– 更新 –
更新这个答案,以防其他人在将来遇到问题。 我select了这个解决scheme。 DNS隐形 。 通过将DNSfunction添加到我的一个VPS,我可以添加所有的内部IPS和外部IPS,所以我所有的内部iptableconfiguration应该按预期工作,同时仍然允许通过其公共IP远程访问任何vps。