Linux防火墙Iptable如何设置只允许某个ip访问3306端口,只允许特定ip访问某端口?参考下面命令,只允许1.2.3.4访问本机的3306端口。如果要设置其他ip或端口,改改即可。
-A INPUT -p TCP --dport 3306 -j DROP
-A INPUT -s 1.2.3.4 -p TCP --dport 3306 -j ACCEPT
在root用户下vi /etc/sysconfig/iptables添加上面命令,重启iptables, service iptables restart
查看iptables是否生效:
[root@www.msadmin.cn]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 1.2.3.4 anywhere tcp dpt:http
DROP tcp -- anywhere anywhere tcp dpt:http
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination