The answersDownload the PDF
Worksheet

A12.6 DHCP, NAT and port forwarding

Networks and the web · A level · AQA 7517 4.9.4.7 · about 30 min

BugBotLab
NameClassDate

What this lesson is about

How a device gets its address, and how a router shares one public address with a whole network.

Questions 6 marks in all

  1. [1 mark]Put the DHCP messages in the order they are sent.

    Number the lines 1 to 4 to put them in the right order.

    1. Offer
    2. Acknowledge
    3. Discover
    4. Request
  2. [1 mark]Which settings does a DHCP server typically give a device? Choose all that apply.

    Tick every answer that is true.

    1. AIP address
    2. BSubnet mask
    3. CDefault gateway
    4. DDNS server address
    5. EMAC address
  3. [1 mark]When a packet leaves a home network through a router using NAT, what does the router change?

    1. AThe private source IP address (and usually the source port) to its public address and a port of its own, recording it in a table
    2. BThe destination IP address to a private address
    3. CThe MAC address of the destination server
    4. DNothing: NAT only affects incoming packets
  4. [1 mark]Why is NAT used? Choose all that apply.

    Tick every answer that is true.

    1. AMany devices can share one public IPv4 address
    2. BPrivate addresses are hidden from the Internet
    3. CIt speeds up DNS lookups
    4. DIt gives every device a globally unique address
  5. [1 mark]A student runs a game server at 192.168.1.40 on their home network. What lets friends on the Internet connect to it?

    1. AA port forwarding rule mapping a public port on the router to 192.168.1.40 and the server's port
    2. BGiving the server a DHCP lease
    3. CTurning off the router's DNS
    4. DUsing a thin client
  6. [1 mark]What does this program print?

    table = {}
    next_port = 50000
    for socket in ['192.168.1.5:3000', '192.168.1.6:3000', '192.168.1.5:3000']:
        if socket not in table:
            table[socket] = next_port
            next_port = next_port + 1
        print(socket, '->', table[socket])

The task: get an address

The Router on this mat is a DHCP server that talks over the radio in a simplified form of DORA. Messages are words separated by single spaces. 1. Send DISCOVER. 2. The Router replies OFFER <address> <mask> <gateway> <lease seconds>. Print offered <address>. 3. Send REQUEST <address>, using the address from the offer. 4. The Router replies ACK <address> <mask> <gateway> <lease seconds>. From the ACK, print address: <address>, then gateway: <gateway>, then lease: <hours> hours, where hours is the lease in seconds divided by 3600 as a whole number. Check messages() every 0.1 s while you wait for each reply. Read every value from the replies; the robot does not drive.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

send("DISCOVER")
wait(1)
print(messages())

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/a12-6-dhcp-nat-and-port-forwarding/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add lease times to the DHCP cell: give each lease an expiry time and return expired addresses to the pool.
  2. Send the same outgoing socket twice in the NAT task. Check it keeps its public port.
  3. Why does NAT get in the way of two home computers trying to connect directly to each other, peer to peer?