欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS 配置防火墙详解及实例

程序员文章站 2023-09-09 10:02:43
 centos配置防火墙 昨天帮朋友配置centos服务器,一开始为了方便测试直接把防火墙关了,之后便需要配置好防火墙,网上找了几个防火墙规则都有错误,后来发现...

 centos配置防火墙

昨天帮朋友配置centos服务器,一开始为了方便测试直接把防火墙关了,之后便需要配置好防火墙,网上找了几个防火墙规则都有错误,后来发现是博主发帖不认真,有太多字符错误,下面是我整理的亲测可用的防火墙规则的配置过程:

修改 iptables-config

首先修改iptables-config文件的一个配置项

$ vi /etc/sysconfig/iptables-config

把文件最后一行iptables_modules="ip_conntrack_ftp" 改为#iptables_modules="ip_conntrack_ftp" ,即注释掉那一行配置项

添加规则

$ vi /etc/sysconfig/iptables
*filter
:input accept [0:0]
:forward accept [0:0]
:output accept [5:564]
:rh-firewall-1-input - [0:0]
-a input -p tcp -m tcp --dport 3306 -j accept 
-a input -j rh-firewall-1-input 
-a forward -j rh-firewall-1-input 
-a rh-firewall-1-input -i lo -j accept 
-a rh-firewall-1-input -p icmp -m icmp --icmp-type any -j accept 
-a rh-firewall-1-input -p esp -j accept 
-a rh-firewall-1-input -p ah -j accept 
-a rh-firewall-1-input -m state --state related,established -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 53 -j accept 
-a rh-firewall-1-input -p udp -m state --state new -m udp --dport 53 -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 22 -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 25 -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 80 -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 8080 -j accept 
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 443 -j accept 
-a rh-firewall-1-input -j reject --reject-with icmp-host-prohibited 
commit

已经包含mysql数据库的3306端口和tomcat的8080端口,可根据需要增删端口。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!