In one minute
- The commands you use on a real server to check its network: network cards, routes, open ports, and whether another machine answers.
- "I can't connect" is one of the most common tickets in DevOps. These tools tell you exactly where the connection breaks.
- Each command checks one step of the journey:
ip addr(do I have an address?),ip route(do I know the way?),ping(can I reach the machine?),ss(is my app listening?),nc/curl(does the remote port answer?). - 👉 Every "can't connect", "timeout" or "connection refused" problem.
Think of it like: checking why a parcel did not arrive. Is the address right? Is there a road? Is anyone home? Did they open the door?
Network cards: ip link and ip addr
A network card (an interface) is how a machine connects to a network. ip shows each one and its address.
👉 The first check: is the interface up, and does it have the right IP?
The ip command replaced the old ifconfig, route and arp.
ip linkip addr show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 state UP inet 10.0.1.25/24 brd 10.0.1.255 scope global eth0| Part | Meaning |
|---|---|
UP,LOWER_UP | Switched on, and the cable (or virtual link) is connected |
mtu 9001 | Biggest packet size (9001 = "jumbo frames" on AWS) |
inet 10.0.1.25/24 | IPv4 address and subnet |
brd | Broadcast address |
Quick changes (lost on reboot):
sudo ip addr add 10.0.1.50/24 dev eth0sudo ip link set eth0 downsudo ip link set eth0 upRouting table: ip route
The routing table is the machine's list of directions: "to reach this network, go that way".
👉 The machine has an IP but cannot reach somewhere.
ip routedefault via 10.0.1.1 dev eth010.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.25172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1default via 10.0.1.1is the default gateway: "if no other rule matches, send it here". This is usually the way to the internet.10.0.1.0/24 dev eth0means the local network is reached directly.- When several routes match, the most specific one wins (the biggest number after the slash).
Ask which way one address would go:
ip route get 8.8.8.8# 8.8.8.8 via 10.0.1.1 dev eth0 src 10.0.1.25No default route = no internet. A wrong route = traffic leaves the wrong way.
Think of it like: road signs. Specific signs ("City centre: turn left") beat the general one ("All other places: straight on").
Neighbours: ip neigh
Shows the hardware (MAC) addresses of machines on the local network.
👉 Rarely. A FAILED entry for the gateway means the local network link itself is broken.
Permanent configuration
The commands above are temporary. Permanent settings live in files, and the files differ by distribution:
| Distribution | Tool | Files |
|---|---|---|
| Ubuntu 18.04+ | netplan | /etc/netplan/*.yaml, apply with netplan apply |
| RHEL 8+, Rocky | NetworkManager | nmcli, files in /etc/NetworkManager/ |
| Older RHEL | network-scripts | /etc/sysconfig/network-scripts/ifcfg-eth0 |
An Ubuntu netplan example:
network: version: 2 ethernets: eth0: addresses: [10.0.1.50/24] routes: - to: default via: 10.0.1.1 nameservers: addresses: [10.0.0.2]Safety tip: sudo netplan try applies the change and undoes it automatically after 120 seconds unless you confirm. This saves you if the change cuts off your SSH session.
On cloud servers, the network is usually set up automatically (by DHCP and cloud-init), so you rarely edit these files.
Can I reach it? ping
ping sends a small "are you there?" message and waits for the reply.
👉 A first, quick check that a machine is reachable, and how fast.
ping -c 3 10.0.2.1064 bytes from 10.0.2.10: icmp_seq=1 ttl=64 time=0.412 ms--- 10.0.2.10 ping statistics ---3 packets transmitted, 3 received, 0% packet loss-c 3sends three pings and stops. Without it, ping runs until you press Ctrl+C.timeis the round trip. Normal values: under 1 ms in the same data centre, 1–2 ms between zones, 50–250 ms across continents.- No reply does NOT prove the machine is down. Cloud firewalls often block ping. Test the real port instead.
The path: traceroute and mtr
traceroute lists each router (hop) a packet passes through.
👉 Traffic is slow or lost somewhere along the way, and you want to know where.
traceroute example.com* * * means a hop did not reply. That is often normal. mtr is a live version of ping plus traceroute, and shows where packet loss starts.
Who is listening? ss
ss shows which ports programs are listening on. It replaced netstat.
👉 "Is my app actually running and listening?"
ss -tulpnss -tn| Option | Meaning |
|---|---|
-t / -u | TCP / UDP |
-l | Only listening ports |
-p | Show the process |
-n | Show numbers, not names (faster and clearer) |
-s | Summary counts |
Remember it:
ss -tulpn= "tell us listening ports, numbers".
The key question: which address is it listening on?
| Listening on | Who can reach it |
|---|---|
127.0.0.1:8080 | Only this machine |
0.0.0.0:8080 | Every network card, so other machines too |
10.0.1.25:8080 | Only through that one IP |
Many "connection refused" tickets are an app listening on 127.0.0.1 when it should listen on 0.0.0.0. Inside Docker this is the number one mistake: the app must listen on 0.0.0.0, or publishing the port will not work.
Does the remote port answer? nc and curl
nc (netcat) tests if a port on another machine accepts connections. curl goes further and talks HTTP to it.
👉 The decisive test in any "can't connect" problem.
nc -zv 10.0.2.10 5432curl -I http://localhostConnection to 10.0.2.10 5432 port [tcp/postgresql] succeeded!How to read the result:
| Result | Meaning | Usual cause |
|---|---|---|
| succeeded / HTTP response | The port is open and answering | The problem is higher up (login, app logic) |
| Connection refused | Reached the machine, but nothing is listening | Service down, wrong port, or listening on 127.0.0.1 |
| Timed out | Packets were dropped on the way | Security group, firewall, NACL or wrong route |
| No route to host | No path, or a firewall actively rejected it | Routing, or a REJECT rule |
Remember it: Refused = the door is there, but nobody is home (the network is fine). Timeout = something blocked the road (firewall or route).
Downloading and calling APIs: curl and wget
curl sends web requests from the terminal. wget downloads files.
👉 Testing a health check, calling an API, downloading a file.
curl -s http://localhost/healthcurl -o page.html https://example.com| Option | Use |
|---|---|
-I | Headers only |
-v | Verbose: shows DNS, connection, TLS and headers |
-s | Silent (no progress bar) |
-o file / -O | Save to a file |
-L | Follow redirects |
-X POST -d '...' | Send data |
-H "Header: x" | Add a header |
-w "%{http_code}" | Print only the status code |
--max-time 5 | Give up after 5 seconds instead of hanging |
Real-world scenario: "the service is unreachable"
ip -br addrip routess -tulpnnc -zv 10.0.2.10 5432curl -I http://localhost- On the server: is the app listening, and on
0.0.0.0? (ss -tulpn) - On the server itself: does
curl localhost:8080work? If not, the app is the problem. - From the client:
nc -zv server 8080. Refused → check what the app listens on. Timeout → check the firewall or security group. - Fix the right layer and test again.
Common mistakes
- Trusting ping alone. Ping is often blocked. Test the real TCP port.
- Apps listening on 127.0.0.1 inside containers or VMs.
- Changing network settings over SSH without a safety net, and locking yourself out. Use
netplan tryor a console. - Using
ifconfigandnetstat. They are old and often not installed.
Practice
- Find the machine's default gateway.
- List listening TCP ports with their processes, and say which ones other machines can reach.
- Test whether port 5432 on
10.0.2.10is open. - Fetch only the headers of
http://localhost. - Explain the difference between "connection refused" and "timed out".
Cheat sheet
| Command | What it does |
|---|---|
ip -br addr | Interfaces and IPs, short form |
ip route / ip route get IP | Routing table / the route for one address |
ping -c 3 host | Basic "are you there?" |
traceroute host / mtr host | The path, and where loss starts |
ss -tulpn | Listening ports and their programs |
nc -zv host port | Test a TCP port |
curl -v url | The full HTTP conversation |
Key takeaways
ip addrshows the machine's address.ip routeshows the way out.ss -tulpnshows which apps are listening, and on which address.- An app must listen on
0.0.0.0for other machines to reach it. - Do not trust ping alone. Test the real port with
ncorcurl. - "Refused" means nobody is listening. "Timeout" means something is blocking.