Centos7 开放及查看端口

1. 开放端口

1
2
3
4
5
6
7
8
# 开放 5672 端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent

# 关闭 5672 端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent

# 配置立即生效
firewall-cmd --reload

2. 查看防火墙所有开放的端口

1
firewall-cmd --zone=public --list-ports

3. 关闭防火墙

如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估

1
systemctl stop firewalld.service

4. 查看防火墙状态

1
firewall-cmd --state

5. 查看监听的端口

1
netstat -lnpt
1
2
3
4
5
6
7
8
9
10
11
[logan@localhost ~]$ sudo netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13883/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1594/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1127/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1128/cupsd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1127/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1128/cupsd

PS:centos7 默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools

6. 查看进程的详细信息

1
ps 13883
1
2
3
[logan@localhost ~]$ ps 13883
PID TTY STAT TIME COMMAND
13883 ? Ss 0:00 nginx: master process nginx

7. 中止进程

1
kill 13883

本文参考:https://www.cnblogs.com/heqiuyong/p/10460150.html