แนะนำคำสั่ง ss command

Linux มีเครื่องมือ ที่มีประโยชน์ในการพัฒนา สำหรับ นักพัฒนาและผู้ดูแลระบบ คำสั่ง ss เป็นเครื่องมือที่ใช้สำหรับการดูข้อมูลที่เกี่ยวของกับ network, socket static และมีอีกมากมาย

# ss -4 state listening
Netid  Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
tcp    0      128                     *:sunrpc                                *:*                    
tcp    0      128                     *:ssh                                   *:*                    
tcp    0      100             127.0.0.1:smtp                                  *:*

แสดง listing sockets ด้วย -l

[root@client ~]# ss -l

เราสามารถต้องการกำหนดให้มีความชัดเจนลงไปเพื่อให้ผลที่ออกมานั้นมีรายละเดียดที่ต้องการ

  1. option -t ต้องการดู TCP connection
  2. option -u ต้องการดู UDP connection
  3. option -x ต้องการดู Unix Connection

    โดย default ทั้ง 3 option จะแสดง connection ที่มีการเชื่อมต่อ (Connected หรือ Establisted) หากต้องการดูทั้งหมด คือดู Listening ด้วย

[root@client ~]# ss -ta
State      Recv-Q Send-Q    Local Address:Port                     Peer Address:Port                
LISTEN     0      128                   *:sunrpc                              *:*                    
LISTEN     0      128                   *:ssh                                 *:*                    
LISTEN     0      100           127.0.0.1:smtp                                *:*                    
ESTAB      0      0             10.0.2.15:ssh                          10.0.2.2:58403                
LISTEN     0      128                  :::sunrpc                             :::*                    
LISTEN     0      128                  :::ssh                                :::*                    
LISTEN     0      100                 ::1:smtp                               :::*

ใช้คำสั่ง ss เพื่อกรอง สถานะการเชื่อมต่อของ TCP โดยมี ค่า FILTER ดังนี้

  1. established
  2. syn-sent
  3. syn-recv
  4. fin-wait-1
  5. fin-wait-2
  6. time-wait
  7. closed
  8. close-wait
  9. last-ack
  10. closing
  11. all - All of the above states
  12. connected - All the states except for listen and closed
  13. synchronized - All the connected states except for syn-sent
  14. bucket - Show states, which are maintained as minisockets, i.e. time-wait and syn-recv.
  15. big - Opposite to bucket state.

การกรองจะใช้คำสั่ง

//For tcp ipv4:
ss -4 state FILTER
//For tcp ipv6:
ss -6 state FILTER

แทนค่า FILTER

# ss -4 state listening
Netid  Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
tcp    0      128                     *:sunrpc                                *:*                    
tcp    0      128                     *:ssh                                   *:*                    
tcp    0      100             127.0.0.1:smtp                                  *:*   

# ss -4 state established
Netid  Recv-Q Send-Q      Local Address:Port                       Peer Address:Port                
udp    0      0               10.0.2.15:36327                     124.109.2.169:ntp                  
tcp    0      0               10.0.2.15:ssh                            10.0.2.2:58403

แสดง Listening sockets

# ss -ltn
State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN     0      128                     *:111                                 *:*                  
LISTEN     0      128                     *:22                                  *:*                  
LISTEN     0      100             127.0.0.1:25                                  *:*                  
LISTEN     0      128                    :::111                                :::*                  
LISTEN     0      128                    :::22                                 :::*                  
LISTEN     0      100                   ::1:25                                 :::*

แสดง listening udp

# ss -lun
State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
UNCONN     0      0                       *:68                                  *:*                  
UNCONN     0      0                       *:1795                                *:*                  
UNCONN     0      0               127.0.0.1:323                                 *:*                  
UNCONN     0      0                      :::9214                               :::*                  
UNCONN     0      0                     ::1:323                                :::*

ให้แสดง Process name / PID

# ss -ltnp
State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN     0      128                     *:111                                 *:*                   users:(("systemd",pid=1,fd=42))
LISTEN     0      128                     *:22                                  *:*                   users:(("sshd",pid=951,fd=3))
LISTEN     0      100             127.0.0.1:25                                  *:*                   users:(("master",pid=1391,fd=13))
LISTEN     0      128                    :::111                                :::*                   users:(("systemd",pid=1,fd=41))
LISTEN     0      128                    :::22                                 :::*                   users:(("sshd",pid=951,fd=4))
LISTEN     0      100                   ::1:25                                 :::*                   users:(("master",pid=1391,fd=14))

แสดง Summary Statics

# ss -s
Total: 199 (kernel 228)
TCP:   7 (estab 1, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0

Transport Total     IP        IPv6
*      228       -         -        
RAW      2         0         2        
UDP      6         4         2        
TCP      7         4         3        
INET      15        8         7        
FRAG      0         0         0

results matching ""

    No results matching ""