Skip to content
Visual explainer 2h 30m to learn 4 steps

ip, ss, curl & nmap on the host

Inspect interfaces, routes, sockets and open ports from the command line.

By Invicly Tech, , in Computer Networking. About 11 minutes to read.

Topic 37 of 51

In short

On Linux the ip command shows and changes interfaces, addresses and routes, while ss lists sockets and the processes that own them. curl tests application endpoints with full control over headers and timing. nmap scans hosts to discover open ports, which you should only do on systems you own or are authorised to test.

Explained simply

When a server or laptop has network trouble, the first place to look is the machine itself. On Linux, a few commands tell you almost everything: which network cards exist, which IP addresses they have, where traffic is sent, and which programs are waiting for connections.

ip shows and changes interfaces, addresses and routes. ss lists sockets, which are the open connections and listening ports, along with the program that owns each one. Together they answer "does this machine have the right address and route?" and "is my service actually listening?"

curl talks to web services the way a browser does, but shows every detail: the request, the response headers, the status code and how long each stage took. It is the standard way to test an API or website from the command line.

nmap checks which ports are open on a machine from the outside, like a visitor knocking on every door. It is great for checking your own firewall, but scanning systems you do not own or have no permission to test can be illegal, so only use it on your own hosts.

Press Play on a diagram to walk through it one step at a time.

LayersWhich tool checks which layer
  1. 1
    Application

    curl -v, openssl s_client

  2. 2
    Transport

    ss -tulpn, nc -zv, nmap

  3. 3
    Network

    ip addr, ip route, ping

  4. 4
    Data link

    ip link, ip neigh

  5. 5
    Physical

    ethtool, iw

Flow"My service is not reachable" checklist
  1. 1
    Is it running?

    systemctl status app

  2. 2
    Is it listening?

    ss -tlnp | grep 8080

  3. 3
    On which address?

    127.0.0.1 or 0.0.0.0

  4. 4
    Local test

    curl -v http://127.0.0.1:8080/

  5. 5
    Firewall

    nft list ruleset or ufw status

  6. 6
    Remote test

    nc -zv host 8080 or nmap -p 8080 host

In depth

ip: interfaces, addresses, routes and neighbours

ip comes from the iproute2 package and replaces ifconfig, route and arp. Its objects are link (the interface itself), addr (IP addresses), route (the routing table) and neigh (the ARP and IPv6 neighbour cache). Add -br for short tables and -c for colour.

ip -br link shows each interface as UP or DOWN. ip -s link shows packet and error counters; rising errors or drops hint at a bad cable or an overloaded card. ip route get 10.1.2.3 is the most useful single command: it asks the kernel which route, interface and source address it would use for that destination. ip neigh shows MAC addresses learned for local IPs; FAILED or INCOMPLETE for the gateway means layer 2 cannot reach it.

Changes made with ip are temporary and vanish on reboot. Permanent settings belong in NetworkManager (nmcli), netplan or systemd-networkd, depending on the distribution.

  • sudo ip addr add 10.0.0.5/24 dev eth0
  • sudo ip route add 10.9.0.0/16 via 10.0.0.1
  • sudo ip link set eth0 up
  • ip -6 route shows IPv6 routes

ss: who is listening and who is connected

ss replaces netstat and reads socket information straight from the kernel, so it is fast even with thousands of connections. The common flags are -t (TCP), -u (UDP), -l (listening only), -n (numbers, no name lookups), -p (owning process, needs sudo for other users' processes) and -a (all states).

The Local Address column matters most. 0.0.0.0:8080 or [::]:8080 means the service accepts connections on every interface. 127.0.0.1:8080 means only local programs can connect, a very common reason a service "works on the server but not from outside". You can filter by state and port: ss -tn state established '( dport = :443 )'. ss -s prints a summary of sockets per state; thousands of TIME-WAIT or SYN-RECV sockets point to connection churn or a SYN flood. ss -ti shows TCP internals such as RTT and retransmits for each connection.

CompareWhat the listen address means
127.0.0.1:8080
  • Loopback only
  • Reachable from the same host
  • Safe default for dev servers
  • Remote clients get connection refused
0.0.0.0:8080
  • All IPv4 interfaces
  • Reachable from the network
  • Firewall must allow the port
  • Typical for real services
10.0.0.5:8080
  • One specific address
  • Only via that interface
  • Used on multi-homed hosts
  • Fails if that IP is removed

curl: testing the application layer

curl -v shows the whole conversation: DNS result, TCP connect, TLS handshake and certificate, request headers and response headers. curl -I sends a HEAD request to see only headers; curl -L follows redirects; -H adds a header; -k skips certificate checks (for testing only).

Two options solve tricky cases. --resolve name:443:10.0.0.7 sends the request to a chosen IP while keeping the real host name for TLS and the Host header, so you can test one backend behind a load balancer, or a new server before DNS changes. -w prints timings: time_namelookup (DNS), time_connect (TCP done), time_appconnect (TLS done), time_starttransfer (first byte) and time_total. Each one is cumulative from the start, so subtract to get each stage. Set --connect-timeout and --max-time in scripts so a dead host does not hang them.

FlowWhere curl -w timings are measured
  1. 1
    time_namelookup

    DNS answer received

  2. 2
    time_connect

    TCP handshake complete

  3. 3
    time_appconnect

    TLS handshake complete

  4. 4
    time_starttransfer

    First byte of the response

  5. 5
    time_total

    Whole response received

nmap: seeing your host from outside

ss shows what listens; nmap shows what is reachable through firewalls. With root, the default scan is a SYN scan (-sS): it sends a SYN and reads the reply without finishing the handshake. Without root it uses a full connect scan (-sT). By default it scans the 1000 most common TCP ports; -p 22,80,443 picks ports and -p- scans all 65535.

nmap reports each port as open (a service answered), closed (the host replied with a reset, so nothing listens), or filtered (no reply or an ICMP error, so a firewall drops it). Filtered versus closed tells you whether a firewall or the service is the problem. -sV probes for service versions, -sU scans UDP (slow), -sn does host discovery only, and -Pn skips discovery for hosts that ignore ping. Always get written permission before scanning anything you do not own.

  • open: something accepted the connection
  • closed: host reachable, nothing listening
  • filtered: a firewall dropped or rejected the probe

Learn it in 4 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Show addresses and routes with ip~40m
  2. 2
    List listening sockets with ss~40m
  3. 3
    Test HTTP endpoints with curl~40m
  4. 4
    Scan your own hosts with nmap~40m

Key points

  • ip replaces the older ifconfig, route and arp commands.
  • ss -tulpn shows TCP and UDP listeners with owning processes.
  • A service bound to 127.0.0.1 is unreachable from other hosts.
  • curl -w prints DNS, connect, TLS and first-byte timings.

Key terms

Tap a card to flip it. 0/3 known

Examples

bash
ip -br addr                          # brief address list
ip route get 1.1.1.1
ss -tulpn                            # listeners and processes
nc -zv db.internal 5432              # is the port reachable?
curl -o /dev/null -s -w 'dns %{time_namelookup} connect %{time_connect} ttfb %{time_starttransfer}\n' https://example.com
nmap -sV -p 22,80,443 192.168.1.10   # only on hosts you own

A new API works on the server but not from your laptop

Step 1: ss shows the process listening on 127.0.0.1:8000, so it only accepts local connections. Step 2: change the app to bind to 0.0.0.0 and restart. Step 3: ss now shows 0.0.0.0:8000. Step 4: from the laptop, nmap reports 8000/tcp filtered, meaning the host firewall still drops it. Step 5: allow the port in the firewall; nmap now says open and curl returns 200.

bash
sudo ss -tlnp | grep 8000
# LISTEN 0 4096 127.0.0.1:8000 0.0.0.0:* users:(("uvicorn",pid=812,fd=6))
# fix: start with --host 0.0.0.0, then:
sudo ss -tlnp | grep 8000      # 0.0.0.0:8000
nmap -Pn -p 8000 10.0.0.5      # from laptop: filtered
sudo ufw allow 8000/tcp
nmap -Pn -p 8000 10.0.0.5      # open
curl -s -o /dev/null -w '%{http_code}\n' http://10.0.0.5:8000/health

Testing one backend behind a load balancer

Users see errors only sometimes, so one of three backends may be bad. Step 1: find the backend IPs from the load balancer config. Step 2: send the same HTTPS request to each one with --resolve, which keeps the real host name for TLS and routing. Step 3: compare status codes and timings. The backend that returns 502 or takes far longer is the culprit.

bash
for ip in 10.0.10.11 10.0.10.12 10.0.10.13; do
  curl -s -o /dev/null --max-time 5 \
    --resolve shop.example.com:443:$ip \
    -w "$ip %{http_code} connect=%{time_connect} total=%{time_total}\n" \
    https://shop.example.com/health
done

Quick reference

  • ip -br addr / ip -br link: one-line view of addresses and link state
  • ip route get 8.8.8.8: which route, interface and source IP the kernel would use
  • ip neigh: ARP cache; FAILED for the gateway means a layer 2 problem
  • ss -tlnp: TCP listeners with process; ss -s: socket counts per state
  • curl -v URL: full request, response headers and TLS details
  • curl --resolve host:443:IP URL: hit a chosen server but keep the real host name
  • nmap -Pn -p 22,80,443 host: check ports even if the host ignores ping
  • nmap states: open (listening), closed (reset), filtered (firewall)

Common mistakes

  • Scanning networks without permission.
  • Missing that a service listens on 127.0.0.1 instead of 0.0.0.0.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which command shows the route, interface and source address the kernel would use to reach 10.1.2.3?

Question 2

2nmap reports a port as filtered. What does that usually mean?

Question 3

3ss shows a service on 127.0.0.1:5432. What happens when another host connects to port 5432?

Question 4

4In curl -w output, time_connect is 0.02 s and time_starttransfer is 3.1 s. Where is most of the delay?

Question 5

5Which ss options list listening TCP sockets with numeric ports and owning processes?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List every TCP and UDP port your machine is listening on, and for each one say whether it is reachable from the network or only from the machine itself.

  2. Exercise 2medium

    Measure DNS, TCP connect, TLS and server time separately for an HTTPS site, printing each stage on its own line.

  3. Exercise 3hard

    On a VM you own, compare what ss says is listening with what nmap sees from another machine, and explain every difference.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is ifconfig deprecated?
Yes, on Linux ifconfig, route, arp and netstat come from the old net-tools package and are no longer installed on many distributions. Use ip and ss from iproute2 instead.
Is it legal to use nmap?
Scanning your own systems, or systems you have written permission to test, is normal practice. Scanning other people's networks without permission can break laws and terms of service in many countries.
What is the difference between netstat and ss?
Both list sockets, but ss reads them directly from the kernel and is faster with many connections. ss -tulpn gives the same view as the old netstat -tulpn.
How do I see the response headers of a website?
Run curl -I https://site to send a HEAD request, or curl -sv https://site -o /dev/null to see headers from a normal GET request.

Go deeper

ShareXLinkedInWhatsApp