标签:doc tab 操作 font 启用 firewalld accept 关闭 设置
2,CentOS 7中防火墙是一个非常的强大的功能,是在CentOS 6.5中在iptables防火墙中进行的升级。
3,firewall配置
1,系统配置目录(目录中存放定义好的网络服务和端口参数,系统参数,不能修改)
/usr/lib/firewalld/services
2,用户配置目录
/etc/firewalld/
3,查询状态,开放端口,启用
查询服务状态 systemctl status firewalld 查看firewall状态 firewall-cmd --state
查询哪些端口开放
firewall-cmd --list-port 查询端口是否开放(eg:80) firewall-cmd --query-port=80/tcp
开放端口(eg:80)
firewall-cmd --zone=public --add-port=80/tcp --permanent
移除端口(eg:8080)
firewall-cmd --permanent --remove-port=8080/tcp
重启防火墙(修改配置后要重启防火墙)
systemctl start firewalld.service #firewall启动
systemctl enable firewalld.service #firewall开机启动
systemctl restart firewalld.service // firewall-cmd --reload
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2,--zone #作用域,Zone的概念,可以将具体的端口制定到具体的zone配置文件中
补:如果–zone=dmz 这样设置的话,会在dmz.xml文件中新增一条
3,--add-port=80/tcp #添加端口,格式为:端口/通讯协议
4,--permanent :表示设置为持久,永久生效,没有此参数重启后失效
4,通过配置文件添加端口
cd /etc/firewalld/zones vim public.xml
<?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public areas.</description> <rule family="ipv4"> <source address="122.10.70.234"/> <port protocol="udp" port="514"/> <accept/> </rule> <rule family="ipv4"> <source address="123.60.255.14"/> <port protocol="tcp" port="10050-10051"/> <accept/> </rule> <rule family="ipv4"> <source address="192.249.87.114"/> 放通指定ip,指定端口、协议 <port protocol="tcp" port="80"/> <accept/> </rule> <rule family="ipv4"> 放通任意ip访问服务器的9527端口 <port protocol="tcp" port="9527"/> <accept/> </rule> </zone>
------------------------------------------------------------------------------------------------------------------------
4,iptables配置
1,关闭firewall
systemctl stop firewalld.service或者service firewalld stop systemctl disable firewalld.service #禁止firewall开机启动
2,安装iptables
yum install iptables-services #安装
3,编辑配置
vi /etc/sysconfig/iptables #编辑防火墙配置文件
Firewall configuration written by system-config-firewall
Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT#必须开启,否则nginx无法打开
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
4,查看,启用
iptables -L#查看规则是否生效
systemctl start iptables.service或者service iptables start #开启 systemctl enable iptables.service #设置防火墙开机启动
Game Over !
标签:doc tab 操作 font 启用 firewalld accept 关闭 设置
原文地址:https://www.cnblogs.com/Miracle1/p/11987312.html