屏蔽IP:
如果对某个ip 例如 192.168.34.63 用户屏蔽,可以执行如下语句:
# iptables -A INPUT -s 192.168.34.63 -j DROP
-A INPUT 给INPUT链增加了一个规则
-s 192.168.34.63 指定规则所针对的源IP
-j DROP 指的是,当数据包符合规则时,内核就会将其丢弃
所以机器就会丢弃所有来自 该ip 的数据包
查看设置好的规则:iptables -L
[root@www etc]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- 192.168.34.63 anywhere
如果该ip发动子网上的所有人请求SMTP (TCP端口25)连接,想屏蔽,执行如下命令:
# iptables -A INPUT -s 192.168.34.0/24 -p tcp --destination-port 25 -j DROP
增加了掩码限定符,并用-p tcp限定只屏蔽TCP包 ,用--destination-port 25 声明只屏蔽端口25
查看防火墙规则:
[root@www etc]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- 192.168.34.63 anywhere DROP tcp -- 192.168.34.0/24 anywhere tcp dpt:smtp
但现在你想地址为192.168.34.37的朋友不能给你发送邮件,如果你使用以下命令:
# iptables -A INPUT -s 192.168.34.37 -j ACCEPT
但是不管用,查明原因,看看防火墙规则:
[root@www etc]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- 192.168.34.63 anywhere DROP tcp -- 192.168.34.0/24 anywhere tcp dpt:smtp ACCEPT all -- 192.168.34.37 anywhere