Add NTP server address in DHCP response of EdgeRouter
If you have an EdgeRouter-X from Ubiquiti, you have to do most of the configuration your self. This includes simple niceties like having a reference NTP server mentioned in your router DHCP responses. For some equipment, like printers, it might even be the only way to automatically configure the time correctly. Having had to Google for the solutions, I decided to write up a small tutorial on doing this.
Ubiquity uses an open source DHCP daemon, but it's configured via their own configuration management system. In order to add the ntp server configuration, we need to add custom DHCP options, the ntp-servers
option to be precise.
Step 1, check your current DHCP response with nmap
:
sudo nmap --script broadcast-dhcp-discover
We run the nmap
script called broadcast-dhcp-discover
. If that does not work, look into adding a -e interface_name
to define the output interface or --script-args mac=9c:66:00:dd:aa:0d
to configure the outbound MAC address to something else.
The output should be something like the following:
Starting Nmap 7.80 ( https://nmap.org ) at 2020-11-19 21:08 CET
Pre-scan script results:
| broadcast-dhcp-discover:
| Response 1 of 1:
| IP Offered: 192.168.62.80
| DHCP Message Type: DHCPOFFER
| Server Identifier: 192.168.62.1
| IP Address Lease Time: 5m00s
| Subnet Mask: 255.255.255.0
| Router: 192.168.62.1
| Domain Name Server: 1.0.0.1, 1.1.1.1
| Renewal Time Value: 2m30s
|_ Rebinding Time Value: 4m22s
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 1.37 seconds
Step 2, add the ntp-servers
option and point it to time.cloudflare.com, SSH into your EdgeRouter and issue the following commands:
configure
set service dhcp-server global-parameters 'option ntp-servers time.cloudflare.com;'
commit
save
exit
Step 3, verify the result by repeating step 1, you should see NTP Servers: 162.159.200.123, 162.159.200.1
in there.