Linux netstat查看端口占用情况

本文介绍如何使用netstat命令检查端口使用和服务连接状态,包括查看服务端口是否启用、统计端口连接数等操作,并提供了命令的帮助信息。

一、使用netstat命令可查看端口使用情况

(1)  查看服务端口是否启用。常用于查看服务器进程端口是否启动

[root@cdh-003 ~]# netstat -nlp |grep 21050
tcp6       0      0 :::21050                :::*                    LISTEN      10859/impalad 

(2) 查看端口连接情况

[root@cdh-003 ~]# netstat -nat|grep -i "21050"    不带进程号
tcp6       0      0 :::21050                :::*                    LISTEN     
tcp6       0      0 192.168.11.124:21050    192.168.11.126:32474    ESTABLISHED
tcp6       0      0 192.168.11.124:21050    192.168.11.126:64128    ESTABLISHED
 

[root@cdh-005 ~]#  netstat -natp|grep -i "21050"   带进程号
tcp6       0      0 :::21050                :::*                    LISTEN      6334/impalad        
tcp6       0      0 192.168.11.126:14792    192.168.11.124:21050    ESTABLISHED 24236/java          
tcp6       0      0 192.168.11.126:32566    192.168.11.124:21050    ESTABLISHED 15111/java 

 

(3) 统计端口的连接数

[root@cdh-003 ~]# netstat -nat|grep -i "21050" |wc -l
63

 

二、netstat命令help

[root@cdh-003 ~]# netstat --help   查看命令帮助
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [<Socket> ...]
       netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]

        -r, --route              display routing table
        -I, --interfaces=<Iface> display interface table for <Iface>
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections

        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets    显示进程号
        -o, --timers             display timers
        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets   服务端listen
        -a, --all                display all sockets (default: connected)   显示所有sockets
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
        -Z, --context            display SELinux security context for sockets

  <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
           {-x|--unix} --ax25 --ipx --netrom

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值