Linux入门教程:centos iptables只允许某一ip访问某端口设置方法,


首先,清除所有预设置

iptables -F

其次,设置只允许指定ip地址访问指定端口

1、在tcp协议中,禁止所有的ip访问本机的8080端口。

iptables -I INPUT -p tcp --dport 8080 -j DROP

2、允许192.168.1.123访问本机的1521端口

iptables -I INPUT -s 211.211.211.211 -p tcp --dport 8080 -j ACCEPT

最后,保存当前规则

/etc/rc.d/init.d/iptables save 
service iptables restart

添加后打开iptables后如图所示,

-A INPUT -s 192.168.1.123/32 -p tcp -m tcp --dport 1521 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 1521 -j DROP

相关内容