linux netstat java,Linux netstat介绍

3、实例

A、列出所有端口

列出所有端口

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -a | more

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 *:http *:* LISTEN

tcp 0 0 *:ssh *:* LISTEN

列出所有tcp端口

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -at

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 *:http *:* LISTEN

tcp 0 0 *:ssh *:* LISTEN

tcp 0 0 121.41.120.65:http 140.205.201.20:35425 TIME_WAIT

列出所有udp端口

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -au

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

udp 0 0 121.41.120.65:ntp *:*

udp 0 0 iZ235ubl1arZ:ntp *:*

udp 0 0 localhost:ntp *:*

udp 0 0 *:ntp *:*

udp6 0 0 [::]:ntp [::]:*

B、列出所有处于监听状态的Sockets

只显示监听端口netstat -l

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -l

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 *:http *:* LISTEN

tcp 0 0 *:ssh *:* LISTEN

udp 0 0 121.41.120.65:ntp *:*

udp 0 0 iZ235ubl1arZ:ntp *:*

udp 0 0 localhost:ntp *:*

只列出所有监听tcp端口netstat -lt

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -lt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 *:http *:* LISTEN

tcp 0 0 *:ssh *:* LISTEN

只列出所有监听udp端口 netstat -lu

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -lu

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

udp 0 0 121.41.120.65:ntp *:*

udp 0 0 iZ235ubl1arZ:ntp *:*

udp 0 0 localhost:ntp *:*

udp 0 0 *:ntp *:*

udp6 0 0 [::]:ntp [::]:*

只列出所有监听UNIX端口 netstat -lx

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -lx

Active UNIX domain sockets (only servers)

Proto RefCnt Flags Type State I-Node Path

unix 2 [ ACC ] STREAM LISTENING 9506 /var/run/nscd/socket

unix 2 [ ACC ] STREAM LISTENING 8267 /var/run/dbus/system_bus_socket

unix 2 [ ACC ] SEQPACKET LISTENING 7769 /run/udev/control

unix 2 [ ACC ] STREAM LISTENING 7592 @/com/ubuntu/upstart

C、在netstat 输出中显示PID和进程名称netstat -p

root@iZ235ubl1arZ:/home/yanmin/blog# netstat -p

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 316 121.41.120.65:ssh 58.246.62.146:54175 ESTABLISHED 17558/sshd: yanmin

tcp 0 0 121.41.120.65:ssh 58.246.62.146:52592 ESTABLISHED 14538/sshd: yanmin

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags Type State I-Node PID/Program name Path

unix 10 [ ] DGRAM 8286 682/rsyslogd /dev/log

unix 3 [ ] STREAM CONNECTED 307127 17558/sshd: yanmin

D、显示核心路由信息 netstat -r

yanmin:blog yanmin$ netstat -r

Routing tables

Internet:

Destination Gateway Flags Refs Use Netif Expire

default 10.96.150.1 UGSc 21 0 en0

10.16/14 10.254.254.81 UGSc 0 0 utun1

10.16.0.222/32 10.254.254.81 UGSc 1 0 utun1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值