The Academy

Loading the search index…

Searches the academy on this device only.

DHCP, DNS and the default gateway

Find out how a device gets its address automatically (DHCP), how a name like example.org becomes a number (DNS), and how the default gateway is the door out of your home network.

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 what DHCP does and what a lease is.
  • Describe the steps of a DNS lookup from the browser to the answer.
  • Say what the default gateway is and why every device needs one.
  • Find the gateway and DNS server of your own computer on Ubuntu or Windows.
  • Match a symptom, such as a site not found, to a DHCP, DNS or gateway cause.

Three quiet helpers make an ordinary web visit possible, and when any one fails the symptoms look similar: the page will not load. DHCP gives your device an address, DNS turns the name you typed into an address, and the default gateway is the door out of your home. When you can tell them apart, you can say which one is broken instead of just saying that the internet is down.

DHCP: addresses handed out automatically

Last lesson you saw that every device needs an IP address. Typing one in by hand for every phone and laptop would be tiring and easy to get wrong. Instead, your router runs a service called DHCP (Dynamic Host Configuration Protocol). A device that joins the network simply asks, and DHCP replies with an address and the other settings it needs.

Think of a cloakroom at a hall. You hand in nothing and are given a numbered ticket for the evening. When you leave, the ticket can be given to someone else. In the same way DHCP lends an address for a limited time. That loan is called a DHCP lease. Before it ends, the device quietly asks to renew it. If a device leaves and never renews, its address goes back into the pool.

A DHCP reply contains four things, all in one go: an IP address for the device, the subnet mask, the address of the default gateway and the address of a DNS server.

Diagram

A new device asks for settings and the router's DHCP service lends it an address.

LaptopRouter (DHCP)1Is anyone handing out addresses? I needone2I can lend you 192.168.1.203Good, I would like to use 192.168.1.204Confirmed for 24 hours. Gateway andDNS: 192.168.1.1
A new device asks for settings and the router's DHCP service lends it an address.
Read this figure as text

A sequence diagram of a laptop and a router exchanging four DHCP messages.

Two actors: a laptop and the router, which runs the DHCP service. Message 1, laptop to router: Is there a DHCP service here? I need an address. Message 2, router to laptop: Yes. I can lend you 192.168.1.20. Message 3, laptop to router: Good, I would like to use 192.168.1.20. Message 4, router to laptop: Confirmed. It is yours for 24 hours, the gateway is 192.168.1.1 and the DNS server is 192.168.1.1. The 24 hours is a made-up example of a lease length.

The default gateway: the door out

Your device knows how to deliver data to its neighbours on the same subnet. For everything else, such as a website on the other side of the world, it needs help. It sends the packet to one trusted neighbour that knows the way out. That neighbour is the default gateway. In nearly every home it is the router, with an address like 192.168.1.1.

Diagram

Local traffic stays on the subnet; everything else goes to the default gateway.

Your subnet 192.168.1.xOutsidelocal1not local23Laptop192.168.1.20Printer192.168.1.30Gateway192.168.1.1Internet
Local traffic stays on the subnet; everything else goes to the default gateway.
Read this figure as text

A network diagram where a laptop talks to a printer directly and to the internet through the router.

A laptop at 192.168.1.20 and a printer at 192.168.1.30 are on the same subnet inside the home zone, and the router at 192.168.1.1 is also in the home zone. Step 1: the laptop sends a print job straight to the printer, because its address is on the same subnet. Step 2: the laptop sends a request for a website to the router, which is its default gateway, because the website is not on the subnet. Step 3: the router forwards the request out to the internet, shown as a cloud.

DNS: names into numbers

People remember names such as example.org. Packets need numbers. The Domain Name System (DNS) is the worldwide directory that turns one into the other, a bit like the contacts list on your phone: you choose Amina, and the phone dials the number. Without DNS you would have to type a number such as 198.51.100.40 for every site.

Your computer asks a DNS resolver, a server whose job is to find the answer. DHCP told your computer which resolver to use; at home it is usually your router, which passes questions on to the resolver run by your provider. If the resolver does not know, it asks other servers in turn: first one that knows the whole internet's top level, then the one responsible for .org, then the one responsible for example.org, which gives the final address.

Diagram

A DNS lookup: the resolver asks a chain of servers until one knows the address.

BrowserResolverRoot server.org serverexample.org server1Address of example.org?2Who knows .org?3Ask the .org server4Who knows example.org?5Ask the example.org server6Address of example.org?7198.51.100.408198.51.100.40
A DNS lookup: the resolver asks a chain of servers until one knows the address.
Read this figure as text

A sequence diagram of a browser, a resolver and three DNS servers answering a lookup for example.org.

Actors: browser, resolver, root server, .org server and example.org server. Message 1, browser to resolver: What is the address of example.org? Message 2, resolver to root server: Who knows about .org? Message 3, root server to resolver: Ask the .org server. Message 4, resolver to the .org server: Who knows example.org? Message 5, .org server to resolver: Ask the example.org server. Message 6, resolver to the example.org server: What is the address of example.org? Message 7, example.org server to resolver: It is 198.51.100.40. Message 8, resolver to browser: 198.51.100.40. The browser can now send its request to that address. The address is made up for the lesson.

This looks long but takes a few thousandths of a second, and the answer is remembered. A DNS cache stores recent answers on your computer, your router and the resolver, so the second visit to a site does not need the whole chain. Answers are kept for a time chosen by the site's owner and then dropped, so that a change of address eventually spreads everywhere.

Try it: step through a lookup

Choose a made-up domain and step through the questions and answers that turn it into an IP address.

Loading lab…

Find your own gateway and DNS server

Show the gateway and DNS server

The Terminal and Command Prompt were introduced in earlier modules. Type each command exactly as shown and press Enter.

ip route show default asks the system for its default route: the gateway that handles everything outside your subnet. resolvectl status shows the DNS servers in use. Both only display information.

Terminal (Linux) · you can run this on your own computer
ip route show default
resolvectl status
Show the default gateway, then the DNS settings (read-only)
Simulated interface: not a real screenshot

A simulated Ubuntu terminal showing a gateway and a DNS server.

Terminal (simulated output)
  1. Marker 1: Command: show the default route
  2. Marker 2: The default gateway
  3. Marker 3: Command: show DNS settings
  4. Marker 4: The DNS server in use
A simulated Ubuntu terminal showing a gateway and a DNS server.
Read this figure as text

A simulated terminal that runs ip route show default and resolvectl status and shows made-up output.

A simulated terminal in the home folder. Marker 1 is the command ip route show default. It prints: default via 192.168.1.1 dev wlp2s0 proto dhcp metric 600. Marker 2 points at 192.168.1.1, which is the default gateway. The word dhcp shows the setting came from DHCP. Marker 3 is resolvectl status. A line then reads Current DNS Server: 192.168.1.1, which is the resolver your computer asks (marker 4). All values are made up and yours will differ.

Which helper is failing? A guide to symptoms
SymptomLikely helperWhat it means
Address starts 169.254, connection limitedDHCPNo address was lent to the device
Can open a site by number but not by nameDNSNames are not being turned into numbers
Can reach the printer and the router but nothing outsideGateway or providerThe way out is closed or the provider's line is down

Common mistakes

  • ✖ Instead of: Saying “DNS is down” whenever a page will not load.

    ✔ Do this: Check first whether a number works and whether other devices work. DNS is only one of several causes: DHCP, the gateway and the provider line can also fail.

  • ✖ Instead of: Setting an address by hand without knowing the network's range.

    ✔ Do this: Leave DHCP on (Automatic) unless you have a clear reason. A hand-typed address can clash with another device.

  • ✖ Instead of: Thinking the gateway and the internet are the same thing.

    ✔ Do this: The gateway is only the nearest door out, usually the router. The internet lies beyond the provider's line.

If something goes wrong

The command resolvectl is not found.
Check you are on Ubuntu 24.04 and typed it exactly. As an alternative, cat /etc/resolv.conf shows a nameserver line; on Ubuntu it may show 127.0.0.53, which is a local helper that passes questions on.
ipconfig shows several adapters and I cannot tell which is mine.
Look for the one named Wi-Fi (or Ethernet if you use a cable) that has an IPv4 Address and a Default Gateway. Adapters marked Media disconnected are not in use.

Key terms

DHCP lease
The time for which a device may keep the address that DHCP gave it.
DNS resolver
The server that looks up a name for you and returns its IP address.
DNS cache
A short-term memory of recent DNS answers, which saves asking the same question again.

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

Read your own network settings

On your real computer, use the command for your system in the lesson to find your default gateway and your DNS server. Write down both, plus your IPv4 address. Then compare: is the gateway in the same subnet as your address (do the first three numbers match)? Is the gateway the same as the DNS server? Do not share these numbers online.

You have succeeded when:
Independent challenge

Challenge: DHCP, DNS or gateway?

For each case, decide whether DHCP, DNS or the gateway is the most likely cause and explain why in one sentence. (a) A laptop shows 169.254.12.7 and no sites load. (b) A browser says the site cannot be found, but a chat app on the same computer still works. (c) Everything on the home network works, including the printer, but no website opens on any device and the router's internet light is off.

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 does DHCP do?
  2. Question 2.DNS is needed because packets travel using numbers, while people prefer to type names.
  3. Question 3.Put these in the order they happen when you visit example.org for the first time.
    1. The browser sends its request to that address
    2. The resolver returns the IP address
    3. The browser asks the resolver for the address
    4. The resolver follows the chain of DNS servers
  4. Question 4.Fatuma's browser says it cannot find any website, but when she types the address 198.51.100.40 (a made-up address) into the browser, the page opens.Which helper is most likely failing?
  5. Question 5.Match each setting to its job.
  6. Question 6.Why is the second visit to a website often quicker to start than the first?

Summary

  • DHCP lends each device an address, mask, gateway and DNS server for a limited time called a lease.
  • The default gateway is the door out of your subnet, normally your router.
  • DNS turns names into addresses through a resolver that asks a chain of servers and caches answers.
  • Different symptoms point to different helpers: 169.254 means DHCP, names failing but numbers working means DNS.

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