有没有办法更新iptables规则来阻止连接,而无需重新启动它?
这是我想要避免的行为的一个例子:
On shell#1: I start a ping command 8.8.8.8 On shell#2: I block ping command with iptables rules. On shell#1: The ping command is still working and I get replies from 8.8.8.8, but if I end the ping command and I restart it, now it will not work.
我想知道是否有办法阻止ping命令,而不需要重新启动它。
1)你问什么是iptables工作的最简单的方法 – 阻止所有的stream量到达目的地,而不pipe连接状态如何,这样现有的连接就会超时。 所以在你的例子
iptables -I OUTPUT -d 8.8.8.8 -j DROP
将立即阻止UDP(DNS),ICMP(ping)和TCP数据包达到8.8.8.8。 所以这似乎是你的答案。 如果您正在获取所描述的行为,请发布您正在使用的iptables命令行。
2)如果您确实需要其他行为,为了维护现有的连接,直到重新启动进程,您可以:
iptables -I OUTPUT -d 8.8.8.8 -m state --state NEW -j DROP
要么
iptables -I OUTPUT -d 8.8.8.8 -p tcp --syn -j REJECT
3)在高级的情况下,你想实际上closures一个build立的TCP连接,而不是阻止它,让它超时,你可能可能会基于-j REJECT --reject-with tcp-reset在input并输出链或运行tcpkill几秒钟。 这很难,几乎在所有情况下,你想打破与解决scheme1)的连接。