Linux (CentOS 7.6 64bit) 开放及查看端口

1.查看防火墙运行的状态

[root@VM-0-5-centos ~]# firewall-cmd --state
not running
[root@VM-0-5-centos ~]# 

 看到状态是not running

2. 启动/关闭防火墙firewalld服务

# 启动防火墙服务
systemctl start firewalld.service


# 关闭防火墙服务
systemctl stop firewalld.service

3.查看防火墙运行的状态

[root@VM-0-5-centos ~]# firewall-cmd --state
running
[root@VM-0-5-centos ~]# 

查看firewalld状态

[root@VM-0-5-centos ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-12-16 11:41:10 CST; 2min 11s ago
     Docs: man:firewalld(1)
 Main PID: 23008 (firewalld)
    Tasks: 2
   Memory: 26.0M
   CGroup: /system.slice/firewalld.service
           └─23008 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Dec 16 11:41:10 VM-0-5-centos systemd[1]: Starting firewalld - dynamic firewall daemon...
Dec 16 11:41:10 VM-0-5-centos systemd[1]: Started firewalld - dynamic firewall daemon.
Dec 16 11:41:10 VM-0-5-centos firewalld[23008]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
Dec 16 11:41:11 VM-0-5-centos firewalld[23008]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).
[root@VM-0-5-centos ~]#

查看所有打开的端口  可以看到已经开放的端口

[root@VM-0-5-centos ~]# firewall-cmd --zone=public --list-ports
80/tcp 8080/tcp 8088/tcp 6379/tcp
[root@VM-0-5-centos ~]# 

6.添加开放端口 (80端口为例)  permanent永久生效,没有此参数重启后失效

# --zone #作用域
# --add-port=80/tcp  #添加端口,格式为:端口/通讯协议
# --permanent   #永久生效,没有此参数重启后失效
# 单独开启一个80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent

# 同时开启多个端口  6379-6389
firewall-cmd --permanent --zone=public --add-port=6379-6389/tcp

7. 添加端口之后需要重新载入

firewall-cmd --reload

8. 查看开放的端口

#查看80端口开放
[root@VM-0-5-centos ~]# firewall-cmd --query-port=80/tcp
yes

#查看6388端口开放
[root@VM-0-5-centos ~]# firewall-cmd --query-port=6388/tcp
yes

9.删除开放的端口

#删除80端口号
firewall-cmd --permanent --zone=public --remove-port=80/tcp

10  开机禁用/开机启用

# 开机禁用
systemctl disable firewalld


# 开机启用
systemctl enable firewalld

                
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值