OpenWrt Forum Archive

Topic: How to configure openwrt to receive ntp server using DHCP?

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Sorry for my lack of knowledge,
I would like to configure openwrt to get the NTP server using DHCP.
I am using Backfire (10.03.1, r29592) AR71xx in a Nanostation Loco M2. Default DHCP client is udhcpc.
I'm trying the following settings:

root@OpenWrt:~# cat /etc/config/network 
config interface loopback
        option ifname   lo
        option proto    static
        option ipaddr   127.0.0.1
        option netmask  255.0.0.0

config interface lan
        option ifname   eth0
        option type     bridge
        option proto    dhcp
        option hostname    ap0009
        option reqopts    42
root@OpenWrt:~# cat /etc/config/system 
config system
        option timezone 'BRT3BRST,M10.3.0/0,M2.3.0/0'
        option log_ip   '10.0.0.2'
        option log_port '514'
        option log_size '16'
        log_type        'circular'

config timeserver 'ntp'
        option enable_server '0'

/etc/init.d/sysntpd is enable.

When I do a "ps | grep ntp" I see no ntp server service running.

Could someone help me please?

thanks,

Which ntp server should OpenWRT use? -> Enter that server in /etc/config/system

Sorry, got your request wrong... didn't even know that NTP configuration can be done via dhcp.

Maybe this helps: http://linux.die.net/man/5/dhcp-options

---> option ntp-servers ip-address [, ip-address... ];
This option specifies a list of IP addresses indicating NTP (RFC 1035) servers available to the client. Servers should be listed in order of preference.

(Last edited by tmo26 on 23 Apr 2013, 17:51)

Hi tmo26, thanks for your reply.

This site says that the option code for ntp-server is 42. ( http://www.networksorcery.com/enp/proto … ptions.htm )

My DHCP server is dnsmasq and is running on linux CentOS.
In the / etc / dnsmasq.conf I inserted the following line:

dhcp-option=42,200.160.7.186,201.49.148.135

And  /etc/config/network was:

root@OpenWrt:~# cat /etc/config/network 
config interface loopback
        option ifname   lo
        option proto    static
        option ipaddr   127.0.0.1
        option netmask  255.0.0.0

config interface lan
        option ifname   eth0
        option type     bridge
        option proto    dhcp
        option hostname    ap0009
        option reqopts    42

With these settings the openwrt failed to get the ntp server via DHCP.

In dnsmasq.conf I can optionally write:

dhcp-option = option: ntp-server, 200.160.7.186,201.49.148.135

However it did not work too.

I replaced 'option reqopts 42' by 'option reqopts ntp-server' in / etc / config / network, but also did not work.

it could be a client problem? in this case udhcpc ?

Thanks!

I think there is some conffusion here, what are you trying todo?

use dnsmasq (dhcp server on the router) to send out the address to the ntp server, or updating the router with the ntp server from the wan dhcp server?

Resurrecting thread, if your ntp servers are 10.0.0.1 and 10.0.0.11 you can either have this in /etc/dsnmasq

# Set the NTP time server addresses to me (.1) and ntp2 (.11)
dhcp-option=option:ntp-server,10.0.0.1,10.0.0.11

or this in /etc/config/dhcp:

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '100'
        option 'limit' '150'
        option 'leasetime' '4h'
[...]
        list   'dhcp_option' '42,10.0.0.1,10.0.0.12'

Now, note that entries in /etc/config/dhcp overides those in /etc/dnsmasq

FriedZombie wrote:

I think there is some conffusion here, what are you trying todo?

use dnsmasq (dhcp server on the router) to send out the address to the ntp server, or updating the router with the ntp server from the wan dhcp server?

Hi , FriedZombie

I want to update the router with the ntp server from the wan dhcp server.

Thanks,

The discussion might have continued from here.