8-Centos7 防火墙查看状态,查看开放端口,开放端口,

CentOS7 端口的开放关闭查看都是用防火墙来控制的,具体命令如下:

如果没有开启防火墙那外网就可以直接访问了,

查看防火墙状态:(active (running) 即是开启状态)

[root@WSS bin]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 四 2019-07-11 09:37:11 CST; 7h ago
     Docs: man:firewalld(1)
 Main PID: 44370 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─44370 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD...t name.
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD...t name.
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT -...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT -...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete OUTPUT ...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT -...hain?).
7月 11 09:37:13 WSS firewalld[44370]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT -...hain?).
Hint: Some lines were ellipsized, use -l to show in full.
[root@WSS bin]#

查看已开放端口:(8080和3306 即是已开放端口)

[root@WSS bin]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens3 ens4
sources:
services: ssh dhcpv6-client
ports: 8080/tcp 3306/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

[root@WSS bin]#

防火墙开放端口:(开放端口后需重载防火墙)

[root@WSS bin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@WSS bin]# 
[root@WSS bin]# firewall-cmd --reload
success
[root@WSS bin]#
命令含义:

–zone #作用域

–add-port=80/tcp #添加端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

firewall-cmd --reload 并不中断用户连接,即不丢失状态信息

firewalld的基本使用



启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld

systemctl

systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
posted @ 2021-11-15 18:21  技术改变命运Andy  阅读(516)  评论(0编辑  收藏  举报