阿里云9.9元云服务器限时购买

Centos7.5 firewalld防火墙配置

CentOS 7.0默认使用的是firewall作为防火墙

1、查看firewall服务状态

systemctl status firewalld

 

2、查看firewall的状态

firewall-cmd --state
 

3、开启、重启、关闭、firewalld.service服务

#查看linux哪些程序正在使用互联网

firewall-cmd --permanent --list-services ssh dhcpv6-client

# 开启
service firewalld start
# 重启
service firewalld restart


# 关闭
service firewalld stop
4、查看防火墙规则

firewall-cmd --list-all

 

停止firewall

systemctl stop firewalld.service

禁止firewall开机启动

systemctl disable firewalld.service


5、查询、开放、关闭端口

# 查询端口是否开放
firewall-cmd --query-port=8080/tcp


# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=8080-8085/tcp


# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
查看防火墙的开放的端口
firewall-cmd --permanent --list-ports

#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload


# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;

常用命令配置白名单,限制指定ip只能访问服务器指定的端口和去掉开通的端口

#配置规则
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="指定的ip地址" port protocol="tcp" prot="指定的端口" accept"
 
#配置所有端口都可以访问
firewall-cmd --permanent --zone=public --add-port=8080/tcp
 
#批量配置规则
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="指定的ip地址段(192.168.1.0/24)" port protocol="tcp" prot="指定的端口" accept"
 
#reload配置生效
firewall-cmd --reload
 
#关闭端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
 
#批量添加区间端口
firewall-cmd --zone=public --add-port=4400-4600/udp --permanent
 
#查看防火墙排除端口
firewall-cmd --permanent --list-port
 
#查看所有开放的端口
iptables -L -n

  

posted @ 2019-09-05 13:37  HIIT  阅读(3638)  评论(0编辑  收藏  举报
阿里云限时红包 最高 ¥ 2000 云产品通用红包,可叠加官网常规优惠使用