端口和防火墙设置 | centos | linux

环境:CentOS 7

netstat 命令详解

netstat -atunlp

  • -a :all,表示列出所有的连接,服务监听,Socket资料
  • -t :tcp,列出tcp协议的服务
  • -u :udp,列出udp协议的服务
  • -n :port number, 用端口号来显示
  • -l :listening,列出当前监听服务
  • -p :program,列出服务程序的PID
[root@VM_0_14_centos etc]# netstat -atunlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      4663/sshd: root@pts 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1491/sshd           
tcp        0      0 172.17.0.14:22          223.73.25.37:4989       ESTABLISHED 31397/sshd: root@no 
tcp        0      0 172.17.0.14:41078       169.254.0.55:8080       TIME_WAIT   -                   
tcp        0      0 172.17.0.14:41520       169.254.0.55:5574       ESTABLISHED 11428/YDService     
tcp        0     52 172.17.0.14:22          223.73.25.37:4994       ESTABLISHED 4663/sshd: root@pts 
tcp6       0      0 :::80                   :::*                    LISTEN      3212/httpd          
tcp6       0      0 :::21                   :::*                    LISTEN      4563/vsftpd         
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1414/dhclient       
udp        0      0 172.17.0.14:123         0.0.0.0:*                           914/ntpd            
udp        0      0 127.0.0.1:123           0.0.0.0:*                           914/ntpd            
udp        0      0 0.0.0.0:177             0.0.0.0:*                           2381/lightdm        
udp6       0      0 fe80::5054:ff:fe4c::123 :::*                                914/ntpd            
udp6       0      0 ::1:123                 :::*                                914/ntpd            
udp6       0      0 :::177                  :::*                                2381/lightdm        

其中

  • Proto:网络传输协议,主要为tcp和udp
  • Local Address:本地的ip:port
  • Foreign Address:远程主机的ip:port
  • State:连线状态,主要有监听( LISTEN )和建立(ESTABLISED)
  • PID:服务的进程编号
  • Program name:服务名称

端口

  • 查看开放的端口
netstat -lnpt
  • 检查某个端口的占用情况
netstat -lnpt |grep 5672
  • 查看进程的详细信息
ps 6832
  • 中止进程
kill -9 6832

防火墙

  • 查看防火墙状态
firewall-cmd --state
  • 关闭防火墙
systemctl stop firewalld.service
  • 开启防火墙:
systemctl start firewalld.service

防火墙端口

1、开放端口

firewall-cmd --zone=public --add-port=5672/tcp --permanent   # 开放5672端口

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

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

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

firewall-cmd --zone=public --list-ports
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值