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端口,可根据需要增删端口。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关推荐
summerinsist 2020-08-21
Aveiox 2020-06-25
yshlovelx 2020-05-27
Wepe0 2020-10-30
Lostinthewoods 2020-10-29
hickwu 2020-10-23
focusforce 2020-10-10
winki 2020-08-19
89284553 2020-07-17
大老张学编程 2020-07-04
xiaohouye 2020-06-28
lizhengfa 2020-06-26
clamzxf 2020-06-16
kerson 2020-06-16
zhangwentaohh 2020-06-14
学峰的学习笔记 2020-06-11