Linux防火墙Iptable如何设置只允许某个ip访问80端口,只允许特定ip访问某端口?参考下面命令,只允许46.166.150.22访问本机的80端口。如果要设置其他ip或端口,改改即可。iptables -I INPUT -p TCP --dport 80 -j DROPiptables -I INPUT -s 46.166.150.22 -p TCP --dport 80 -j ACCEPT在root用户下执行上面2行命令后,重启iptables, service iptables restart查看iptables是否生效:[[email protected]]# iptables -LChain INPUT (policy ACCEPT)target prot opt source destination ACCEPT tcp -- 46.166.150.22 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 上面命令是针对整个服务器(全部ip)禁止80端口,如果只是需要禁止服务器上某个ip地址的80端口,怎么办?下面的命令是只允许来自174.140.3.190的ip访问服务器上216.99.1.216的80端口iptables -A FORWARD -s 174.140.3.190 -d 216.99.1.216 -p tcp -m tcp --dport 80 -j ACCEPT iptables -A FORWARD -d 216.99.1.216 -p tcp -m tcp --dport 80 -j DROP如果您不熟悉linux的ssh命令,那么可以在webmin/virtualmin面板中设置,达到相同效果。参考:webmin面板怎样设置允许特定ip访问80端口,禁止80端口 更多iptables参考命令如下:1.先备份iptables # cp /etc/sysconfig/iptables /var/tmp 需要开80端口,指定IP和局域网 下面三行的意思: 先关闭所有的80端口 开启ip段192.168.1.0/24端的80口 开启ip段211.123.16.123/24端ip段的80口 # iptables -I INPUT -p tcp --dport 80 -j DROP # iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT 以上是临时设置。 2.然后保存iptables # service iptables save 3.重启防火墙 #service iptables restart
时间: 2024-12-25 01:04:22