الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

ss

Show network sockets: which ports are listening, which connections are open, and which process owns them.

المستوى
امتحان RHCSA
المجموعة
الشبكة
يحتاج root
للتغييرات
الحزمة
iproute

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

ss (socket statistics) replaces the old netstat. The most used form is ss -tulpn: TCP and UDP, listening, with processes, as numbers.

You can filter by state (state established), port (sport = :22, dport = :443) and address (dst 192.168.122.0/24). Process names (-p) of other users are only shown to root.

طريقة الكتابة

ss [OPTION]... [FILTER]

الخيارات 39

الأكثر استخدامًا

What to show

-t, --tcp
TCP sockets.
-u, --udp
UDP sockets.
-l, --listening
Only listening sockets.
-a, --all
Listening and other sockets.
-x, --unix
Unix domain sockets.
-w, --raw
Raw sockets.
-d, --dccp
DCCP sockets.
-S, --sctp
SCTP sockets.
-M, --mptcp
MPTCP sockets.
-0, --packet
Packet sockets.
-4, --ipv4
Only IPv4.
-6, --ipv6
Only IPv6.
-f, --family=FAMILY
Only this family: inet, inet6, link, unix, netlink, vsock, tipc, xdp.
-A, --query=QUERY
Socket tables to show (like all, inet, tcp, udp, unix).
-N, --net=NETNS
Switch to this network namespace.

Details

-n, --numeric
Numbers for ports and addresses (faster).
-r, --resolve
Resolve names.
-p, --processes
Show the process that uses the socket.
-T, --threads
Show the threads too.
-e, --extended
Extra information (uid, inode).
-o, --options
Timer information.
-m, --memory
Socket memory use.
-i, --info
Internal TCP information (rtt, cwnd …).
-s, --summary
Totals per type.
-Z, --context
SELinux context of the process.
-z, --contexts
SELinux context of process and socket.
--tos
ToS and priority information.
--cgroup
The cgroup of the socket.
--tipcinfo
TIPC socket details.
--inet-sockopt
Show inet socket options.

Output

-H, --no-header
No header line.
-O, --oneline
One line per socket.
-E, --events
Show sockets as they are destroyed (live).
-D, --diag=FILE
Dump raw data to a file.
-F, --filter=FILE
Read the filter from a file.
-K, --kill
Close the matching sockets (root).
-b, --bpf
Show the BPF filter of sockets.
-h, --help
Show help.
-V, --version
Show the version.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Which ports are open?

    ss -tulpn
    Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process
    udp   UNCONN 0      0          127.0.0.1:323        0.0.0.0:*     users:(("chronyd",pid=812,fd=5))
    tcp   LISTEN 0      128          0.0.0.0:22         0.0.0.0:*     users:(("sshd",pid=1010,fd=3))
    tcp   LISTEN 0      511                *:80               *:*     users:(("httpd",pid=1420,fd=4))

    The most used form. 0.0.0.0 or * = all addresses; 127.0.0.1 = only local.

  2. 2Is my service listening?

    ss -tlnp | grep ':80 '

    Nothing = the service did not start or listens on another port.

  3. 3Open SSH connections

    ss -tn state established '( sport = :22 )'

    Who is connected to this server now.

  4. 4Connections to a remote port

    ss -tn dst :443

    Outgoing HTTPS connections.

  5. 5Summary of all sockets

    ss -s

    Totals; many TIME-WAIT can mean a busy web server.

  6. 6Connections from one network

    ss -tn dst 192.168.122.0/24

    Filter by address.

  7. 7Find unknown listeners (security)

    ss -tulpn | grep -vE ':(22|80|443|323)\b'

    Every open port should be known; a strange one can be a backdoor.

  8. 8Show the SELinux context of listeners

    ss -tlnZ

    Helps when SELinux blocks a service on a new port.

  9. 9Close a hanging connection

    ss -K dst 192.168.122.99 dport = :8080

    Needs a kernel with socket destroy support.

  10. 10Watch new connections

    watch -n1 'ss -tn state established | wc -l'

    Number of open connections every second.

  11. 11Unix sockets of a service

    ss -xlp | grep podman

    Local sockets (like the podman or docker API).

انتبه

  • Without root, -p shows only your own processes.
  • A port in LISTEN is not reachable when the firewall blocks it. Check firewall-cmd --list-all.

رموز الخروج

0Done.
1Error.