Web servers and networking · Intermediate · 16 min
Trace the network path to a server with traceroute and mtr
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · traceroute 2.1.6 · mtr 0.95
You will trace the route to a server with UDP, ICMP and TCP probes, read an mtr report without being fooled by routers that rate-limit replies, and save a timestamped evidence file you can send to a hosting provider.
On this page
When a site is slow or unreachable from one place but fine from another, the problem is often somewhere between the two machines rather than on the server. traceroute shows the routers a packet crosses on its way to a server. mtr does the same thing continuously and adds loss and latency figures for every hop, which makes it the better tool for evidence.
Both tools are often misread. A hop full of * or showing 50% loss often means nothing at all. In this tutorial you will learn how the trace works, pick the probe type that gets through firewalls, read a report the way a network engineer does, and finish with a file you can attach to a support ticket.
The examples trace to 1.1.1.1, a public anycast DNS resolver: many sites around the world answer for the same address, so your nearest one replies. Replace it with your own server's address when you diagnose a real problem. Your hop list will differ from the samples here, because it depends on where you run the commands.
Step 1 · Install traceroute and mtr
Ubuntu 26.04 ships both tools in its archive. mtr-tiny is the build without the graphical interface, which is what you want on a server.
sudo apt update
sudo apt install -y traceroute mtr-tiny
mkdir -p ~/nettrace-demoThe ~/nettrace-demo folder holds the outputs you save along the way.
Check it worked
traceroute --version
mtr --versionYou see something like Modern traceroute for Linux, version 2.1.6 and mtr 0.95.
Step 2 · Understand what a trace measures
Every IP packet carries a time to live (TTL) field. Each router that forwards the packet lowers the TTL by one. A router that brings it to zero drops the packet and sends an ICMP "time exceeded" message back to the sender, and that message comes from the router's own address.
traceroute uses this on purpose. It sends probes with TTL 1, then 2, then 3, and so on. Each "time exceeded" reply reveals one router and how long the round trip to it took. When a probe finally reaches the server, the server answers in its own way and the trace ends.
Two things follow from this, and they explain most confusing traces:
- A hop's time is the round trip to that router and back, including the time the router takes to build a reply. Routers forward traffic in hardware but generate ICMP replies in software, at low priority.
- The reply comes back by whatever path the network chooses. It is not guaranteed to retrace the forward path.
Run a first trace with numeric output (-n, no reverse DNS lookups), one probe per hop (-q 1), a two-second wait (-w 2) and a 20-hop limit (-m 20):
traceroute -n -q 1 -w 2 -m 20 1.1.1.1 2>&1 | tee ~/nettrace-demo/udp.txttraceroute prints its header line on standard error, so 2>&1 keeps it in the saved file. The output looks something like this:
traceroute to 1.1.1.1 (1.1.1.1), 20 hops max, 60 byte packets
1 192.168.1.1 1.204 ms
2 10.20.0.1 8.917 ms
3 *
4 198.51.100.3 14.862 ms
5 1.1.1.1 15.311 msEach line is a hop number, the address that replied and the round-trip time. A * means no reply arrived within the wait time.
Check it worked
grep '^traceroute to 1.1.1.1' ~/nettrace-demo/udp.txt
grep -E '^ *1 ' ~/nettrace-demo/udp.txtThe first line is the header. The second is hop 1, usually your router or your server's default gateway (ip route shows it as default via ...).
Step 3 · Choose a probe that gets through
traceroute can send three kinds of probe. Routers along the path treat time-exceeded the same way for all of them, but firewalls in front of the destination do not.
- UDP (the default) sends datagrams to high, unlikely ports starting at 33434. It needs no special privileges. Many firewalls drop these, so the last hops often show
*. - ICMP (
-I) sends echo requests, likeping. Useful when UDP is dropped but ping works. - TCP (
-T) sends a SYN to one fixed port, as if opening a connection. With-p 443the probe looks like the start of an HTTPS connection, which any web server's firewall must let through.
ICMP and TCP probes use raw sockets, so run them with sudo:
sudo traceroute -I -n -q 1 -w 2 -m 20 1.1.1.1 2>&1 | tee ~/nettrace-demo/icmp.txt
sudo traceroute -T -p 443 -n -q 1 -w 2 -m 20 1.1.1.1 2>&1 | tee ~/nettrace-demo/tcp443.txtWhen you diagnose a website, the TCP trace to the port the site uses is the one that matters. It follows the same rules as your visitors' traffic, including policy routing and load balancers that pick a path per port.
A few markers can appear after a time: !H (host unreachable), !N (network unreachable) and !X (communication administratively prohibited, usually a firewall rejecting the probe). These are real answers from a router, unlike *.
Check it worked
Compare the last line of each file:
tail -n 1 ~/nettrace-demo/udp.txt ~/nettrace-demo/icmp.txt ~/nettrace-demo/tcp443.txtIf the TCP trace ends at the destination address while the UDP trace ends in *, a firewall near the server drops UDP probes and nothing is wrong with the path. If all three stop at the same hop, look closer at that hop.
Step 4 · Get loss and latency per hop with mtr
A single trace is one sample. mtr sends probes to every hop again and again, then summarises. Report mode (-r) runs a fixed number of cycles (-c) and prints a table; -w stops it cutting long hostnames.
mtr -r -w -n -c 20 1.1.1.1 | tee ~/nettrace-demo/mtr-icmp.txtmtr uses ICMP by default. For a web server, also run it over TCP to the real port:
sudo mtr -r -w -n -T -P 443 -c 20 1.1.1.1 | tee ~/nettrace-demo/mtr-tcp443.txtEach run takes about 20 seconds, one cycle per second. The report looks something like this:
Start: 2026-11-26T09:14:02+0000
HOST: web-01 Loss% Snt Last Avg Best Wrst StDev
1.|-- 192.168.1.1 0.0% 20 1.1 1.3 0.9 2.4 0.3
2.|-- 10.20.0.1 0.0% 20 9.4 9.9 8.7 14.2 1.1
3.|-- 203.0.113.9 45.0% 20 13.8 14.1 13.2 16.0 0.7
4.|-- 198.51.100.3 0.0% 20 14.6 15.0 14.1 17.3 0.8
5.|-- 1.1.1.1 0.0% 20 15.2 15.3 14.6 16.9 0.5The columns are: Loss% (share of probes with no reply), Snt (probes sent), Last (latest round trip in ms), Avg, Best and Wrst (average, lowest and highest), and StDev (how much the times vary; high values mean jitter). A line of ??? is a hop that never replied.
Check it worked
grep 'Loss%' ~/nettrace-demo/mtr-icmp.txt ~/nettrace-demo/mtr-tcp443.txtBoth files have the header row. Read Snt on the last line: it is 20 when every cycle completed.
Step 5 · Tell real loss from a router that rate-limits
This is where most reports to hosting providers go wrong. In the sample above, hop 3 shows 45% loss, yet hops 4 and 5 show 0%. Traffic clearly passes through hop 3 without loss, or the later hops could not answer every probe. What hop 3 loses is its own replies: many routers cap how many ICMP messages they generate per second, to protect their processors. Your traffic is not affected.
Use these rules, in this order:
- Read the last line first. If the destination shows 0% loss and a normal
Avg, the path is healthy, whatever the middle looks like. - Real loss starts at one hop and carries on, at a similar rate or higher, to every hop after it and to the destination.
- A latency jump that stays high for every later hop marks a slow link, often a long physical distance (an undersea cable) or a congested link. A jump at one hop only, with later hops back to normal, is that router's slow reply.
- Loss at the very last hop only, over ICMP, can be the server rate-limiting pings. Confirm with the TCP report on the service port before you blame anyone.
If you are in Africa, expect some routes to leave the continent and come back: traffic between two local networks that do not peer at a local exchange point can travel through Europe, which shows up as one hop where Avg jumps by 80 ms or more. That is a routing fact to mention to your provider, not loss. Mobile data networks also tend to hide hops behind carrier NAT and filter ICMP, so traces over a prepaid SIM or a phone hotspot often show many ??? lines in a row. Run the evidence trace from a wired connection or a server when you can.
Check it worked
Look at the last line of your TCP report:
tail -n 1 ~/nettrace-demo/mtr-tcp443.txtWrite down the destination's Loss% and Avg. Then find any middle hop with loss above 0% and check whether the hops after it also show loss. If they do not, you have found a rate-limiting router, not a fault.
Step 6 · Trace the return path too
Your trace only shows the forward path. Replies can come back through different networks, and a problem on the return path shows up in your report as loss or delay at the hop where the paths split, even though that hop is fine.
To see the return path, run mtr on the server, aimed at the public address of the machine you ran the first trace from. Your router's admin page shows that address; 203.0.113.10 below is a documentation address, so replace it.
# On the server: trace back to your office or home (replace the address)
sudo mtr -r -w -n -T -P 22 -c 20 203.0.113.10Use a TCP port that your side answers on, such as 22 if you run SSH, or the default ICMP probes if your router replies to ping. Many home routers answer neither, and the last hop then shows ???; the hops before it still tell you which networks the return traffic crosses.
Check it worked
Compare the network names or address ranges in both reports. If the forward and return reports cross different networks, mention both when you report a problem, because the fault may sit on either side. If you have no access to the server, ask the provider to run this trace for you, as in the next step.
Step 7 · Save evidence for your hosting provider
A good network report lets the provider's engineers find the fault without asking you for anything. Collect the time in UTC, where you ran the trace from, what you traced and the same trace over ICMP and TCP, with hostnames (-b shows names and addresses together; router names often say the city and the network). Use more cycles than before, so short bursts of loss show up.
TARGET=1.1.1.1
PORT=443
OUT=~/nettrace-demo/report-$(date -u +%Y%m%dT%H%M%SZ).txt
{
echo "Network report, generated $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "Source host: $(hostname)"
echo "Target: $TARGET port $PORT"
echo
echo "== mtr ICMP, 50 cycles =="
mtr -r -w -b -c 50 "$TARGET"
echo
echo "== mtr TCP $PORT, 50 cycles =="
sudo mtr -r -w -b -T -P "$PORT" -c 50 "$TARGET"
} | tee "$OUT"
echo "Saved $OUT"Replace 1.1.1.1 and 443 with your server's address and service port. The script takes under two minutes. Run it while the problem is happening, and once more when things are normal for comparison.
In the ticket, write, in plain sentences:
- What fails, from where, and since when (for example "HTTPS to 198.51.100.7 times out from our Lagos office since 08:40 UTC; fine from London").
- Your public source address, so they can trace back to you. Do not post it in a public forum.
- The hop where loss or latency starts and continues, quoted from the report.
- That you checked over TCP on the service port, so they do not reply "ICMP is rate-limited".
- A request for a trace from their side back to your address.
Attach the saved file rather than pasting a screenshot: engineers search and compare text.
Check it worked
ls ~/nettrace-demo/report-*.txt
grep -c 'Loss%' ~/nettrace-demo/report-*.txtOne report file is listed, and the count is 2: one table for ICMP and one for TCP.
When you have sent the report, remove the demo folder with rm -rf ~/nettrace-demo. Keep traceroute and mtr-tiny installed for next time, or remove them with sudo apt remove traceroute mtr-tiny.
Next steps
- See the local side of the path, your addresses and default route, in
/tutorials/see-addresses-and-routes-with-the-ip-command. - When the path is clean but the site is still slow, time each phase of the request with
/tutorials/debug-a-slow-or-failing-website-with-curl. - Follow a request from DNS to your web server in
/tutorials/how-a-request-reaches-your-server.
Related tutorials
- Write Nginx location blocks that match what you expectYou will build a practice Nginx 1.30 server where every location block labels its responses, predict which block answers each of twelve URLs, check your answers with curl, and fix the alias, regex-order and proxy_pass mistakes that catch most people out.
- Write a server firewall with nftablesYou will write one /etc/nftables.conf with a default-drop input chain, rate-limited SSH, named address sets, counters and logging, and load it over SSH behind a timer that undoes it if you lose your connection.
- Watch a TCP connection open and close with tcpdumpYou will capture a curl request to a local web server with tcpdump on Ubuntu 26.04, read its handshake, data and teardown line by line, see the reset a closed port sends, and save, filter and rotate captures as pcap files.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials