netstat

netstat命令

netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等

1 常用选项:

-a :(all)显示所有选项,默认不显示LISTEN相关

-t :(tcp)仅显示tcp相关选项

-u :(udp)仅显示udp相关选项

-n :以数字显示IP和端口,能显示数字的全部转化成数字。

-l :仅列出有在 Listen (监听) 的服務状态

-p: 显示建立相关链接的程序名

-r :显示路由信息,路由表

-e :显示扩展信息,例如uid等

-s :按各个协议进行统计

-c :每隔一个固定时间,执行该netstat命令。

-w:raw socket相关

2 -tan 显示所有tcp端口

[root@centos7 ~]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 52 192.168.29.3:22 192.168.29.1:51029 ESTABLISHED
tcp 0 0 192.168.29.3:22 192.168.29.1:51180 ESTABLISHED
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::*

3 显示所有udo端口 -uan

[root@centos7 ~]# netstat -anu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:47414 0.0.0.0:*
udp 0 0 192.168.122.1:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*

4 显示所有处于监听的tcp端口    -tnl

[root@centos7 ~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN

5 显示所有处于监听状态的udp端口 -unl

[root@centos7 ~]# netstat -unl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:47414 0.0.0.0:*
udp 0 0 0.0.0.0:20815 0.0.0.0:*
udp 0 0 192.168.122.1:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:9804 0.0.0.0:*
udp6 0 0 :::12799 :::*
udp6 0 0 :::37953 :::*

6 显示路由表 –rn

[root@centos7 ~]# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.29.1 0.0.0.0 UG 0 0 0 ens33
192.168.29.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@centos7 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.29.1 0.0.0.0 UG 100 0 0 ens33
192.168.29.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

7 显示每个协议的统计信息

显示所有端口的统计信息 netstat -s

[root@centos7 ~]# netstat -s
Ip:
3808 total packets received
0 forwarded
0 incoming packets discarded
2444 incoming packets delivered
2254 requests sent out
32 outgoing packets dropped
Icmp:
676 ICMP messages received
0 input ICMP message failed.
ICMP input histogram:
destination unreachable: 148
echo replies: 528
717 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 148
echo request: 569
[……]

显示 TCP 或 UDP 端口的统计信息 netstat -st 或 -su

[root@centos7 ~]# netstat -st
IcmpMsg:
InType0: 528
InType3: 148
OutType3: 148
OutType8: 569
Tcp:
0 active connections openings
2 passive connection openings
0 failed connection attempts
0 connection resets received
2 connections established
1637 segments received
1418 segments send out
0 segments retransmited
0 bad segments received.
0 resets sent

[root@centos7 ~]# netstat -su
IcmpMsg:
InType0: 528
InType3: 148
OutType3: 148
OutType8: 569
Udp:
0 packets received
140 packets to unknown port received.
0 packet receive errors
169 packets sent
0 receive buffer errors
0 send buffer errors
UdpLite:
IpExt:
InMcastPkts: 27
OutMcastPkts: 33
InBcastPkts: 766
InOctets: 410294
OutOctets: 432666
InMcastOctets: 4963
OutMcastOctets: 5444
InBcastOctets: 179503
InNoECTPkts: 3848

8 显示 PID 和进程名称 netstat -p

[root@centos7 ~]# netstat -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 52 centos7.3.local:ssh gateway:51029 ESTABLISHED 1552/sshd: root@pts
tcp 0 0 centos7.3.local:ssh gateway:51180 ESTABLISHED 1854/sshd: root@pts
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ] DGRAM 8520 1/systemd /run/systemd/notify
unix 2 [ ] DGRAM 8522 1/systemd /run/systemd/cgroups-agent
unix 5 [ ] DGRAM 8542 1/systemd /run/systemd/journal/socket
unix 28 [ ] DGRAM 8544 1/systemd /dev/log
unix 2 [ ] DGRAM 11419 1/systemd /run/systemd/shutdownd
unix 3 [ ] STREAM CONNECTED 23993 1276/ibus-x11

原创文章,作者:linux is not unix,如若转载,请注明出处:http://www.178linux.com/74901

(0)
linux is not unixlinux is not unix
上一篇 2017-05-07
下一篇 2017-05-07

相关推荐

  • 关于 磁盘、文件系统管理

                   磁盘、文件系统管理               1  设备识别2  设备分区3 …

    系统运维 2016-08-30
  • 马哥教育-第一周作业

    第一部分:计算机组成及功能 电子真空管的出现促使了计算机的诞生; 根据冯●诺依曼的哲学思想,计算机的组成分为五大部分。分别为: 1.     运算器 2.     控制器 3.     存储器 4.   &nb…

    Linux干货 2016-12-04
  • linux的各种小命令和目录

    linux的各种小命令   pwd 显示当前工作的目录   w who whoami 显示当前用户及已建立的ssh链接   useradd 新建一个普通用户   passwd 修改用户的密码   # 代表当前工作的是root 超级用户   $ 代表当前工作的普通用户 &…

    Linux干货 2017-03-27
  • Linux下硬连接和软连接的区别

    Linux下硬链接与软链接的区别   链接,是指在计算机文件之间传递参数和控制命令,并把它们组成一个可执行的整体的过程。例如我们常见的windows系统下的“快捷方式”,它是一种链接,人们可以通过它来直接访问计算机上的某个文件,不必逐级在硬盘目录下寻找;互联网上的“超文本链接”,它用文字链接的形式来指向一个页面,人们可以通过此链接快速访问网站的页面…

    Linux干货 2016-10-21
  • 马哥教育网络班20期-第四周课程作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。       cp -r /etc/skel /home/tuser1 | chmod -R g…

    Linux干货 2016-06-29
  • 马哥教育网络班20期+第3周课程练习

    1、列出当前系统上所有已经登录的用户的用户名。 注意同一个用户登陆多次,只显示一次即可。    w | cut -d ' ' -f 1 | uniq -c       2、取出最后登陆到当前系统的用户的相关信息    last | head -n 1  &nbsp…

    Linux干货 2016-06-26