ntpd是一个用于实现网络时间协议(NTP)的守护进程,它允许路由器与互联网上的时间服务器同步时间。这样可以确保路由器的系统时间是准确的,这对于很多依赖于时间的服务和功能来说非常重要,比如VPN、动态DNS、定时任务等。
1 配置ntpd
ntpd由Busybox提供:
Base system
Networking Utilities
ntpd
Make ntpd usable as a NTP server
Make ntpd understand /etc/ntp.conf
Support md5/sha1 message authentication codes
2 启动ntpd
ntpd使用说明:
Usage: ntpd [-dnqNwl] [-I IFACE] [-S PROG] [-p PEER]...
NTP client/server
-d[d] Verbose
-n Run in foreground
-q Quit after clock is set
-N Run at high priority
-w Do not set time (only query peers), implies -n
-S PROG Run PROG after stepping time, stratum change, and every 11 min
-p PEER Obtain time from PEER (may be repeated)
-l Also run as server on port 123
-I IFACE Bind server to IFACE, implies -l
/etc/rc.d/S98sysntpd启动ntpd进程:
/sbin/ujail -t 5 -n ntpd -U ntp -G ntp -C /etc/capabilities/ntpd.json -c -u -r /bin/ubus -r /usr/bin/env -r /usr/bin/jshn -r /usr/sbin/ntpd-hotplug -r /usr/share/libubox/jshn.sh -- /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.o
/usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org
3 配置ntpd
ntpd配置文件位于/etc/config/system中:
/etc/config/system
config system
option hostname 'OpenWrt'
option ttylogin '0'
option log_size '64'
option urandom_seed '0'
option zonename 'UTC'
option log_proto 'udp'
option conloglevel '8'
option cronloglevel '5'
config timeserver 'ntp'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
这里添加了四个公共的NTP服务器,可以通过Web界面配置:
- 登录到OpenWrt的Web界面。
- 导航到 “System Tools” -> “Time Synchronization”。
- 在 “NTP Servers” 部分,你可以输入你想要使用的NTP服务器地址。
- 保存设置并重启ntpd服务。
5316

被折叠的 条评论
为什么被折叠?



