Network Services - DHCP and DNS Configuration
In questa pagina 4
The program lists DHCP, DNS and firewall among the network elements configured in the laboratory (Emulating Networks with KatharàKatharà is a network emulator where every device is a Docker container joined to virtual collision domains; a lab is a folder with lab.conf (topology), one .startup file per machine and optional per-device folders; machines are configured with ifconfig, tested with ping and observed with tcpdump and Wireshark.Emulating Networks with Katharà →); the firewall part is in Firewall Configuration with iptables in KatharàLab 6 configures a packet-filter firewall on Linux with iptables (NetFilter): tables filter, nat, mangle and raw hold chains of rules, the first matching rule wins, otherwise the default policy applies; three experiences cover a firewall protecting a host (INPUT with DROP policy plus loopback, ping, SSH and ESTABLISHED,RELATED), a firewall on a LAN router (FORWARD) and NAT with SNAT and DNAT.Firewall Configuration with iptables in Katharà →. This note collects what must be known to configure and test the other two services. In the lab a DNS server is placed on a machine and queried with nslookup.
DHCP
Assigning address and netmask by hand to each host is inefficient and error-prone. BOOTP (deprecated) keeps a fixed table MAC IP, assigns the address only at boot and new hosts must be added by hand. DHCP (Dynamic Host Configuration Protocol) is dynamic: the address is lent (lease) for a limited time, also when the operating system is already running; hosts can outnumber the addresses (e.g. Wi-Fi); when all addresses are assigned, new requests are refused.
Protocol phases
DHCP uses UDP: server port 67, client port 68. Broadcast and UDP are needed because the client has no IP address and does not know the server, so it cannot open a TCP connection; the frame carrying the DISCOVER has destination MAC ff:ff:ff:ff:ff:ff. The two broadcasts are on different layers: for the network, all-ones MAC for the link.
- DHCPDISCOVER: the client broadcasts a message with its MAC and a random transaction ID; source IP , destination .
- DHCPOFFER: each DHCP server answers with its identifier, the proposed IP address and the lease time.
- DHCPREQUEST: the client accepts one offer, broadcasting a message containing the identifier of the chosen server (so the others know they were not chosen).
- DHCPACK: the server assigns the address and sends everything needed to configure the interface: netmask, default gateway, DNS server.
- DHCPRELEASE: when the address is no longer needed, the client sends it in unicast to the chosen server and the address returns to the pool.
| message | direction | source IP | destination IP | purpose |
|---|---|---|---|---|
| DHCPDISCOVER | client server | looking for a server | ||
| DHCPOFFER | server client | server IP | proposes an IP and a lease | |
| DHCPREQUEST | client server | assigned IP | accepts the offer of server X | |
| DHCPACK | server client | server IP | confirms, gives IP, netmask, gateway, DNS | |
| DHCPRELEASE | client server | client IP | server IP | releases the address |
Example. A laptop joins a Wi-Fi network using with a DHCP server at and a pool from to (101 addresses). It sends DISCOVER (, UDP ); the server offers with a one-hour lease; the laptop sends REQUEST; the server sends ACK with netmask , gateway and a DNS server. At the end the laptop sends RELEASE and is available again.
Client state machine and lease renewal
| state | event | message sent | next state |
|---|---|---|---|
| Initializing | boot | DHCPDISCOVER | Selecting |
| Selecting | offer(s) arrive | DHCPREQUEST | Requesting |
| Requesting | DHCPACK | none | Bound |
| Bound | of the lease elapsed | DHCPREQUEST (to the server that gave the address) | Renewing |
| Renewing | DHCPACK: new lease | none | Bound |
| Renewing | no answer by | DHCPREQUEST (any server, broadcast) | Rebinding |
| Rebinding | DHCPACK | none | Bound |
| Rebinding | lease expired or DHCPNACK | none | Initializing |
| Bound | the client deletes the lease | DHCPRELEASE | Initializing |
Example. Lease of 24 hours: renewal at h, rebinding at h, at 24 h the client restarts from DISCOVER. With a 1-hour lease the thresholds are 30 min and min.
Pool size. If devices arrive at rate and each keeps the address for a mean time , the mean number of occupied addresses is (Little's formula). Example. devices per hour, hours each: ; a pool has assignable addresses, a margin of only .
Different networks. A limited broadcast does not cross routers: a relay agent on the router forwards the client's broadcast in unicast to a DHCP server in another network. The DHCPACK also tells the host its default gateway, needed for indirect forwarding.
DNS
The DNS (Domain Name System) translates names into IP addresses. It is distributed (a central directory would be too large and a single point of failure) and hierarchical: an inverted tree with the root at the top, at most levels. Names read right to left: signet.dei.unipd.it is group signet (level ) inside dei, unipd and it. A label is at most characters, the whole name at most . A domain is the subtree starting at a node. There are root server addresses; new domains are registered with an ICANN-accredited registrar.
Local DNS and resolver. Each ISP has a local name server acting as a proxy. The host (resolver) sends the request to it, usually over UDP. Its address reaches the host through DHCP (in the DHCPACK). Iterative: the server answers "ask this other server"; recursive: the server finds the final answer. Normally the recursive part is between host and local DNS, which queries the others one at a time.
Resolution chain (empty cache; host some.anet.com looks up engineering.mcgraw-hill.com):
step from -> to content
1 host -> local DNS engineering.mcgraw-hill.com ?
2 local DNS -> root engineering.mcgraw-hill.com ?
3 root -> local DNS ask the server of "com"
4 local DNS -> "com" server engineering.mcgraw-hill.com ?
5 "com" server -> local DNS ask the DNS of mcgraw-hill.com
6 local DNS -> McGraw-Hill DNS engineering.mcgraw-hill.com ?
7 McGraw-Hill DNS -> local DNS the requested IP address
8 local DNS -> host the requested IP addressResolution time. ; with a fraction answered from the local cache, . Example. RTTs , , , ms: ms; with the company DNS cached, ms; answer cached, ms; with , ms.
Cache and TTL. A server stores every association it learns and marks such answers non-authoritative; an authoritative answer needs the server of the organisation that manages the name. Entries expire after the record's TTL: a change in the zone stays invisible to cached copies until the TTL ends (TTL s means up to minutes; before a migration the TTL is lowered, e.g. to s).
Records. Each item is a resource record (name, type, value, class, TTL); class IN is Internet. Types: A (IPv4 address), AAAA (IPv6), NS (authoritative DNS server of the domain), CNAME (alias), MX (mail server), PTR (name for an address).
Example. www.example.it. 3600 IN A 192.0.2.80; example.it. 3600 IN MX 10 mail.example.it. (10 is the preference: the lowest value wins).
nslookup.
nslookup www.example.it
Server: 192.168.1.1 <- local DNS used (address and port 53)
Address: 192.168.1.1#53
Non-authoritative answer: <- answer from the cache
Name: www.example.it
Address: 192.0.2.80An authoritative answer is obtained by querying an authoritative server directly: nslookup www.example.it ns1.example.it (the second argument is the server to use).
DNS and NAT. A server with a private address (10.0.0.207) must be reachable by name from outside: the intranet DNS knows myserver.com as 10.0.0.207, the NAT converts it into the public address 194.54.21.6, and the DNS reply to the client carries the public address.
Attacks on the DNS
A false answer sends the user to a wrong site (Network Security - Threats and AttacksA threat is any event that can violate a security goal (confidentiality, integrity, availability, accountability, privacy) and its realisation is an attack; security services and mechanisms counter the threats, and sniffing and spoofing underlie the main network attacks, DoS and man-in-the-middle.Network Security - Threats and Attacks →). Four types: compromised machines (the attacker modifies the host's DNS cache); a spoofed answer sent to a request of the user's machine; local DNS cache poisoning (false answers to the local DNS are cached and users go to a fake site for the whole TTL); malicious DNS servers (fraudulent data in the optional fields of the reply).
How easy is it to guess? The false answer must carry the same -bit transaction identifier ( values) and arrive before the true one. With independent false answers, : gives about , about , about . Modern resolvers also randomise the UDP source port (about more bits): the probability per attempt falls to about .
Common mistakes
- Saying the DNS only translates names to IP: it also has MX, NS, PTR, CNAME.
- Confusing the local DNS (cache, asks on behalf of the host) with an authoritative server.
- Thinking a record change is visible immediately: it stays cached until the TTL ends.
- Forgetting that the host must already know the DNS address (it comes from DHCP).
- Counting one RTT for a full resolution: with an empty cache there are four.
- Using TCP ideas for DHCP: the client has no IP yet, so it uses UDP broadcast on ports 68 and 67.
Versione ripasso
DHCP
- BOOTP vs DHCP. BOOTP (deprecated): fixed table MAC IP, only at boot. DHCP: dynamic, lease, also with the OS running, more hosts than addresses, requests refused when addresses end.
- Transport. UDP, server port , client port ; DISCOVER with MAC
ff:ff:ff:ff:ff:ff, IP (client has no IP and does not know the server). - Phases. DISCOVER (broadcast, transaction ID); OFFER (server id, proposed IP, lease); REQUEST (accepts one server); ACK (IP, netmask, default gateway, DNS server); RELEASE (unicast, address returns to the pool).
- Example. Pool
.100-.200of , server : offer with 1-hour lease, ACK with netmask and gateway . - States. Initializing DISCOVER Selecting REQUEST Requesting ACK Bound. At of the lease: Renewing (REQUEST to the same server); no answer by : Rebinding (REQUEST in broadcast); lease expired or NACK: restart from DISCOVER. Lease 24 h: 12 h and 21 h; lease 1 h: 30 min and min.
- Pool size. (Little): 120 devices/h, 2 h each, against addresses of a .
- Different networks. Limited broadcast does not cross routers: a relay agent forwards in unicast.
DNS
- Purpose. Names to IP. Distributed and hierarchical: inverted tree, root at top, at most levels, labels characters, name ; root server addresses; registrar accredited by ICANN.
signet.dei.unipd.itreads right to left. - Local DNS. Proxy of the ISP, address learned via DHCP; resolver sends the request, usually over UDP. Iterative vs recursive (recursive between host and local DNS).
- Chain with empty cache. host local DNS root TLD server authoritative DNS, each answering with the next server; sum of four RTTs. RTTs ms: ms; company DNS cached: ms; answer cached: ms; : ms.
- Cache and TTL. Non-authoritative answers come from the cache; entries expire after the TTL (3600 s means up to 60 min of stale data; lower the TTL before a migration).
- Records. (name, type, value, class, TTL), class
IN. A, AAAA, NS, CNAME, MX (lowest preference wins), PTR.www.example.it. 3600 IN A 192.0.2.80. nslookup.nslookup www.example.itshows server,Non-authoritative answer, name, address;nslookup www.example.it ns1.example.itqueries an authoritative server directly.- DNS and NAT. The reply to an external client carries the public address (
10.0.0.207194.54.21.6). - Attacks. Compromised host; spoofed answer; local cache poisoning (fake site for the whole TTL); malicious DNS server. Transaction ID bits: ( at , at ); random source port makes it about per attempt (Network Security - Threats and AttacksA threat is any event that can violate a security goal (confidentiality, integrity, availability, accountability, privacy) and its realisation is an attack; security services and mechanisms counter the threats, and sniffing and spoofing underlie the main network attacks, DoS and man-in-the-middle.Network Security - Threats and Attacks →).
- Mistakes: DNS also has MX, NS, PTR, CNAME; local DNS vs authoritative; changes cached until TTL; DNS address comes from DHCP; four RTTs, not one; DHCP uses UDP broadcast (68 and 67).