CentOS7 端口的开放关闭查看都是用防火墙来控制的,具体命令如下:
查看防火墙状态
- (active (running) 即是开启状态):
[root@izbp1hcw0fjg64l58525bqz nacos]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since 六 2021-08-14 21:39:24 CST; 5 days ago
Docs: man:firewalld(1)
Main PID: 17946 (firewalld)
Tasks: 2
Memory: 26.3M
CGroup: /system.slice/firewalld.service
└─17946 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
8月 14 21:38:45 izbp1hcw0fjg64l58525bqz systemd[1]: Starting firewalld - dyn...
8月 14 21:39:24 izbp1hcw0fjg64l58525bqz systemd[1]: Started firewalld - dyna...
8月 14 21:39:31 izbp1hcw0fjg64l58525bqz firewalld[17946]: WARNING: AllowZone...
8月 14 21:43:49 izbp1hcw0fjg64l58525bqz firewalld[17946]: WARNING: AllowZone...
Hint: Some lines were ellipsized, use -l to show in full.
查看已开放端口
[root@izbp1hcw0fjg64l58525bqz nacos]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: 6379/tcp 3306/tcp 9200/tcp 9300/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
防火墙开放端口
注意:执行开放端口后,需重载防火墙
[root@izbp1hcw0fjg64l58525bqz nacos]# firewall-cmd --zone=public --add-port=8848/tcp --permanent
success
## 重启防火墙
[root@izbp1hcw0fjg64l58525bqz nacos]# firewall-cmd --reload
success
命令含义:
–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
配置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
|