找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 56019|回复: 26

[已解决]openwrt如何同步时间

[复制链接]
发表于 2014-6-18 21:03 | 显示全部楼层 |阅读模式
本帖最后由 jbcdidgosir 于 2016-2-28 14:51 编辑

系统重启后,时间丢失,因为是在公司内网通过代理连接openvirtual**的,所以开机后不会自动同步时间,只有在连上virtual**后才能同步,那么,同步的指令是啥?尝试过:
ntpdate 0.pool.ntp.org
但是回复是-ash: ntpdate: not found

网上查到有说用ntpclient,其实我发现即使不动它,24小时内也会自动会同步时间的,说明不需要安装任何软件,只是需要触发一下自带的同步命令,但是不知道是啥命令,请问有达人知道吗?

2016-2-28更新:
已解决,免安装的指令是
ntpd -n -q -p 0.asia.pool.ntp.org
我的恩山、我的无线 The best wifi forum is right here.
发表于 2014-6-18 21:45 | 显示全部楼层
你打 ps | grep ntp 不是有这个服务吗?

root@OpenWrt:~# ps | grep ntp
3290 root      1504 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p



点评

有这服务说明什么?能直接用ntpclient? root@OpenWrt:~# ps | grep ntp 1393 root 1380 S /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.open 14440 root 1372 S grep ntp root@OpenWrt:  详情 回复 发表于 2014-6-18 22:45
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-6-18 21:46 | 显示全部楼层
直接用date命令设置时间

点评

我要让路由器自动同步,路由器怎么可能知道当前时间.  详情 回复 发表于 2014-6-18 22:46
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-6-18 22:45 | 显示全部楼层
hkal 发表于 2014-6-18 21:45
你打 ps | grep ntp 不是有这个服务吗?

root@OpenWrt:~# ps | grep ntp

有这服务说明什么?能直接用ntpclient?

root@OpenWrt:~# ps | grep ntp
1393 root      1380 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.open
14440 root      1372 S    grep ntp
root@OpenWrt:~# ntpclient -s -c 0 -h 0.openwrt.pool.ntp.org
-ash: ntpclient: not found

还望继续指点.谢谢!

点评

你试试行不行。我的路由时间本来已经同步了,运行了上面的指令,不知道时间有没有改变。 ntpd 的命令:  详情 回复 发表于 2014-6-18 23:04
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-6-18 22:46 | 显示全部楼层
airqj 发表于 2014-6-18 21:46
直接用date命令设置时间

我要让路由器自动同步,路由器怎么可能知道当前时间.
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-6-18 23:04 | 显示全部楼层
jbcdidgosir 发表于 2014-6-18 22:45
有这服务说明什么?能直接用ntpclient?

root@OpenWrt:~# ps | grep ntp
root@OpenWrt:~# ntpd -n -d -p stdtime.gov.hk
ntpd: resolved peer stdtime.gov.hk to 118.143.17.82
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x01 offset -0.006161 delay 0.003906 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x03 offset -0.006240 delay 0.004142 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x07 offset -0.005990 delay 0.003906 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x0f offset -0.005922 delay 0.003906 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x1f offset -0.005893 delay 0.003906 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
ntpd: sent query to 118.143.17.82
ntpd: reply from 118.143.17.82: reach 0x3f offset -0.001876 delay 0.013546 status 0x24 strat 1 refid 0x4d525300 rootdelay 0.000000
Alarm clock
root@OpenWrt:~#
你试试行不行。我的路由时间本来已经同步了,运行了上面的指令,不知道时间有没有改变。



ntpd 的命令:

root@OpenWrt:~# ntpd -h
ntpd: invalid option -- h
BusyBox v1.19.4 (2014-01-26 22:27:51 CST) multi-call binary.

Usage: ntpd [-dnqNwl] [-S PROG] [-p PEER]...

NTP client/server

        -d      Verbose
        -n      Do not daemonize
        -q      Quit after clock is set
        -N      Run at high priority
        -w      Do not set time (only query peers), implies -n
        -l      Run as server on port 123
        -S PROG Run PROG after stepping time, stratum change, and every 11 mins
        -p PEER Obtain time from PEER (may be repeated)

root@OpenWrt:~#



点评

我的也无法同步,可是我执行了取是这样:还是不行。 root@OPENWRT:~# ntpd -n -d -p stdtime.gov.hk ntpd: resolved peer stdtime.gov.hk to 118.143.17.82 ntpd: sending query to 118.143.17.82 ntpd: timed  详情 回复 发表于 2016-2-14 19:58
果然可以同步,只是为啥同步那么多次呢?我想写入c语言,这样的话,可能就需要等待很长的时间了.不知有其他方法吗?其实不需要特别准,误差3秒都无所谓的.  详情 回复 发表于 2014-6-18 23:44
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-6-18 23:44 | 显示全部楼层
本帖最后由 jbcdidgosir 于 2014-6-18 23:45 编辑
hkal 发表于 2014-6-18 23:04
你试试行不行。我的路由时间本来已经同步了,运行了上面的指令,不知道时间有没有改变。


果然可以同步,只是为啥同步那么多次呢?好像如果不强行打断是不会停的.
我想用c写这句指令后编译,但这样的话,不光要等待很长的时间,还不能结束.不知有其他方法吗?其实不需要特别准,误差3秒都无所谓的.

点评

我换了其他的NTP服务器地址,还是不行... root@OPENWRT:~# ntpd -n -d -p ntp.sjtu.edu.cn ntpd: resolved peer ntp.sjtu.edu.cn to 202.120.2.100 ntpd: sending query to 202.120.2.100 ntpd: timed out waiti  详情 回复 发表于 2016-2-14 20:03
不知道为什么要这么多次。 不需要强行打断,它自己会停,时间久一点。  详情 回复 发表于 2014-6-18 23:51
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-6-18 23:51 | 显示全部楼层
jbcdidgosir 发表于 2014-6-18 23:44
果然可以同步,只是为啥同步那么多次呢?好像如果不强行打断是不会停的.
我想用c写这句指令后编译,但这 ...

不知道为什么要这么多次。
不需要强行打断,它自己会停,时间久一点。

点评

哦,那也行,多谢啊!  详情 回复 发表于 2014-6-19 09:21
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-6-19 09:21 | 显示全部楼层
hkal 发表于 2014-6-18 23:51
不知道为什么要这么多次。
不需要强行打断,它自己会停,时间久一点。

哦,那也行,多谢啊!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-6-19 17:58 | 显示全部楼层
Mark
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-2-14 18:01 | 显示全部楼层
MARK!晚些弄!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-2-14 19:58 | 显示全部楼层
hkal 发表于 2014-6-18 23:04
你试试行不行。我的路由时间本来已经同步了,运行了上面的指令,不知道时间有没有改变。

我的也无法同步,可是我执行了取是这样:还是不行。

root@OPENWRT:~# ntpd -n -d -p stdtime.gov.hk
ntpd: resolved peer stdtime.gov.hk to 118.143.17.82
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 1s
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 2s
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 1s
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 2s
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 32s
ntpd: sending query to 118.143.17.82
ntpd: timed out waiting for 118.143.17.82, reach 0x00, next query in 33s

点评

试试其他 ntp 服务器,我刚试了:  详情 回复 发表于 2016-2-18 23:13
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-2-14 20:03 | 显示全部楼层
jbcdidgosir 发表于 2014-6-18 23:44
果然可以同步,只是为啥同步那么多次呢?好像如果不强行打断是不会停的.
我想用c写这句指令后编译,但这 ...

我换了其他的NTP服务器地址,还是不行...
root@OPENWRT:~# ntpd -n -d -p ntp.sjtu.edu.cn
ntpd: resolved peer ntp.sjtu.edu.cn to 202.120.2.100
ntpd: sending query to 202.120.2.100
ntpd: timed out waiting for 202.120.2.100, reach 0x00, next query in 2s
ntpd: sending query to 202.120.2.100

不知为什么。

点评

可以的.你是原版的固件吗?  详情 回复 发表于 2016-2-15 10:54
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-2-15 10:54 | 显示全部楼层
mitchell 发表于 2016-2-14 20:03
我换了其他的NTP服务器地址,还是不行...
root@OPENWRT:~# ntpd -n -d -p ntp.sjtu.edu.cn
ntpd: resol ...

可以的.你是原版的固件吗?

点评

哦,我用的是明月的固件。不过这个是很基础的东西。难道是固件的问题?! 谢谢指教!  详情 回复 发表于 2016-2-15 12:36
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-2-15 12:36 | 显示全部楼层
jbcdidgosir 发表于 2016-2-15 10:54
可以的.你是原版的固件吗?

哦,我用的是明月的固件。不过这个是很基础的东西。难道是固件的问题?!
谢谢指教!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-19 16:14

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表