CentOS7 端口相关命令

1、查看指定的端口号的进程情况

方式①

[root@localhost src]# netstat -tunlp |grep 6379
tcp6       0      0 :::6379                 :::*                    LISTEN      81857/docker-proxy  

方式②

[root@localhost ace]# lsof -i:6379
COMMAND      PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 117539 root    4u  IPv6 258301      0t0  TCP *:6379 (LISTEN)

方式③

[root@localhost ace]# firewall-cmd --query-port=6379/tcp
no

2、查看所有开启的端口号

方式①

[root@localhost ace]# netstat -aptn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2163/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      27582/sshd          
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      27451/cupsd         
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1706/master         
tcp        0      0 192.168.46.120:22       192.168.46.1:64068      ESTABLISHED 22516/sshd: root@no 
tcp        0     96 192.168.46.120:22       192.168.46.1:64053      ESTABLISHED 22465/sshd: root@pt 
tcp        0      0 192.168.46.120:22       192.168.46.1:54774      ESTABLISHED 19078/sshd: root@pt 
tcp6       0      0 :::6379                 :::*                    LISTEN      117539/docker-proxy 
tcp6       0      0 :::22                   :::*                    LISTEN      27582/sshd          
tcp6       0      0 ::1:631                 :::*                    LISTEN      27451/cupsd         
tcp6       0      0 :::15672                :::*                    LISTEN      116960/docker-proxy 
tcp6       0      0 :::8761                 :::*                    LISTEN      28273/java          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1706/master         
tcp6       0      0 :::5672                 :::*                    LISTEN      116971/docker-proxy 

方式②

[root@localhost ace]# firewall-cmd --zone=public --list-ports
8761/tcp

3、查看UDP类型端口

[root@localhost ace]# netstat -nupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           27673/avahi-daemon: 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           29173/chronyd       
udp        0      0 0.0.0.0:33685           0.0.0.0:*                           27673/avahi-daemon: 
udp        0      0 192.168.122.1:53        0.0.0.0:*                           29818/dnsmasq       
udp        0      0 192.168.122.1:53        0.0.0.0:*                           2163/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           29818/dnsmasq       
udp        0      0 0.0.0.0:67              0.0.0.0:*                           2163/dnsmasq        
udp6       0      0 ::1:323                 :::*                                29173/chronyd       

4、查看TCP类型端口

[root@localhost ace]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2163/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      27582/sshd          
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      27451/cupsd         
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1706/master         
tcp6       0      0 :::6379                 :::*                    LISTEN      117539/docker-proxy 
tcp6       0      0 :::22                   :::*                    LISTEN      27582/sshd          
tcp6       0      0 ::1:631                 :::*                    LISTEN      27451/cupsd         
tcp6       0      0 :::15672                :::*                    LISTEN      116960/docker-proxy 
tcp6       0      0 :::8761                 :::*                    LISTEN      28273/java          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1706/master         
tcp6       0      0 :::5672                 :::*                    LISTEN      116971/docker-proxy 

5、开放端口(--permanent永久生效,没有此参数重启后失效)

[root@localhost ace]# firewall-cmd --zone=public --add-port=8761/tcp --permanent  
success
[root@localhost ace]# firewall-cmd --reload
success
[root@localhost ace]# firewall-cmd --query-port=8761/tcp
yes

猜你喜欢

转载自blog.csdn.net/m0_37726449/article/details/84761808