关于netstat 的问题

不太理解nestat 统计的的结果中 关于local address  和foreign address 部分 用
127.0.0.1
0.0.0.0
 ::


-bash-3.2$ netstat -tl ?? 查看 tcp 监听端口

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 localhost.localdomain:2208   *:*                         LISTEN      
tcp        0      0 *:nfs                       *:*                         LISTEN      
tcp        0      0 *:acap                       *:*                         LISTEN      
tcp        0      0 *:interintelli               *:*                         LISTEN           
tcp        0      0 192.168.122.1:domain         *:*                         LISTEN      
tcp        0      0 *:726                       *:*                         LISTEN      
tcp        0      0 localhost.localdomain:ipp   *:*                         LISTEN             
tcp        0      0 *:accessnetwork             *:*                         LISTEN      
tcp        0      0 *:34238                     *:*                         LISTEN      
tcp        0      0 localhost.localdomain:2207   *:*                         LISTEN      
tcp        0      0 *:http                       *:*                         LISTEN      
 .-------------------------------------................
-bash-3.2$ netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 127.0.0.1:2208             0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:2049                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:674                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:2633               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:726                 0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:699                 0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:34238               0.0.0.0:*                   LISTEN

tcp        0      0 127.0.0.1:2207             0.0.0.0:*                   LISTEN      

tcp        0      0 :::80                            :::*                        LISTEN
tcp        0      0 0.0.0.0:9869                 0.0.0.0:*                   LISTEN
-------------------..........................................  

建立连接的端口
[root@localhost ~]# netstat -tn
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 192.168.32.27:2049          192.168.63.27:909           ESTABLISHED 
tcp        0      0 192.168.32.27:52409         192.168.32.27:3306          ESTABLISHED 
tcp        0      0 192.168.32.27:3306          192.168.32.27:52409         ESTABLISHED 
tcp        0      0 127.0.0.1:2633              127.0.0.1:38090             TIME_WAIT   
tcp        0      0 127.0.0.1:2633              127.0.0.1:38091             TIME_WAIT   
tcp        1      0 127.0.0.1:38096             127.0.0.1:2633              CLOSE_WAIT  
tcp        0      0 192.168.32.27:9869          192.168.32.29:50117         FIN_WAIT2   
tcp        0      0 192.168.32.27:9869          192.168.32.29:50119         FIN_WAIT2   
tcp        0      0 192.168.32.27:9869          192.168.32.29:50120         ESTABLISHED 
-----------------...................
监听的端口建立连接后 local address 的部分就变成本机的ip地址 192.168.32.27 或者 127.0.0.1



google了一下
在这个帖子中看到http://topic.csdn.net/u/20071221/22/5fd06b47-e3aa-4374-9116-dfaa43ea9f65.html
网友的解释是
TCP 0.0.0.0:80表示在所有的本地可用接口上监听TCP80端口


===============================================下面转的这片文章说的比较详细

命令:netstat

功能说明:显示网络状态。

语  法netstat [-acCeFghilMnNoprstuvVwx][-A<网络类型>][--ip]

补充说明:利用netstat指令可让你得知整个Linux系统的网络情况。

参  数:
  -a或--all   显示所有连线中的Socket。
  -A<网络类型>或--<网络类型>   列出该网络类型连线中的相关地址。
  -c或--continuous   持续列出网络状态。
  -C或--cache   显示路由器配置的快取信息。
  -e或--extend   显示网络其他相关信息。
  -F或--fib   显示FIB。
  -g或--groups   显示多重广播功能群组组员名单。
  -h或--help   在线帮助。
  -i或--interfaces   显示网络界面信息表单。
  -l或--listening   显示监控中的服务器的Socket。
  -M或--masquerade   显示伪装的网络连线。
  -n或--numeric   直接使用IP地址,而不通过域名服务器。
  -N或--netlink或--symbolic   显示网络硬件外围设备的符号连接名称。
  -o或--timers   显示计时器。
  -p或--programs   显示正在使用Socket的程序识别码和程序名称。
  -r或--route   显示Routing Table。
  -s或--statistice   显示网络工作信息统计表。
  -t或--tcp   显示TCP传输协议的连线状况。
  -u或--udp   显示UDP传输协议的连线状况。
  -v或--verbose   显示指令执行过程。
  -V或--version   显示版本信息。
  -w或--raw   显示RAW传输协议的连线状况。
  -x或--unix   此参数的效果和指定"-A unix"参数相同。
  --ip或--inet   此参数的效果和指定"-A inet"参数相同。

常用组合,查看出正在连接和网络信息

netstat -ntulpa

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:2208              0.0.0.0:*                   LISTEN      3226/hpiod         
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3411/mysqld        
tcp        0      0 0.0.0.0:1002                0.0.0.0:*                   LISTEN      2940/rpc.statd     
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2883/portmap       
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      3259/cupsd         
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3453/sendmail: acce
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      3231/python        
tcp        0      0 202.102.240.93:3306         122.207.210.12:1750         ESTABLISHED 3411/mysqld        
tcp        0      0 202.102.240.93:3306         122.207.210.12:1748         ESTABLISHED 3411/mysqld        
tcp        0      0 202.102.240.93:3306         202.102.240.93:59141        ESTABLISHED 3411/mysqld        
tcp        0      0 202.102.240.93:59141        202.102.240.93:3306         ESTABLISHED 7059/httpd 

 netstat 的一些常用选项
  netstat –s
  本选项能够按照各个协议分别显示其统计数据。如果我们的应用程序(如Web浏览器)运行速度比较慢,或者不能显示Web页之类的数据,那么我们就可以用本选项来查看一下所显示的信息。我们需要仔细查看统计数据的各行,找到出错的关键字,进而确定问题所在。
  netstat –e
  本选项用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量)。
  netstat –r
  本选项可以显示关于路由表的信息,类似于后面所讲使用route print命令时看到的 信息。除了显示有效路由外,还显示当前有效的连接。
  netstat –a
  本选项显示一个所有的有效连接信息列表,包括已建立的连接(ESTABLISHED),也包括监听连接请求(LISTENING)的那些连接。
  netstat –n
  显示所有已建立的有效连接。

 扩展资料: 常用参数组合

1) netstat -tl    -nltp
查看当前tcp监听端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 *:rrac                  *:*                     LISTEN      
tcp        0      0 *:34006                 *:*                     LISTEN      
......

2) netstat -tlp
查看当前tcp监听端口, 需要显示监听的程序名,当不清楚mysql的监听端口时比较好用
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 *:rrac                  *:*                     LISTEN      -                          
tcp        0      0 *:34006                 *:*                     LISTEN      23425/mysqld   
......


3) netstat -tl | grep 34006
    只查看mysql的监听端口,当前启动的mysql端口为34006,明确知道mysql监听端口时使用
4) netstat -ta | grep 34006
tcp        0      0 *:34006                 *:*                     LISTEN      
tcp        0      0 linux.local:34006       linux.local:41485       ESTABLISHED 
tcp        0      0 linux.local:34006       linux.local:41486       ESTABLISHED 
...
tcp        0      0 10.3.2.35:41488         10.3.2.35:34006         ESTABLISHED 
tcp        0      0 10.3.2.35:41489         10.3.2.35:34006         ESTABLISHED 
tcp        0      0 10.3.2.35:41490         10.3.2.35:34006         ESTABLISHED 

由于数据库和运用程序都放在同一台机器了,因此这里连接被显示了两次. 可以使用-p参数来显示PID,然后grep PID.


5) netstat -tap | grep 34006 | grep 23425
    23425是当前mysql的PID
tcp        0      0 *:34006                 *:*                     LISTEN      23425/mysqld        
tcp        0      0 linux.local:34006       linux.local:41510       ESTABLISHED 23425/mysqld        
tcp        0      0 linux.local:34006       linux.local:41511       ESTABLISHED 23425/mysqld        
tcp        0      0 linux.local:34006       linux.local:41516       ESTABLISHED 23425/mysqld 从 整体上看,netstat的输出结果可以分为两个部分,一个是Active Internet connections,称为有源TCP连接,另一个是Active UNIX domain sockets,称为有源Unix域套接口。在上面的输出结果中,第一部分有5个输出结果,显示有源TCP连接的情况,而第二部分的输出结果显示的是 Unix域套接口的连接情况。Proto显示连接使用的协议;RefCnt表示连接到本套接口上的进程号;Types显示套接口的类型;State显示套 接口当前的状态;Path表示连接到套接口的其它进程使用的路径名。
事实上,netstat是若干个工具的汇总。

◆ 显示路由表
在随- r标记一起调用n e t s t a t时,将显示内核路由表,就像我们利用r o u t e命令一样。产生的输出如下:

[root@machine1 /]$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
210.34.6.0 0.0.0.0 255.255.255.128 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 210.34.6.2 0.0.0.0 UG 0 0 0 eth0

- n 选项令netstat以点分四段式的形式输出IP地址,而不是象征性的主机名和网络名。如果想避免通过网络查找地址(比如避开DNS或NIS服务器),这一点是特别有用的。
netstat 输出结果中,第二列展示的是路由条目所指的网关,如果没有使用网关,就会出现一个星号(*)或者0.0.0.0;第三列展示路由的概述,在为具体的I P地址找出最恰当的路由时,内核将查看路由表内的所有条目,在对找到的路由与目标路由比较之前,将对I P地址和genmask进行按位“与”计算;第四列显示了不同的标记,这些标记的说明如下:

■ G 路由将采用网关。
■ U 准备使用的接口处于“活动”状态。
■ H 通过该路由,只能抵达一台主机。
■ D 如果路由表的条目是由ICMP重定向消息生成的,就会设置这个标记。
■ M 如果路由表条目已被ICMP重定向消息修改,就会设置这个标记。

netstat输出结果的Iface显示该连接所用的物理网卡,如eth0表示用第一张,eth1表示用第二张。

◆ 显示接口特性

在随- i标记一起调用时, netstat将显示网络接口的当前配置特性。除此以外,如果调用时还带上-a选项,它还将输出内核中所有接口,并不只是当前配置的接口。netstat-i的输出结果是这样的:

[root@machine1 /]$ netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 787165 0 0 1 51655 0 0 0 BRU
eth1 1500 0 520811 0 0 0 1986 0 0 0 BRU
lo 3924 0 1943 0 0 0 43 0 0 0 LRU

MTU 和Met字段表示的是接口的MTU和度量值值;RX和TX这两列表示的是已经准确无误地收发了多少数据包( RX - OK / TX - OK)、产生了多少错误( RX-ERR/TX-ERR)、丢弃了多少包(RX-DRP/TX-DRP),由于误差而遗失了多少包(RX-OVR/TX-OVR);最后一列展示的是 为这个接口设置的标记,在利用ifconfig显示接口配置时,这些标记都采用一个字母。它们的说明如下:

■ B 已经设置了一个广播地址。
■ L 该接口是一个回送设备。
■ M 接收所有数据包(混乱模式)。
■ N 避免跟踪。
■ O 在该接口上,禁用A R P。
■ P 这是一个点到点链接。
■ R 接口正在运行。
■ U 接口处于“活动”状态。

◆ 显示链接
netstat 支持用于显示活动或被动套接字的选项集。选项- t、- u、- w和- x分别表示TCP、UDP、RAW和UNIX套接字连接。如果你另外还提供了一个- a标记,还会显示出等待连接(也就是说处于监听模式)的套接字。这样就可以得到一份服务器清单,当前所有运行于系统中的所有服务器都会列入其中。

调用netstat -ta时,输出结果如下:

[root@machine1 /]$ netstat -ta
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 2 210.34.6.89:telnet 210.34.6.96:2873 ESTABLISHED
tcp 0 0 210.34.6.89:1165 210.34.6.84:netbios-ssn ESTABLISHED
tcp 0 0 localhost.localdom:9001 localhost.localdom:1162 ESTABLISHED
tcp 0 0 localhost.localdom:1162 localhost.localdom:9001 ESTABLISHED
tcp 0 0 *:9001 *:* LISTEN
tcp 0 0 *:6000 *:* LISTEN
tcp 0 0 *:socks *:* LISTEN
tcp 0 80 210.34.6.89:1161 210.34.6.10:netbios-ssn CLOSE 

上 面的输出表明部分服务器处于等待接入连接状态。利用- a选项的话,netstat还会显示出所有的套接字。注意根据端口号,可以判断出一条连接是否是外出连接。对呼叫方主机来说,列出的端口号应该一直是一个 整数,而对众所周知服务(well known service)端口正在使用中的被呼叫方来说,netstat采用的则是取自/etc/services文件的象征性服务名。

参考资料:http://www.linuxso.com/command/netstat.html









http://linux.die.net/man/8/netstat

Output

Active Internet connections (TCP, UDP, raw)

Proto

The protocol (tcp, udp, raw) used by the socket.

Recv-Q

The count of bytes not copied by the user program connected to this socket.

Send-Q

The count of bytes not acknowledged by the remote host.

Local Address

Address and port number of the local end of the socket. Unless the --numeric( -n) option is specified, the socket address is resolved to its canonical host name (FQDN), and the port number is translated into the correspondingservice name.

Foreign Address

Address and port number of the remote end of the socket. Analogous to "Local Address."

State

The state of the socket. Since there are no states in raw mode and usually no states used in UDP,this column may be left blank. Normally this can be one of several values:
ESTABLISHED
The socket has an established connection.
SYN_SENT
The socket is actively attempting to establish a connection.
SYN_RECV
A connection request has been received from the network.
FIN_WAIT1
The socket is closed, and the connection is shutting down.
FIN_WAIT2
Connection is closed, and the socket is waiting for a shutdown from the remote end.
TIME_WAIT
The socket is waiting after close to handle packets still in the network.
CLOSED
The socket is not being used.
CLOSE_WAIT
The remote end has shut down, waiting for the socket to close.
LAST_ACK
The remote end has shut down, and the socket is closed. Waiting for acknowledgement.
LISTEN
The socket is listening for incoming connections. Such sockets are not included in the output unless you specify the --listening ( -l) or --all ( -a) option.
CLOSING
Both sockets are shut down but we still don't have all our data sent.
UNKNOWN
The state of the socket is unknown.

User

The username or the user id (UID) of the owner of the socket.

PID/Program name

Slash-separated pair of the process id (PID) and process name of the process that ownsthe socket. --program causes this column to be included. You will also need superuser privileges to see this information on sockets you don'town. This identification information is not yet available for IPX sockets.

Timer

(this needs to be written)

Active UNIX domain Sockets

Proto

The protocol (usually unix) used by the socket.

RefCnt

The reference count (i.e. attached processes via this socket).

Flags

The flags displayed is SO_ACCEPTON (displayed as ACC), SO_WAITDATA ( W) or SO_NOSPACE( N). SO_ACCECPTON is used on unconnected sockets if their corresponding processes are waiting for a connect request. The other flags are not of normalinterest.

Type

There are several types of socket access:
SOCK_DGRAM
The socket is used in Datagram (connectionless) mode.
SOCK_STREAM
This is a stream (connection) socket.
SOCK_RAW
The socket is used as a raw socket.
SOCK_RDM
This one serves reliably-delivered messages.
SOCK_SEQPACKET
This is a sequential packet socket.
SOCK_PACKET
Raw interface access socket.
UNKNOWN
Who ever knows what the future will bring us - just fill in here :-)

State

This field will contain one of the following Keywords:
FREE
The socket is not allocated
LISTENING
The socket is listening for a connection request. Such sockets are only included in the output if you specify the --listening ( -l) or --all ( -a) option.
CONNECTING
The socket is about to establish a connection.
CONNECTED
The socket is connected.
DISCONNECTING
The socket is disconnecting.
(empty)
The socket is not connected to another one.
UNKNOWN
This state should never happen.

PID/Program name

Process ID (PID) and process name of the process that has the socket open. More infoavailable in Active Internet connections section written above.

Path

This is the path name as which the corresponding processes attached to the socket.

Active IPX sockets

(this needs to be done by somebody who knows it)

Active NET/ROM sockets

(this needs to be done by somebody who knows it)

Active AX.25 sockets

(this needs to be done by somebody who knows it)




你可能感兴趣的:(关于netstat 的问题)