The Academy

Loading the search index…

Searches the academy on this device only.

Ports, TCP and UDP, ping and traceroute

Understand how one address serves many programs through ports, why TCP and UDP exist, and how ping and traceroute test a connection, so you can read a ping result with confidence.

30 minelementaryUbuntu/LinuxWindowsPractical task needs a laptop or desktop

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

By the end of this lesson you will be able to

  • Explain with an analogy how ports let one device run many network programs at once.
  • Name three well-known port numbers and what they are used for.
  • Contrast TCP and UDP and choose which suits a file download and which a video call.
  • Run ping on your own computer and read the replies, loss and times.
  • Describe what traceroute shows and why some lines may be blank.

Your laptop may have a browser open, a chat app, an email program and a software update all running at once, yet it has only one IP address. How does each packet find the right program? And when something is wrong, how do you test whether the other end is even reachable? Ports, the TCP and UDP rules and the ping tool answer these questions.

Ports: doors in a building

The IP address gets a packet to the right device, like the street address of a large block of flats. But the flats inside have different residents. A network port is a number from 0 to 65,535 that picks the program on the device that should receive the packet, like a flat number.

A server listens on a well-known port for its job. A web server using HTTPS listens on port 443, so your browser sends its request to the server's address, port 443. Your own computer also uses a port for each conversation, picked at random, so that replies come back to the right program. This is why your browser and your chat app do not receive each other's data.

Some well-known ports
PortUsed forProtocol name
53Looking up namesDNS
80Web pages without encryptionHTTP
443Web pages with encryptionHTTPS
22Secure remote command lineSSH
587Sending email from a mail programSMTP submission
Diagram

One address, many ports: the port number sends each packet to the right program.

same addressport 443port 587port 53LaptopServer 198.51.100.40Web programMail programName program
One address, many ports: the port number sends each packet to the right program.
Read this figure as text

A network diagram of a server with three labelled ports leading to a web program, a mail program and a name program.

A laptop on the left sends three packets to one server at 198.51.100.40 (a made-up address). The first packet is marked port 443 and arrives at the web program (HTTPS). The second is marked port 587 and arrives at the mail program. The third is marked port 53 and arrives at the name-lookup program (DNS). The address is the same for all three; the port number decides which program receives each one.

TCP and UDP: careful or fast

Two protocols sit on top of IP and decide how a conversation behaves. TCP is the careful one. It first sets up a connection with a quick greeting, numbers every packet, and checks that each arrives. If one is lost it is sent again, and the pieces are put in the right order before the program sees them. This is like a registered delivery with a signature.

UDP is the fast one. It just sends packets with no greeting, no checking and no resending, like throwing postcards over a fence. That sounds careless but is ideal when speed matters more than perfection. In a video call, a late packet is useless: it is better to skip a tiny part of the sound than to wait for it.

Diagram

TCP checks everything; UDP skips the checks to save time.

TCPCareful and reliable
  • Sets up a connection first
  • Checks and resends lost packets
  • Keeps packets in order
  • Used for web, email, downloads

Every piece must arrive.

UDPFast and light
  • No connection set-up
  • No checking or resending
  • Some packets may be lost
  • Used for calls, games, streams

Speed matters more.

TCP checks everything; UDP skips the checks to save time.
Read this figure as text

A two-column comparison of TCP and UDP with examples of each.

TCP: sets up a connection first; numbers packets and checks that each arrives; resends lost packets; keeps the packets in order; slightly slower. Used for web pages, email and file downloads, where every piece must arrive. UDP: no connection set-up; no checking or resending; packets may be lost or out of order; very fast and light. Used for video calls, online games, live streams and simple DNS questions, where speed matters more than a perfect copy.

Ping: are you there?

Ping sends a tiny test message to another computer and waits for a reply, like calling out in a dark room and listening for an answer. It tells you three things: whether the other end is reachable, how long the round trip took (the Round-trip time, in milliseconds), and whether any messages were lost.

Run a ping

Replace 192.168.1.1 with your own router address if it is different (the previous lesson showed how to find it).

On Ubuntu, ping keeps going until you stop it, so we add -c 4, which means 'count 4': send four messages, then stop and summarise. 192.168.1.1 is the address to test.

Terminal (Linux) · you can run this on your own computer
ping -c 4 192.168.1.1
Send four test messages to the router
Simulated interface: not a real screenshot

A simulated terminal showing four successful ping replies.

Terminal (simulated output)
  1. Marker 1: Command: four test messages
  2. Marker 2: One reply and its round-trip time
  3. Marker 3: Summary: nothing lost
A simulated terminal showing four successful ping replies.
Read this figure as text

A simulated Ubuntu terminal running ping -c 4 and showing four replies and a summary.

A simulated terminal. Marker 1 is the command ping -c 4 192.168.1.1. Four reply lines follow, each saying 64 bytes from 192.168.1.1 with a sequence number and a time in milliseconds, between 2 and 3 ms (marker 2: the round-trip time). A summary then says 4 packets transmitted, 4 received, 0% packet loss (marker 3). The last line gives the minimum, average and maximum times. All values are made up. Zero loss and low times are healthy.

Reading ping results
What you seeWhat it usually means
Replies with small times (under about 20 ms to your router)A healthy local connection
Replies for the router but not for example.orgYour home network is fine; the problem is beyond it, or with DNS if the name will not resolve
Request timed out. (Windows) or no replies (Linux)No answer came back: the device is off, a firewall is blocking ping, or the path is broken
Destination host unreachableYour computer or a router on the way knows there is no route to that address
Some replies lost (for example 25% loss)An unreliable link, often a weak Wi-Fi signal

Traceroute: the route taken

Traceroute (named tracert on Windows) shows the path a packet takes. It works by sending messages that are allowed to travel only one Hop, then two hops, then three, and noting which router sends back a note each time. Each line of the result is one router on the route, with the times for three tries. A line of stars means that router did not answer, which is common and not always a fault: some routers are set to stay quiet.

Simulated interface: not a real screenshot

A simulated tracert result; every address is made up.

Command Prompt (simulated output)
  1. Marker 1: Hop 1: your own router
  2. Marker 2: Hop 2: the provider's first router
  3. Marker 3: A quiet router; not always a fault
A simulated tracert result; every address is made up.
Read this figure as text

A simulated Windows command window showing a tracert result with four hops to a made-up address.

A simulated command window running tracert 198.51.100.40, a made-up address. Hop 1 is 192.168.1.1 (marker 1, your own router), taking 2 ms. Hop 2 is 203.0.113.1 (marker 2, the first router at the provider), taking 9 ms. Hop 3 shows three stars and the message Request timed out (marker 3: that router did not answer, which is not always a fault). Hop 4 is the destination 198.51.100.40, taking 31 ms. Times usually rise as the distance grows.

You will use these tools again in the lesson on diagnostic tools. For now, the idea is enough: ping asks whether something is reachable, and traceroute shows where along the route the answer stops or slows down.

Common mistakes

  • ✖ Instead of: Concluding that a site is down because ping shows 'Request timed out'.

    ✔ Do this: Many servers and routers are set to ignore ping. Try opening the site in a browser too before deciding.

  • ✖ Instead of: Using ping or traceroute on computers you do not own to see if they are 'alive'.

    ✔ Do this: Test only your own devices and well-known example sites. Probing other people's systems is not appropriate.

  • ✖ Instead of: Thinking a high ping time to a distant site means your internet is slow.

    ✔ Do this: Time grows with distance. Compare with your router first: a small time there and a larger one far away is normal.

If something goes wrong

Ping on Ubuntu never stops.
Press Ctrl and C together to stop it, and use -c 4 next time to send just four.
Ping works with a number but not with a name.
That is a DNS problem. Revisit the DNS section of the previous lesson and check which DNS server your computer uses.
traceroute is not found on Ubuntu.
It is not installed by default. The command tracepath example.org does a similar job and is included. Installing software comes later in the academy.

Key terms

Network port
A numbered door on a computer that tells it which program should receive incoming data.
Round-trip time
How long a message takes to reach another computer and for the reply to come back.
Traceroute
A tool that lists the routers a packet passes through on its way to a destination.

Practise it for real

Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.

Guided exerciseNeeds a laptop or desktop

Ping your router and a website

On your real computer, open the Terminal (Ubuntu) or PowerShell (Windows). Ping your router's address. Then ping example.org. Write down the average time for each and the percentage of packets lost. Do not ping any other address.

You have succeeded when:
Independent challenge

Challenge: choose TCP or UDP

For each activity, say whether TCP or UDP is the better fit and give one reason: (a) downloading a PDF; (b) a live video call with a relative; (c) sending an email; (d) an online game where positions update many times a second. Then say which port a normal HTTPS website uses.

You have succeeded when:

Knowledge check

6 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.

  1. Question 1.What is the job of a port number?
  2. Question 2.Match each port to its normal use.
  3. Question 3.UDP checks that every packet arrives and resends any that are lost.
  4. Question 4.Joseph pings his router and gets four replies at about 3 ms, then pings example.org and sees only 'Ping request could not find host example.org'.What does this suggest?
  5. Question 5.A ping to the router reports 4 sent, 3 received, 25% loss. What is the most likely cause at home?
  6. Question 6.Put the typical hops of a traceroute in order from your laptop.
    1. Your home router
    2. The destination server
    3. The provider's first router
    4. Routers across the internet

Summary

  • A port number chooses the program on a device; well-known ports include 443 for HTTPS and 53 for DNS.
  • TCP is careful and reliable; UDP is quick and tolerant of loss.
  • Ping tests reachability, loss and round-trip time.
  • Traceroute lists the routers on the way; a line of stars is not always a fault.

Checklist: can you do these?

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

Related lessons

References and further reading

Official sources for details that can change between versions.

On this page