命令netstat查看网络状态

netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况。

  • 命令语法
    netstat (参数)

  • 命令选项
    a:=all 显示所有连线中的socket;
    -l:=listening 显示监控中的服务器的socket;
    -n:=numeric 直接使用IP地址;
    -p:=programs 显示正在使用socket的程序识别码和程序名称;
    -t:=tcp 显示tcp传输协议的连接状况;


  • 查看监听端口
[root@localhost ~]# netstat -lnp
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:22              0.0.0.0:*               LISTEN      1467/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2036/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1467/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2036/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           621/chronyd         
udp6       0      0 ::1:323                 :::*                                621/chronyd         
raw6       0      0 :::58                   :::*                    7           671/NetworkManager  
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     STREAM     LISTENING     14377    1/systemd            /var/run/dbus/system_bus_socket
。。。。。。。。。。。。。。。。。。

  • 查看网络连接状况
[root@localhost ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0     52 192.168.152.128:22      192.168.152.1:56504     ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp        0      0 192.168.152.128:52670   193.228.143.23:123      ESTABLISHED
udp        0      0 192.168.152.128:40023   51.15.41.135:123        ESTABLISHED
udp6       0      0 ::1:323                 :::*                               
raw6       0      0 :::58                   :::*                    7          
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     14377    /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     18825    public/qmgr
。。。。。。。。。。。。。。。。。

  • 只查看tcp协议连接
[root@localhost ~]# netstat -lntp
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:22              0.0.0.0:*               LISTEN      1467/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2036/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1467/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2036/master    

  • 查看tcp协议状态的命令
[root@localhost ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
LISTEN   4
ESTABLISHED      1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值