Linux uses the SS command to view the socket status

Source: Internet
Author: User

The SS command is used to display the socket information in the active state. The SS command can be used to get socket statistics, which can display and netstat similar content. But the advantage of the SS is that it can show more and more detailed information about TCP and connection status, and is faster and more efficient than netstat.

When the number of socket connections for a server becomes very large, the execution speed is slow, either with the netstat command or the direct cat/proc/net/tcp. You may not have a personal feeling, but please believe me, when the server maintains a connection of tens of thousands of times, the use of netstat equals wasting life, and the SS is to save time.


All TCP sockets

All UDP sockets

All Ssh/ftp/ttp/https Persistent connections

All local processes connected to the Xserver

Use state (for example: Connected, synchronized, SYN-RECV, syn-sent,time-wait), address, port filtering


All state fin-wait-1 tcpsocket connections and more

Many popular Linux distributions support SS as well as many monitoring tools using the SS command. Familiarity with this tool will help you better identify and resolve system performance issues. I strongly recommend that you use the SS command instead of the netstat part of the command, such as NETSAT-ANT/LNT.


Count Server Concurrent connections:


[[Email protected] ~]# Time NETSTAT-ANTLP | grep EST | Wc-l

1


Real 0m0.015s

User 0m0.005s

SYS 0m0.006s



[Email protected] ~]# Time Ss-o State established | Wc-l

140


Real 0m0.031s

User 0m0.003s

SYS 0m0.003s



The result is obviously SS statistics concurrent connection number efficiency netstat, in the case of SS can be done, you will also choose netstat?


Common SS Commands:


Ss-l Show all ports that are open locally

SS-PL Show each process specific open socket

Ss-t-A displays all TCP sockets

Ss-u-a displays all UDP Socekt

Ss-o State established ' (Dport =: SMTP or sport =: SMTP) ' Displays all established SMTP connections

Ss-o State established ' (Dport =: http or sport =: http) ' shows all established HTTP connections

Ss-x src/tmp/. x11-unix/* identify all processes that connect to the X server

SS-S List Current Socket details:



Display sockets brief information

Lists the TCP connections that are currently connected, closed, and waiting:


[Email protected] ~]# ss-s

total:246 (Kernel 276)

Tcp:70 (estab 1, closed, orphaned 0, synrecv 0, timewait 58/0), ports 0


Transport Total IP IPv6

* 276--

RAW 0 0 0

UDP 2 1 1

TCP 11 6 5

INET 13 7 6

FRAG 0 0 0



The SS lists each process name and its listening ports:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/97/wKioL1epfw7ADnLbAAIN4dE246c615.png-wh_500x0-wm_3 -wmp_4-s_170069434.png "title=" 1.png "alt=" Wkiol1epfw7adnlbaain4de246c615.png-wh_50 "/>


SS column All TCP sockets:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/97/wKiom1epfzqARDoDAAMHTwdzdPU570.png-wh_500x0-wm_3 -wmp_4-s_2399574225.png "title=" Ss_t_a.png "alt=" Wkiom1epfzqardodaamhtwdzdpu570.png-wh_50 "/>


SS List all UDP sockets:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/85/97/wKioL1epf16x9WOrAAD8-U4B21E793.png-wh_500x0-wm_3 -wmp_4-s_3616921925.png "title=" Ss_u_a.png "alt=" Wkiol1epf16x9woraad8-u4b21e793.png-wh_50 "/>


The SS lists the connections in all HTTP connections:

# Ss-o State established ' (Dport =: http or sport =: http) '


The above includes 80 externally provided, as well as access to the external 80

With the above command perfect alternative netstat get the number of HTTP concurrent connections, monitoring in common to


The SS lists which processes are locally connected to the X server:


[Email protected] ~]# ss-x src/tmp/. x11-unix/*

Netid State recv-q send-q Local address:port Peer address:port


The SS lists HTTP, HTTPS connections in the FIN-WAIT-1 state:

[[email protected] ~]# ss-o State fin-wait-1 ' (sport =: http or sport =: HTTPS) '

Netid recv-q send-q Local address:port Peer address:port



SS Common State states:


Established

Syn-sent

Syn-recv

Fin-wait-1

Fin-wait-2

Time-wait

Closed

Close-wait

Last-ack

Listen

Closing

All:all of the above states

Connected:all the states except for listen and closed

Synchronized:all the connected states except for syn-sent

Bucket:show states, which is maintained as minisockets, i.e. time-wait and SYN-RECV.

Big:opposite to buckets state.




The SS uses IP address filtering:

SS Src Address_pattern

SRC: Indicates the source

Address_pattern: Represents an Address rule

As follows:

SS SRC 120.33.31.1 # Lists the connections to the 20.33.31.1

# list connections to the 120.33.31.1,80 port

SS Src 120.33.31.1:http

SS Src 120.33.31.1:80


SS uses port filtering:

SS Dport OP PORT

OP: Is operator

Port: Indicates ports

Dport: Indicates that the target port is filtered and the opposite has a sport



The OP operator is as follows:

<= or le: less than or equal to >= or GE: greater than or equal

= = or eq: equals

! = or NE: Not equal to port

< or LT: Less than this port > or GT: Greater than port



OP instance:

SS Sport =: HTTP can also be SS sport =: 80

SS Dport =: http

SS Dport \>: 1024

SS Sport \>: 1024

SS Sport \<: 32000

SS Sport Eq:22

SS Dport! =: 22

SS State Connected sport =: http

SS \ (sport =: http or sport =: HTTPS \)

Ss-o state fin-wait-1 \ (sport =: http or sport =: HTTPS \) DST 192.168.1/24


Print sockets information for TCP IPv4:

[Email protected] ~]# SS-4 State established

Netid recv-q send-q Local address:port Peer address:port

TCP 0 0 172.16.25.192:ssh 172.16.25.98:52581



To view the help information for the SS command:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/85/97/wKiom1ephD-x3pd7AAYJ2RdSPdY729.png-wh_500x0-wm_3 -wmp_4-s_3382804731.png "title=" 4.png "alt=" Wkiom1ephd-x3pd7aayj2rdspdy729.png-wh_50 "/>


Article reference: http://www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.html










This article is from the "LINUX Super Dream" blog, make sure to keep this source http://215687833.blog.51cto.com/6724358/1836119

Linux uses the SS command to view the socket status

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.