Linux防火墻Iptable如何設(shè)置只允許某個(gè)ip訪問3306端口,只允許特定ip訪問某端口?參考下面命令,只允許1.2.3.4訪問本機(jī)的3306端口。如果要設(shè)置其他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
贊
1
賞