Sub topic 12
DHCP, NTP, SNMP and syslog
This chapter covers four infrastructure protocols that keep a network running. It assumes you know what a port is, the difference between TCP and UDP, and how a client talks to a server on a well-known port. All four mainly use UDP, because their messages are small and a lost message is cheap to retry or skip.
Port summary
| Protocol | Purpose | Default port |
|---|---|---|
| DHCP | Hands out IP configuration | UDP 67 (server), UDP 68 (client) |
| NTP | Synchronizes clocks | UDP 123 |
| SNMP | Queries and monitors devices | UDP 161 (queries), UDP 162 (traps) |
| Syslog | Collects log messages | UDP 514 (traditional), TCP 6514 (TLS) |
DHCP: ports 67 and 68
The Dynamic Host Configuration Protocol (DHCP) gives a host an IP address, a subnet mask, a default gateway and DNS servers. It is unusual because both ends use a fixed port. The server listens on UDP 67 and the client listens on UDP 68. The client has no address yet, so it broadcasts its first message.
Across routers, a DHCP relay agent forwards these broadcasts to a server on another subnet. DHCPv6 uses UDP 546 for clients and UDP 547 for servers.
NTP: port 123
The Network Time Protocol (NTP) keeps clocks in agreement. Servers listen on UDP 123. Accurate time matters for log correlation, certificate validation and Kerberos. A firewall that blocks UDP 123 causes clock drift that is hard to diagnose.
SNMP: ports 161 and 162
The Simple Network Management Protocol (SNMP) lets a management station read counters and settings from devices such as switches and printers. The device runs an agent that listens on UDP 161. The agent can also send unsolicited alerts, called traps, to the manager on UDP 162.
Versions 1 and 2c authenticate with a plain-text community string. Use SNMPv3 where possible, because it adds authentication and encryption.
Syslog: port 514 and TLS
Syslog sends log messages from devices and servers to a central collector. The traditional transport is UDP 514. Because UDP gives no delivery guarantee, messages can be lost silently. Some collectors also accept TCP 514. For protected delivery, syslog over TLS uses TCP 6514.
Looking up the ports in code
This script asks the system services database for each port. Some systems omit entries such as bootps, so the script reports a missing name instead of failing.
import socket
services = [
("bootps", "udp"),
("bootpc", "udp"),
("ntp", "udp"),
("snmp", "udp"),
("snmptrap", "udp"),
("syslog", "udp"),
]
for name, proto in services:
try:
print(name, proto, socket.getservbyname(name, proto))
except OSError:
print(name, proto, "not in the services database")On a typical Linux system this prints 67, 68, 123, 161, 162 and 514.
Exercise
A monitoring station polls a switch with SNMP, and the switch also sends alerts back to the station. Which UDP port does the switch listen on for polls, and which port does the station listen on for the alerts?
Show answer
The switch listens on UDP 161 for polls. The station listens on UDP 162 for the traps the switch sends.
Exercise
Why does a DHCP client use a broadcast for its first message, and which source and destination ports does that message use?
Show answer
The client has no IP address yet and does not know the server's address, so it broadcasts. The message goes from UDP port 68 to UDP port 67.