Networking commands - toge510/homelab GitHub Wiki

ss

: Utility to investigate sockets. Similar to netstat.

ex) sudo ss -ltunp: Inspect what programs are currently running and waiting for incoming network connections

$ sudo ss -ltunp
Netid State  Recv-Q Send-Q                     Local Address:Port  Peer Address:PortProcess   
.                                                                                                                 
tcp   LISTEN 0      128                              0.0.0.0:22         0.0.0.0:*    users:(("sshd",pid=1343,fd=3))   
.
.                                                  
  • -l: listening
  • -t: TCP connections
  • -u: UDP connections
  • -n: numeric values
  • -p: processes *0.0.0.0 means that this will accept connections from any external IP address

lsof

: Lists open files and the corresponding processes.

ex) lsof -i :port: Find the process that opened a local internet port

goto@homelab:~$ sudo lsof -i :22
COMMAND    PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
.
sshd      1343 root    3u  IPv4   26246      0t0  TCP *:ssh (LISTEN)
.
.

ip route

: IP Routing table management

  • Default route: displays as "default" and used when no route matching the destination IP address is found. Typically, the next-hop IP address or interface name is displayed after "via". 
  • Network route: displays route information for a specific network.
  • Host route: displays route information for a specific host.

ex) ip r(ip route show): Display the routing table

goto@homelab:~$ ip r
default via 192.168.11.1 dev enp2s0 proto dhcp src 192.168.11.2 metric 100 
192.168.11.0/24 dev enp2s0 proto kernel scope link src 192.168.11.2 metric 100 
192.168.11.1 dev enp2s0 proto dhcp scope link src 192.168.11.2 metric 100

*default gateway: 192.168.11.1