Linux下設置Iptable只允許某個ip訪問3306端口

2014年12月31日19:04:15 發表評論 8,113 ℃

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

【騰訊云】云服務器、云數據庫、COS、CDN、短信等云產品特惠熱賣中

發表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: