Linux防火墙相关操作

Linux防火墙相关操作

CentOS 7采用新的firewalld,CentOS 6及以前版本采用iptables,不过firewalld底层仍然调用的是iptables

1、安装

firewalld在CentOS 7中默认是安装的。CentOS 7还支持以图形界面的方式配置防火墙,即firewall-config工具,默认也是安装的。

//安装firewalld和firewall-config工具
[root@localhost ~]# yum install firewalld -y         //默认已安装
[root@localhost ~]# yum install firewall-config -y   //默认已安装

2、查看状态

# 1、查看防火墙状态
systemctl status firewalld

#2、查看firewalld服务是否开机自动启动
systemctl list-unit-files | grep firewalld.service

3、停止/开启/重启/重载/自启动/不可用

#1、停止防火墙
systemctl stop firewalld 
或:systemctl stop firewalld.service

#2、启动防火墙
systemctl start firewalld

#3、重启防火墙
systemctl restart firewalld

#4、重载防火墙配置
sudo firewall-cmd --reload

#4、开机自启动防火墙
systemctl enable firewalld

#5、设置防火墙不可用
systemctl disable firewalld.service

4、查看放行端口

linux查看开放端口的方法:

1、使用rpm安装nmap工具,执行“nmap 127.0.0.1”命令即可查看本机开放的端口;

2、执行“netstat -anp”命令进行查看开放的端口。(注:加参数’-n’会将应用程序转为端口显示,即数字格式的地址,如:nfs->2049, ftp->21,因此可以开启两个终端,一一对应一下程序所对应的端口号)

防火墙放行端口:

# 1.查看所有已开放的临时端口(默认为空)
firewall-cmd --list-ports

# 2.查看所有永久开放的端口(默认为空)
firewall-cmd --list-ports --permanent

# 3.查询指定端口是否开启成功
firewall-cmd --query-port=5601/tcp

5、关闭/放行端口

#1、放行永久端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
--zone 作用域
--permanent 永久生效
#2、放行临时开放端口(例如:比如我修改ssh远程连接端口是223,则需要开放这个端口)
firewall-cmd --add-port=223/tcp

#3、关闭永久端口
firewll-cmd --remove-port=80/tcp --permanent
#4、关闭临时端口
firewall-cmd --remove-port=80/tcp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值