Linux下设置Iptable只允许某个ip访问3306端口

2014年12月31日19:04:15 发表评论 6,311 ℃

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: