Skip to content
$ lynuxpro
← Linux

LESSON 14 OF 26 · INTERMEDIATE · 19 MIN

Network configuration and commands

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?

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 eth0
SHELLbashutf-8 · 2L
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 state UP    inet 10.0.1.25/24 brd 10.0.1.255 scope global eth0
OUTPUTterminalutf-8 · 2L
PartMeaning
UP,LOWER_UPSwitched on, and the cable (or virtual link) is connected
mtu 9001Biggest packet size (9001 = "jumbo frames" on AWS)
inet 10.0.1.25/24IPv4 address and subnet
brdBroadcast 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 up
OUTPUTterminalutf-8 · 3L

Routing 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 route
SHELLbashutf-8 · 1L
default 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.1
OUTPUTterminalutf-8 · 3L
  • default via 10.0.1.1 is 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 eth0 means 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.25
OUTPUTterminalutf-8 · 2L

No 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:

DistributionToolFiles
Ubuntu 18.04+netplan/etc/netplan/*.yaml, apply with netplan apply
RHEL 8+, RockyNetworkManagernmcli, files in /etc/NetworkManager/
Older RHELnetwork-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]
NORMALyamlutf-8 · 10L

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.10
SHELLbashutf-8 · 1L
64 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
OUTPUTterminalutf-8 · 3L
  • -c 3 sends three pings and stops. Without it, ping runs until you press Ctrl+C.
  • time is 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
SHELLbashutf-8 · 1L

* * * 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
SHELLbashutf-8 · 2L
OptionMeaning
-t / -uTCP / UDP
-lOnly listening ports
-pShow the process
-nShow numbers, not names (faster and clearer)
-sSummary counts

Remember it: ss -tulpn = "tell us listening ports, numbers".

The key question: which address is it listening on?

Listening onWho can reach it
127.0.0.1:8080Only this machine
0.0.0.0:8080Every network card, so other machines too
10.0.1.25:8080Only 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://localhost
SHELLbashutf-8 · 2L
Connection to 10.0.2.10 5432 port [tcp/postgresql] succeeded!
OUTPUTterminalutf-8 · 1L

How to read the result:

ResultMeaningUsual cause
succeeded / HTTP responseThe port is open and answeringThe problem is higher up (login, app logic)
Connection refusedReached the machine, but nothing is listeningService down, wrong port, or listening on 127.0.0.1
Timed outPackets were dropped on the waySecurity group, firewall, NACL or wrong route
No route to hostNo path, or a firewall actively rejected itRouting, 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
SHELLbashutf-8 · 2L
OptionUse
-IHeaders only
-vVerbose: shows DNS, connection, TLS and headers
-sSilent (no progress bar)
-o file / -OSave to a file
-LFollow redirects
-X POST -d '...'Send data
-H "Header: x"Add a header
-w "%{http_code}"Print only the status code
--max-time 5Give 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
SHELLbashutf-8 · 5L
  1. On the server: is the app listening, and on 0.0.0.0? (ss -tulpn)
  2. On the server itself: does curl localhost:8080 work? If not, the app is the problem.
  3. From the client: nc -zv server 8080. Refused → check what the app listens on. Timeout → check the firewall or security group.
  4. 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 try or a console.
  • Using ifconfig and netstat. They are old and often not installed.

Practice

  1. Find the machine's default gateway.
  2. List listening TCP ports with their processes, and say which ones other machines can reach.
  3. Test whether port 5432 on 10.0.2.10 is open.
  4. Fetch only the headers of http://localhost.
  5. Explain the difference between "connection refused" and "timed out".

Cheat sheet

CommandWhat it does
ip -br addrInterfaces and IPs, short form
ip route / ip route get IPRouting table / the route for one address
ping -c 3 hostBasic "are you there?"
traceroute host / mtr hostThe path, and where loss starts
ss -tulpnListening ports and their programs
nc -zv host portTest a TCP port
curl -v urlThe full HTTP conversation

Key takeaways

  • ip addr shows the machine's address. ip route shows the way out.
  • ss -tulpn shows which apps are listening, and on which address.
  • An app must listen on 0.0.0.0 for other machines to reach it.
  • Do not trust ping alone. Test the real port with nc or curl.
  • "Refused" means nobody is listening. "Timeout" means something is blocking.