<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Soul Of Free Loop &#187; ntpdate</title>
	<atom:link href="https://zohead.com/archives/tag/ntpdate/feed/" rel="self" type="application/rss+xml" />
	<link>https://zohead.com</link>
	<description>Uranus Zhou&#039;s Blog</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:42:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>树莓派上使用htpdate同步时间</title>
		<link>https://zohead.com/archives/htpdate-raspberry/</link>
		<comments>https://zohead.com/archives/htpdate-raspberry/#comments</comments>
		<pubDate>Mon, 13 Oct 2014 16:12:25 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[工具]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[NTP]]></category>
		<category><![CDATA[ntpdate]]></category>
		<category><![CDATA[时间同步]]></category>
		<category><![CDATA[树莓派]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=809</guid>
		<description><![CDATA[最近住处的网络由电信换为移动宽带之后，之前一直使用的 Raspberry Pi 树莓派板子上出现系统时间不正确的问题（显示为 1970 年 1 月 1 日），由于树莓派板子上没有 RTC 硬件和电池，因此树莓派上的系统时间重启是保存不了的。 之前设置的是每次开机自动使用 ntpdate 命令从 NTP 服务器上同步时间，但现在每次运行时都提示： 同时公司里电信网络环境下这个命令又是完全正常的，移动宽带环境下直接 ping 这个 NTP 服务器也是通的，因此估计就是移动宽带直接把 NTP 给封了。 在谴责移动的同时只能另想办法，还好网上已经有人想到这种应对 NTP 被防火墙封掉类似的需求了，开源 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>最近住处的网络由电信换为移动宽带之后，之前一直使用的 Raspberry Pi 树莓派板子上出现系统时间不正确的问题（显示为 1970 年 1 月 1 日），由于树莓派板子上没有 RTC 硬件和电池，因此树莓派上的系统时间重启是保存不了的。</p>
<p>之前设置的是每次开机自动使用 ntpdate 命令从 NTP 服务器上同步时间，但现在每次运行时都提示：</p>
<p><pre class="brush: bash; title: ; notranslate">
root@XBian:~# ntpdate ntp.sjtu.edu.cn
13 Oct 23:49:01 ntpdate[1484]: no server suitable for synchronization found
</pre>
</p>
<p><span id="more-809"></span></p>
<p>同时公司里电信网络环境下这个命令又是完全正常的，移动宽带环境下直接 ping 这个 NTP 服务器也是通的，因此估计就是移动宽带直接把 NTP 给封了。</p>
<p>在谴责移动的同时只能另想办法，还好网上已经有人想到这种应对 NTP 被防火墙封掉类似的需求了，开源的 htpdate 命令直接使用 HTTP 协议（这个是不可能封的了）来进行系统时间同步，项目主页在这里：</p>
<p><a href="https://github.com/iridium77/htpdate" target="_blank">https://github.com/iridium77/htpdate</a></p>
<p>htpdate 的原理也非常简单，直接解析 HTTP 协议头中的服务器时间信息，然后设置本地时间，我们来看百度返回的 HTTP 头：</p>
<p><pre class="brush: plain; title: ; notranslate">
HTTP/1.1 200 OK
Date Mon, 13 Oct 2014 16:05:18 GMT
Content-Type text/html
Transfer-Encoding chunked
Connection Keep-Alive
Cache-Control private
Expires Mon, 13 Oct 2014 16:05:18 GMT
Server BWS/1.1
BDPAGETYPE 2
BDQID 0x8b40c1f700000bd4
BDUSERID 13923551
Set-Cookie BDSVRTM=133; path=/
Set-Cookie BD_HOME=1; path=/
</pre>
</p>
<p>上面的 Date Mon, 13 Oct 2014 16:05:18 GMT 就是百度的 Web 服务器上的系统时间了。</p>
<p>htpdate 命令做时间同步会有 0.5 秒左右的误差（看看 HTTP 头就知道里面很多时间都是以秒为单位哈），对于我的树莓派来说就完全没有关系，如果对这个比较在意的话只能尽量用 NTP 时间同步了。</p>
<p>htpdate 使用上也很简单，简单编译安装之后把这条命令加到 Raspberry Pi Raspbian 系统的 /etc/rc.local 文件中（不加 -t 参数基本不能同步成功哦）：</p>
<p><strong>htpdate -t -s ntp.neu.edu.cn</strong></p>
<p>然后重启树莓派就可以正常同步系统时间了。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/htpdate-raspberry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
