我有一个大的OpenVPNnetworking。 大部分地址都可以自由访问。 但是,less数IP只需要限制在其他几个IP上。
例如,只允许10.8.0.6与10.8.0.10通信。但是10.8.0.10和子网中的所有其他地址可以无限制地相互通信。 下面的iptables代码会完成这个吗?
# allow communication between 10.8.0.6 and 10.8.0.10, deny any additional # access to 10.8.0.6 iptables -A FORWARD -s 10.180.0.6 -d 10.8.0.10 -j ACCEPT iptables -A FORWARD -s 10.180.0.10 -d 10.8.0.6 -j ACCEPT iptables -A FORWARD -s 10.180.0.6 -j DROP # Begin required lines for server operation iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 10.8.0.0/16 -j ACCEPT iptables -A FORWARD -j REJECT iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -o eth0 -j MASQUERADE /etc/init.d/dnsmasq restart # End required lines for server operation
谢谢
你是对的,它应该是10.8.xx但是,它仍然没有工作。 我试图限制的地址仍然可以访问所有的服务器。 这是我目前的rc.local
# Begin access restriction lines # eg. allow communication between 10.8.0.122 and 10.8.0.58, deny any additional$ # client access only to certain systems iptables -A FORWARD -s 10.8.0.122 -d 10.8.0.58 -j ACCEPT iptables -A FORWARD -s 10.8.0.122 -d 10.8.0.66 -j ACCEPT iptables -A FORWARD -s 10.8.0.122 -d 10.8.0.70 -j ACCEPT iptables -A FORWARD -s 10.8.0.122 -d 10.8.0.62 -j ACCEPT iptables -A FORWARD -s 10.8.0.122 -j DROP # client access only to certain systems iptables -A FORWARD -s 10.8.0.126 -d 10.8.0.58 -j ACCEPT iptables -A FORWARD -s 10.8.0.126 -d 10.8.0.66 -j ACCEPT iptables -A FORWARD -s 10.8.0.126 -d 10.8.0.70 -j ACCEPT iptables -A FORWARD -s 10.8.0.126 -d 10.8.0.62 -j ACCEPT iptables -A FORWARD -s 10.8.0.126 -j DROP # End access restriction lines # Begin required lines for server operation iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 10.8.0.0/16 -j ACCEPT iptables -A FORWARD -j REJECT iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -o eth0 -j MASQUERADE /etc/init.d/dnsmasq restart # End required lines for server operation exit 0
谢谢
更新:
iptables -L -v -n的输出
root@li590-32:~# iptables -L -n -v Chain INPUT (policy ACCEPT 2455K packets, 430M bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 4597K 2770M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 32180 1813K ACCEPT all -- * * 10.8.0.0/16 0.0.0.0/0 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT all -- * * 10.8.0.0/16 0.0.0.0/0 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT all -- * * 10.8.0.0/16 0.0.0.0/0 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 0 0 ACCEPT all -- * * 10.8.0.122 10.8.0.58 0 0 ACCEPT all -- * * 10.8.0.122 10.8.0.66 0 0 ACCEPT all -- * * 10.8.0.122 10.8.0.70 0 0 ACCEPT all -- * * 10.8.0.122 10.8.0.62 0 0 DROP all -- * * 10.8.0.122 0.0.0.0/0 0 0 ACCEPT all -- * * 10.8.0.126 10.8.0.58 0 0 ACCEPT all -- * * 10.8.0.126 10.8.0.66 0 0 ACCEPT all -- * * 10.8.0.126 10.8.0.70 0 0 ACCEPT all -- * * 10.8.0.126 10.8.0.62 0 0 DROP all -- * * 10.8.0.126 0.0.0.0/0 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT all -- * * 10.8.0.0/16 0.0.0.0/0 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT 3144K packets, 2737M bytes) pkts bytes target prot opt in out source destination
当我认为你的意思是10.8.xx时,前三行代表10.180.xx?
如果是这样的话, iptables -A FORWARD -s 10.180.0.10 -d 10.8.0.6 -j ACCEPT是不必要的。
否则看起来不错。
iptables工作原理是以第一种方式匹配为基础,所以您发布的完整规则集使问题变得清晰:前两行后面没有任何限制可以看到任何stream量,因为第一个和第二个规则匹配 – 并允许 – 所有的交通,你试图匹配和否认以后。
要么你需要找出前两行的位置,并确保你所有的行被移到前面, 否则你需要在前两行之前插入所有新的行,使用iptables -I FORWARD 1在上面的脚本中,不断地在FORWARD链的开头插入每一行,而不是将其添加到最后。
以前的方法是首选,因为它更容易维护; 但是你不知道你在做什么发行版,所以我不能说规则在哪里设置。
无论哪种方式,您都需要确保在最后一个链中,高度特定的DROP规则出现在任何可以匹配(并因此允许)相同stream量的较不具体的ACCEPT规则之前。