appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Routing, NAT and DHCP

Lesson 3 of 412 minIntermediate

How packets find their way out, and how a home network shares one public address.

Routing

Each device has a routing table. For every packet it picks the most specific matching route. If none matches, it uses the default gateway, usually the router, which then does the same.

ip route
# default via 192.168.1.1 dev eth0
# 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.20
traceroute example.com     # list the routers on the path

NAT

Private addresses cannot be used on the internet. NAT (network address translation) on the router rewrites the source address of outgoing packets to its public address and remembers which port belongs to which internal device, so the replies come back to the right one.

  • It lets many devices share one public IPv4 address.
  • It is not a firewall, although by default it blocks unsolicited incoming connections. To reach a device inside, you configure port forwarding.
  • IPv6 has enough addresses that NAT is not needed. A firewall is.

DHCP

DHCP hands out network settings automatically. A new device broadcasts a request and receives an address, mask, default gateway and DNS servers for a limited lease time. Servers and printers often get a fixed address, either set by hand or with a DHCP reservation.

CarefulTwo devices with the same IP address cause intermittent problems. Keep your DHCP range separate from the addresses you assign by hand.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What does the default gateway do?
2. Which statement about NAT is true?
Hintip route

Key terms