netstat -a | Display All Connections (default: connected) -a, –all, –listening display all sockets |
netstat -at | List Only TCP connections (default: connected) |
netstat -au | List Only UDP Connections | ||
netstat -ant | Show IP Address without Reverse DNS lookup -a, –all, –listening display all sockets (default: connected) -n, –numeric don’t resolve names [–tcp|-t] |
||
netstat -anu | Show IP Address without Reverse DNS lookup -a, –all, –listening display all sockets (default: connected) -n, –numeric don’t resolve names [–udp|-u] |
||
netstat -l | List All Listening Conditions -l, –listening display listening server sockets |
||
List Only Listening TCP Ports / FQDN | netstat -lt | -l, –listening [–tcp|-t] |
|
List only listening UDP Ports / FQDN | netstat -lu | -l, –listening [–udp|-u] |
|
List only listening UDP Ports / IP | netstat -lnt | -l, –listening -n, –numeric don’t resolve names [–tcp|-t] |
|
List only listening TCP Ports / IP | netstat -lnu | -l, –listening -n, –numeric don’t resolve names [–udp|-u] |
|
List only listening UDP end TCP Ports / IP | netstat -lntu | -l, –listening -n, –numeric don’t resolve names [–tcp|-t] [–udp|-u] |
|
Check Open Ports (both ipv4 and ipv6) | netstat -lntup | -l, –listening -n, –numeric don’t resolve names [–tcp|-t] [–udp|-u] -p, –program |
|
netstat -lntupe netstat -tulpen |
-l, –listening -n, –numeric don’t resolve names [–tcp|-t] [–udp|-u] -p, –program -e, –extend |
||
netstat -s | Display Summary Statistics | netstat -st | Display Statistics for TCP |
netstat -su | Display Statistics for UDP | ||
netstat -F | FQDN / Displays Domain Name. (This is the default.) Print routing information from the FIB. |
||
netstat -n | IP / Display Only IP address | ||
netstat -c | Get Netstat Output Continuously. This will cause netstat to print the selected information every second continuously. |
netstat -ct | [–tcp|-t] -c, –continuous |
The -c option can be combined with other netstat options like -t (see below). |
[–tcp|-t] -c, –continuous |
||
netstat -lntupec netstat -tulpenc |
-l, –listening -n, –numeric don’t resolve names [–tcp|-t] [–udp|-u] -p, –program -e, –extend -c, –continuous |
||
netstat -p | Display Process Identifier (PID)Show the PID and name of the program to which each socket belongs. |
netstat -tp | Show Service Name with PID Number |
netstat -tcp | Displays TCP Connections Continuously. Above command will output TCP connections along with PID continuously. |
||
netstat -r | Display the kernel routing tables. See the description in route(8) for details. netstat -r and route -e produce the same output. |
netstat -rn | -r, –route -n, –numeric |
netstat -i | Display a table of all network interfaces. Display a table of all network interfaces. |
netstat -ie | -i, –interfaces -e, –extend |
USGABE Aktive Internet-Verbindungen (TCP, UDP, RAW) Proto Das von Socket verwendete Protokoll (TCP, UDP, RAW). Recv-Q Die Anzahl von Bytes, die noch nicht von der Anwendung vom Socket abgeholt wurden. Send-Q Die Anzahl von Bytes, die von der Gegenseite noch nicht bestätigt wurde. Lokale Adresse Die lokale Adresse (lokaler Rechnername) und Portnummer des Sockets. Außer bei Verwendung dern Option wird die Socketadresse nach dem kanonischen Rechnernamen und die Portnummer in den zugehörigen Dienstenamen aufgelßt. Foreign Address Die Adresse und Portnummer der Gegenseite des Sockets. Wie bei lokalen Adressen schaltet dern Schalter die Umwandlung von Rechneradresse und Portnummer ab. State Der Zustand des Sockets. Da RAW-Sockets keinen und UDP-Sockets üblicherweise keinen Zustand haben, kann diese Spalte leer bleiben. Normalerweise ist sie einer von mehreren Werten: ESTABLISHED The socket has an established connection. SYN_SENT Es wird versucht auf dem Socket eine Verbindung aufzubauen. SYN_RECV Eine Verbindungsanfrage wurde von der Gegenseite empfangen. FIN_WAIT1 Der Socket wurde geschloßen und die Verbindung wird beendet. FIN_WAIT2 Die Verbindung ist geschlßen und der Socket wartet darauf, daß sie von der Gegenseite ebenfalls geschloßen wird. TIME_WAIT Der Socket ist nach dem Schließen im Wartezustand um Pakete handzuhaben, die sich eventuell noch im Netzwerk befinden. CLOSE Der Socket wird nicht benutzt. CLOSE_WAIT Die Gegenseite hat die Verbindung beendet und das Schließen des Sockets wird erwartet. LAST_ACK Die Gegenseite hat die Verbindung beendet und der Socket ist geschloßen; die Bestätigung wird abgewartet. LISTEN Der Socket wartet auf eingehende Verbindungen. Diese Sockets werden nur angezeit, wenn die The socket is listening for incoming connections. Those sockets are only displayed if the -a,--listening Option gegeben wird. CLOSING Beide Sockets sind geschloßen es wurden aber noch nicht alle Daten geschickt. UNKNOWN Der Zustand des Sockets ist unbekannt. User Der Name oder die Benutzer-ID des Eigentümers des Sockets. PID/Program name Durch einen Schrägstrich abgetrenntes Paar von Prozess-ID und Programmname des Programms, das diesen Socket besitzt. Die Option -p schaltet die Anzeige dieser Spalte ein. Es werden root Privilegien benötigt um die nötigen Daten zu erhalten. Für IPX Sockets sind diese Daten nicht verfügbar. Timer (Dies muß noch geschrieben werden) Aktive Sockets in der UNIX Domäne Proto Das Protokoll (in der Regel unix), das vom Socket verwendet wird. RefCnt Der Referenzzähler, d.h. die Zahl der Prozesse, die diesen Socket benutzen. Flags Die Flaggen, die angezeigt werden sind SO_ACCEPTON (angezeigt als ACC), SO_WAITDATA (W) oder SO_NOSPACE (N). SO_ACCECPTON wird auf unverbundenen Sockets verwendet, wenn die zugehörigen Sockets auf Verbindungsanfragen warten. Die anderen Flaggen sind normalerweise nicht von Interesse. Type Es gibt verschiedene Arten von Socketzugriff: SOCK_DGRAM Der Socket wird im verbindungslosen Datagram-Modus verwendet. SOCK_STREAM Dies ist ein verbindungsorientierter Stream-Socket. SOCK_RAW Der Socket wird als RAW-Socket verwendet. SOCK_RDM Dieser Socket bedient zuverlßig zugestellte Nachrichten. SOCK_SEQPACKET Dies ist ein Socket, der die Zustellung in der richtigen Reihenfolge garantiert. SOCK_PACKET Socket mit direktem (RAW) Zugriff auf die Schnittstelle. UNKNOWN Wer weiß, was uns die Zukunft bringt soll es hier hinschreiben :-) State/Zustand Dieses Feld enthält eines der folgenden Schlüsselworte: FREE Der Socket ist unbenutzt LISTENING Der Socket lauscht nach Verbindungsanfragen. Diese Sockets werden nur angezeigt, wenn die -a,--listening Option gesetzt ist. CONNECTING Auf dem Socket wird gerade eine Verbindung aufgebaut. CONNECTED Auf dem Socket ist Verbindung aufgebaut. DISCONNECTING Die Verbindung des Sockets wird gerade abgebaut. (empty) Der Socket hat keine Verbundung zu einem anderen Socket. UNKNOWN Ein Socket sollte niemals in diesem Zustand sein.
# --------------------------------------------------------- # --- : Show Active/Established Connections # netstat -atnp | grep ESTA # # tcp 0 0 10.3.14.7:58410 172.217.22.14:443 ESTABLISHED 10133/chrome # tcp 0 0 10.3.14.7:36804 216.58.211.206:443 ESTABLISHED 10133/chrome # tcp 0 0 10.3.14.7:55412 104.27.159.202:80 ESTABLISHED 2574/firefox # tcp 0 0 10.3.14.7:57938 52.38.159.157:443 ESTABLISHED 2574/firefox # tcp 0 0 10.3.14.7:33804 52.42.108.131:443 ESTABLISHED 2574/firefox # tcp 0 0 10.3.14.7:44530 31.13.93.3:443 ESTABLISHED 2574/firefox # tcp 0 0 10.3.14.7:49168 172.217.22.13:443 ESTABLISHED 2574/firefox # tcp 0 0 10.3.14.7:38396 172.217.22.5:443 ESTABLISHED 2574/firefox # # --------------------------------------------------------- # --- : Get Continuous List of Active Connections watch -d -n0 "netstat -atnp | grep ESTA" # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Check if a Service is Running # netstat -aple | grep dnsmasq # tcp 0 0 nautilus-t410:domain *:* LISTEN root 27011 2429/dnsmasq # udp 0 0 *:48234 *:* nobody 27114 2429/dnsmasq # udp 0 0 nautilus-t410:domain *:* root 27010 2429/dnsmasq # unix 2 [ ] DGRAM 27018 2429/dnsmasq # unix 3 [ ] STREAM CONNECTED 27012 2429/dnsmasq # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Display IPs with High Number of Connections. These commands are useful in identifying malicious visitors. # Some of them are useful in bringing small-scale DOS attacks under control. netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head # 1 104.27.159.202 # ---------------------------------------------------------
# --------------------------------------------------------- # --- : # netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' |sed -e 's/::ffff://' | cut -f1 -d: | sort | uniq -c | sort -rn | head # 1 104.27.159.202 # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Display Number of Active Connections on Port 80 # netstat -an |grep :80 |wc -l # 4 netstat -an |grep :80 # tcp 0 0 10.3.14.7:32838 216.58.208.42:80 TIME_WAIT # tcp 0 0 10.3.14.7:55452 104.27.159.202:80 ESTABLISHED # tcp 0 0 10.3.14.7:57288 216.58.212.234:80 TIME_WAIT # tcp 0 0 10.3.14.7:57284 216.58.212.234:80 TIME_WAIT # # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Displays Foreign IP Addresses Only # netstat -antu | grep :80 | grep -v LISTEN | awk '{print $5}' # 104.27.159.202:80 # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Display Active SYNC_REC # The below command will output how many active SYNC_REC are occurring and happening # on the server. The number should be low (less than 5). If the number is in double # digits, you may be suffering a DoS attack or being mail bombed. netstat -n -p|grep SYN_REC | wc -l # ---------------------------------------------------------
# --------------------------------------------------------- # --- : List Unique IP Addresses Sending SYN_REC Connection # Like the above command, this command too lists all unique IP addresses of the node that are sending SYN_REC connection status netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}' # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Connections Per Remote IP # netstat -antu | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n # or netstat -antu | awk '$5 ~ /[0-9]:/{split($5, a, ":"); ips[a[1]]++} END {for (ip in ips) print ips[ip], ip | "sort -k1 -nr"}' # ---------------------------------------------------------
# --------------------------------------------------------- # --- :Number of Open Connections per IP netstat -an | grep 80 | wc -l # ---------------------------------------------------------
# --------------------------------------------------------- # --- : Active Internet Connections # netstat -pnut -w | column -t -s $'\t' # ---------------------------------------------------------
# --------------------------------------------------------- # --- :-s, --statistics display networking statistics (like SNMP) # netstat -s # Ip: # 145490 total packets received # 1 with invalid addresses # 0 forwarded # 0 incoming packets discarded # 144857 incoming packets delivered # 105602 requests sent out # 188 outgoing packets dropped # 4 dropped because of missing route # Icmp: # 428 ICMP messages received # 0 input ICMP message failed. # ICMP input histogram: # destination unreachable: 428 # 444 ICMP messages sent # 0 ICMP messages failed # ICMP output histogram: # destination unreachable: 444 # IcmpMsg: # InType3: 428 # OutType3: 444 # Tcp: # 1523 active connections openings # 0 passive connection openings # 0 failed connection attempts # 40 connection resets received # 4 connections established # 139918 segments received # 100264 segments send out # 20 segments retransmited # 7 bad segments received. # 420 resets sent # Udp: # 4299 packets received # 428 packets to unknown port received. # 0 packet receive errors # 4868 packets sent # UdpLite: # TcpExt: # 8 packets pruned from receive queue because of socket buffer overrun # 554 TCP sockets finished time wait in fast timer # 1539 delayed acks sent # 1 delayed acks further delayed because of locked socket # Quick ack mode was activated 197 times # 8 packets directly queued to recvmsg prequeue. # 4902 bytes directly received in process context from prequeue # 95779 packet headers predicted # 7 packets header predicted and directly queued to user # 14072 acknowledgments not containing data payload received # 5339 predicted acknowledgments # 1 congestion windows recovered without slow start after partial ack # 1 other TCP timeouts # TCPLossProbes: 20 # TCPLossProbeRecovery: 1 # 72 packets collapsed in receive queue due to low socket buffer # 158 DSACKs sent for old packets # 12 DSACKs received # 116 connections reset due to unexpected data # 31 connections reset due to early user close # TCPDSACKIgnoredNoUndo: 8 # TCPRcvCoalesce: 70824 # TCPOFOQueue: 226 # TCPChallengeACK: 7 # TCPSYNChallenge: 7 # TCPSpuriousRtxHostQueues: 4 # TCPAutoCorking: 3263 # TCPWantZeroWindowAdv: 1 # TCPSynRetrans: 1 # TCPOrigDataSent: 19471 # TCPHystartTrainDetect: 3 # TCPHystartTrainCwnd: 74 # TCPHystartDelayDetect: 1 # TCPHystartDelayCwnd: 19 # TCPKeepAlive: 7458 # IpExt: # InMcastPkts: 324 # OutMcastPkts: 713 # InBcastPkts: 66 # OutBcastPkts: 2 # InOctets: 151150204 # OutOctets: 14177464 # InMcastOctets: 32836 # OutMcastOctets: 132480 # InBcastOctets: 19724 # OutBcastOctets: 1948 # InNoECTPkts: 145490 # ---------------------------------------------------------