这是我在 bash 中运行的 iptables 脚本。配置的保存是脚本的一部分。
#!/bin/bash
#
# iptables-konfigurasjon
#
# Set default rule to ACCEPT to avoid being locked out
iptables -P INPUT ACCEPT
# Flush all excisting rules
iptables -F
# New default rules
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# localhost:
iptables -A INPUT -i lo -j ACCEPT
# Not entirely shure what this is about....:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH.
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow http traffic for tomcat:
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
# Save rules:
/sbin/service iptables save
但是,经过测试,这些规则似乎根本没有效果。
示例:如果我注释掉允许流量到我的 tomcat 服务器的行,我仍然可以从外部访问我的 tomcat 服务器......即使在重新启动后。
我的脚本有什么问题?
顺便说一句:我正在使用 CentOS 6。
最佳答案
将新添加的规则保存到您的iptables
后,您必须重新启动服务才能使更改生效。
/sbin/service iptables restart
或者
/etc/rc.d/init.d/iptables restart
关于centos - 对 iptables 的更改没有效果。我的脚本有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18047550/