Learn / Stage 3: Networking and CCNA / Lesson 3.10

$ lesson 3.10 --track ccna --domain ip-services

DHCP, DNS and NAT/PAT: Addresses, Names and the Internet Edge

Three services every network quietly depends on. DHCP gives devices their addresses, DNS turns names into addresses, and NAT lets a whole office share one public IP. Learn how each works, how to configure them on a Cisco router, and how attackers abuse DHCP and DNS.

  • Stage 3 Networking and CCNA
  • Level Intermediate
  • 65 min
  • 4 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Describe the DHCP DORA exchange and why relay is needed
  • Configure a router as DHCP server, relay agent and client
  • Explain DNS record types and why DNS uses both UDP and TCP
  • Use the four NAT address terms correctly
  • Configure and verify static NAT and PAT
3.10.01

DHCP: how a PC gets its address

Typing addresses into every PC does not scale and invites mistakes. DHCP hands out the address, mask, default gateway, DNS servers and a lease time. The client uses UDP port 68 and the server UDP port 67.

The DORA exchange

Use Next or the arrow keys.

    Discover

    The PC has no address yet, so it broadcasts: source 0.0.0.0, destination 255.255.255.255. "Is there a DHCP server out there?"

    Offer

    A server replies with an offer: "you can have 192.168.10.100/24, gateway 192.168.10.1, DNS 10.0.0.10, for one day".

    Request

    The PC broadcasts that it accepts this server's offer. It is a broadcast so any other servers that made offers know they were not picked.

    Acknowledge

    The server confirms. The PC configures itself and renews part way through the lease (by default at half the lease time) instead of repeating the whole process.

    Broadcasts do not cross routers, so a server in the data centre never hears a Discover from a branch LAN. The fix is a relay agent: ip helper-address 10.0.0.10 on the router interface facing the clients turns the broadcast into a unicast to the server, and includes the interface address (192.168.10.1) so the server knows which pool to use. A router can also be a DHCP server itself, or a DHCP client with ip address dhcp, which is common on an internet facing interface.

    3.10.02

    DNS: names to addresses

    People type names; packets need addresses. DNS resolves one to the other. Your PC asks its configured resolver, which finds the answer (asking other servers if needed) and caches it.

    Common DNS records
    RecordHolds
    AAn IPv4 address for a name
    AAAAAn IPv6 address for a name
    CNAMEAn alias pointing to another name
    MXThe mail server for a domain
    PTRReverse lookup: address to name
    NSWhich servers are authoritative for a zone

    DNS mostly uses UDP port 53, and TCP port 53 for large answers and zone transfers, so "DNS is only UDP" is wrong. On a router, ip name-server sets the resolver it uses itself, and no ip domain-lookup (lesson 3.3) stops it trying to resolve every mistyped command.

    3.10.03

    NAT and PAT

    Private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) are not routed on the internet. NAT on the edge router rewrites them to public addresses on the way out and back again for the replies.

    PAT: PC1's private source address and port are swapped for R1's public address on the way out, and swapped back for the replyPC1inside local 192.168.10.100R1 (PAT)inside global 203.0.113.2Web serveroutside global 198.51.100.10src .10.100:49152src 203.0.113.2:49152R1 rewrites the source on the way out and remembers the mapping so it can reverse it for the reply
    With PAT, many inside hosts share one public address and are told apart by port numbers in the translation table.
    NAT address terms
    TermMeaningIn the lab
    Inside localThe real, usually private, address of the inside host192.168.10.100
    Inside globalThe public address that represents the inside host203.0.113.2
    Outside globalThe real address of the remote host198.51.100.10
    Outside localHow the remote host appears from inside; usually the same as outside global198.51.100.10
    NAT types
    TypeMappingUse
    Static NATOne inside address to one public address, permanentlyPublishing a server
    Dynamic NATInside hosts borrow addresses from a pool, one to one while in useRare today; runs out when the pool is used up
    PAT (overload)Many inside hosts share one public address, told apart by portAlmost every home and office
    R1(config)#access-list 1 permit 192.168.10.0 0.0.0.255
    R1(config)#ip nat inside source list 1 interface GigabitEthernet0/0/2 overload
    R1(config)#interface GigabitEthernet0/0/0
    R1(config-if)#ip nat inside
    R1(config)#interface GigabitEthernet0/0/2
    R1(config-if)#ip nat outside
    R1(config)#ip nat inside source static 10.0.0.10 203.0.113.3

    NAT hides internal addresses, but it is not a security policy: a static mapping publishes the server to the whole internet. Use an ACL or firewall to allow only the ports you mean to publish, and keep that server patched and separated. Also note that clear ip nat translation * drops every active session through the router.

    3.10.04

    Practise on R1

    R1's interfaces are addressed. The DHCP clients and the internet traffic in this console are modelled for you so the show commands have something to display.

    console: R1 (R1 DHCP and NAT console)

    Missions 0/12

      Simplified IOS simulator in your browser. It teaches the commands; Packet Tracer and real gear have many more.

      Flashcards: do you remember?

      Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

      Quick quiz

      Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

      Q1Why does a PC in another subnet not reach a central DHCP server by default?

      Q2Which address is the inside global?

      Q3Many hosts share one public IP. Which NAT type?

      Q4Which record maps a name to an IPv6 address?

      Q5What does a DHCP starvation attack do?

      Q6A static NAT mapping publishes an internal server. What should accompany it?

      0 / 6

      Hands-on lab

      Cisco Packet Tracer lab55 minutessimulated network

      Packet Tracer lab 3.10: central DHCP with relay, DNS, and PAT to the internet

      You need: Cisco Packet Tracer (free with a Cisco Networking Academy account; version 9.0.1 was the current download on the NetAcad Resource Hub when this lesson was written). Devices: 2 x ISR4331 (R1 and ISP), 2 x 2960, 2 x PC-PT, 2 x Server-PT. 203.0.113.0/24 and 198.51.100.0/24 are documentation ranges (RFC 5737) standing in for public space.

      Topology and addressing

      Lab 3.10 topology: PCs on 192.168.10.0/24 get addresses from a central server through R1, and reach a fake internet through PAT on R1 Gi0/0/2 (203.0.113.2/29)Gi0/0/0 .1Gi0/0/1 10.0.0.1Gi0/0/2 .2Gi0/0/0 .1Gi0/0/1 .1SW1PC1, PC2DHCP clientsR1ISR4331SW-SServer-DHCP-DNS10.0.0.10ISPISR4331Web-Internet198.51.100.10
      PCs on SW1 to R1 Gi0/0/0. R1 Gi0/0/1 to SW-S and Server-DHCP-DNS. R1 Gi0/0/2 to ISP Gi0/0/0; ISP Gi0/0/1 to Web-Internet.
      Addressing table
      DeviceInterfaceIPv4 address / prefixDefault gateway or note
      R1Gi0/0/0192.168.10.1/24ip nat inside, ip helper-address 10.0.0.10
      R1Gi0/0/110.0.0.1/24ip nat inside
      R1Gi0/0/2203.0.113.2/29ip nat outside
      ISPGi0/0/0 / Gi0/0/1203.0.113.1/29 / 198.51.100.1/24no route to 192.168.10.0 needed
      Server-DHCP-DNSFa010.0.0.10/24gateway 10.0.0.1
      Web-InternetFa0198.51.100.10/24gateway 198.51.100.1, HTTP on
      1. Server services

        On Server-DHCP-DNS, open Services, DHCP: create a pool for 192.168.10.0/24 starting at 192.168.10.100 with default gateway 192.168.10.1 and DNS server 10.0.0.10, and turn the service on. Then Services, DNS: turn it on and add an A record web.cwm.lab pointing to 198.51.100.10.

      2. Relay

        R1(config)#interface GigabitEthernet0/0/0
        R1(config-if)#ip helper-address 10.0.0.10

        Set both PCs to DHCP in their IP Configuration and confirm they receive .100 and up.

      3. Optional: router as the DHCP server instead

        R1(config)#ip dhcp excluded-address 192.168.10.1 192.168.10.99
        R1(config)#ip dhcp pool LAN10
        R1(dhcp-config)# network 192.168.10.0 255.255.255.0
        R1(dhcp-config)# default-router 192.168.10.1
        R1(dhcp-config)# dns-server 10.0.0.10

        Remove the helper address if you try this, or you will have two servers answering.

      4. PAT for the LAN

        R1(config)#access-list 1 permit 192.168.10.0 0.0.0.255
        R1(config)#ip nat inside source list 1 interface GigabitEthernet0/0/2 overload
        R1(config)#interface GigabitEthernet0/0/0
        R1(config-if)#ip nat inside
        R1(config)#interface GigabitEthernet0/0/1
        R1(config-if)#ip nat inside
        R1(config)#interface GigabitEthernet0/0/2
        R1(config-if)#ip nat outside
        R1(config)#ip route 0.0.0.0 0.0.0.0 203.0.113.1

        The ISP has no route back to 192.168.10.0/24, and needs none. That is the point of NAT.

      5. Static NAT for the DNS server (demo only)

        R1(config)#ip nat inside source static 10.0.0.10 203.0.113.3

        From Web-Internet, ping 203.0.113.3 or run nslookup web.cwm.lab 203.0.113.3. In real life publish only the ports you need and filter with an ACL.

      6. Dynamic NAT with a pool (in a copy of the file)

        R1(config)#no ip nat inside source list 1 interface GigabitEthernet0/0/2 overload
        R1(config)#ip nat pool PUBLIC 203.0.113.4 203.0.113.6 netmask 255.255.255.248
        R1(config)#ip nat inside source list 1 pool PUBLIC

        With three pool addresses, a fourth inside host cannot get out until a translation times out. Adding overload to the pool line turns it into PAT over the pool.

      7. Test and verify

        PC1>ipconfig /all
        R1#show ip nat translations
        R1#show ip nat statistics
        R1#show ip dhcp binding
        R1#show ip dhcp pool

        From PC1, browse http://web.cwm.lab. Briefly try debug ip nat, then turn it off with undebug all.

      You are done when: PC1 ipconfig /all shows an address from .100 up, gateway 192.168.10.1 and DNS 10.0.0.10. show ip nat translations lists entries with inside global 203.0.113.2 and different ports for different inside locals, plus the static entry for 10.0.0.10. PC1 opens http://web.cwm.lab.

      Packet Tracer limits and notes

      • Server-PT DHCP and DNS services work for simple pools and A records. How Packet Tracer matches a Server-PT pool to the relay address in every version is UNVERIFIED; if a PC gets no lease, check that the pool's gateway sits in the PC's subnet.
      • Packet Tracer's show ip nat statistics output is shorter than real IOS.
      • Which DNS record types beyond A and CNAME Packet Tracer's DNS server supports is UNVERIFIED for every version.
      • Packet Tracer simulates a subset of IOS. If a command here is rejected in your version, note it, skip that step and carry on; the concept still applies to real Cisco gear.

      Download the lab checklist (.txt) Print it or keep it open beside Packet Tracer.

      Key takeaways

      • DHCP is DORA over UDP 67 and 68; relay it across routers with ip helper-address.
      • DNS uses UDP 53 and TCP 53; whoever controls your DNS controls where names go.
      • Know the four NAT terms: inside local, inside global, outside local, outside global.
      • PAT (overload) lets a whole site share one public address.
      • NAT is not a firewall; filter what you publish.

      Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.