Linux Network Commands Cheat Sheet

Linux Network Commands Cheat Sheet
The important Linux network commands include ip for addresses and routes, ss for open ports and connections, ping and traceroute for reachability, dig for DNS, and curl for testing services' availability. This cheat sheet includes what each command is good for and when to use it.
What are the essential Linux network commands?
ip, ss, ping, dig, and curl cover all that is necessary. The ip command manages addresses and routes, ss displays ports and connections, ping and dig test reachability and DNS resolution, while curl checks whether the service works.
Command | What it's for | Common usage |
|---|---|---|
| Display IP addresses for each network interface |
|
| Display the routing table |
|
| Display open ports and connections |
|
| Test reachability to a host |
|
| Discover path and identify its problematic parts |
|
| Request DNS records directly |
|
| Check whether an HTTP(s) service works |
|
While older tutorials often refer to ifconfig and netstat, they are deprecated on modern systems in favor of ip and ss โ they may still work, but there is no reason to choose them over their alternatives on modern systems.
How do I check my IP address and network interfaces on Linux?
Use ip addr (shorter variant โ ip a). It shows all network interfaces and assigned addresses.
$ ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
inet 203.0.113.10/24 brd 203.0.113.255 scope global eth0
As explained in the ip man page, it can be used to "show / manipulate routing, network devices, interfaces and tunnels". ip addr is only one object among others that this tool can operate with; ip route displays the routing table in the same way using the same command format.
How do I check open ports and active connections?
Use ss -tulpn. It displays listening TCP and UDP ports and processes using these ports.
$ ss -tulpn
Netid State Local Address:Port Process
tcp LISTEN 0.0.0.0:22 sshd
tcp LISTEN 0.0.0.0:443 nginx
According to the ss man page, it "is used to dump socket statistics" and "can display more TCP and state information than other tools". It is an actively maintained replacement of netstat, and the flags are similar enough (-t stands for TCP, -u stands for UDP, -l stands for listening, -p stands for process, -n stands for numeric ports) to switch to it easily.
How do I test connectivity to another host?
Run ping hostname to test reachability of a host or traceroute hostname to test which node along the way fails.
$ ping -c 4 example.com
$ traceroute example.com
With ping, you can find out if a host is accessible, but you cannot understand why it is inaccessible if it is not. In such cases, traceroute comes into play since it displays each node on the way to the destination and helps to understand where the problem occurs.
Where do these commands matter most?
Whenever something that should be reachable is unreachable, and you need to identify the source of the problem.
Our VPS plans and Bare Metal servers let you have complete access to networking to run all commands from the list, so diagnosing a connectivity issue won't be restricted by the provider's control plane layer.
Get started with Orbit Servers
Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.
Get startedRelated products
Written by
Julius