ntp簡介:
定義:網路時間協議ntp(network time protocol)是tcp/ip協議簇裡面的乙個應用層協議,
ntp用於在一系列分布式時間伺服器之間同步時鐘,ntp的實現基於ip和udp,ntp的報文通過udp傳輸,
埠號是udp123。
目的:隨著網路拓撲的日益複雜,整個網路內裝置的時鐘同步變得十分重要,如果依靠管理員手動修改系統時鐘,
不僅工作量大,而且無法保證時間的準確性,ntp的出現就是為了解決網路內裝置系統時鐘的同步問題。
》系統時鐘的同步流程如下:
1.ntp客戶端在t1時刻傳送乙個ntp請求報文給ntp服務區,該請求報文中攜帶離開客戶端的時間戳為t1。
2.ntp請求報文到達ntp伺服器,此時ntp伺服器的時刻為t2。
3.ntp伺服器處理之後,與t3時刻傳送出ntp應答報文,該應答報文中攜帶離開ntp客戶端的時間戳為t1,
到達ntp伺服器時的時間戳t2,離開ntp伺服器的時間戳為t3。
4.ntp客戶端在t4時刻受到應答報文。
我們可以通過以下公式算出ntp客戶端與ntp伺服器之間的時間差,也就是ntp客戶端需要調整的時間。
1.計算ntp報文從ntp客服端傳送到ntp伺服器所需的時間delay。
delay =[(t4-t1)-(t3-t2)]/2
2. 計算ntp客戶端與ntp伺服器之間的時間差offset。
以t4時刻為例,在這個時刻點,ntp伺服器傳送過來的報文被ntp客戶端接收時,伺服器的時刻已經為t3+delay。
那麼時間差offset可由以下公式進行計算:
t4 + offset = t3+ delay
公式整理之後,offset = t3 + delay - t4 =t3+[(t4-t1)-(t3-t2)]/2 -t4=[(t2-t1)+(t3-t4)]/2
ntp 客戶端根據計算得到的offset 來調整自己的時鐘,實現與ntp伺服器的時鐘同步。
配置命令:
》配置帶驗證的單播ntp伺服器
swa:ntp-service refclock-master 2 //在swa上指定使用自己的本地時鐘作為主時鐘,層數為2
swa:ntp-service authentication enable //使能ntp認證功能
swa:ntp-service authentication-keyid 42 authentication-mode hmac-sha256 cipher 123456
//配置驗證秘鑰
swa:ntp-service reliable authentication-keyid 42 //宣告該秘鑰可信
swa:undo ntp-service server disable //伺服器需要使能ntp伺服器功能
swb:ntp-service authentication enable
swb: ntp-service suthentication-keyid 42 authentication-mode hmac-sha256 cipher 123456
swb: ntp-service reliable authentication-keyid 42
swb: ntp -service unicast-server 10.1.1.1 authentication-keyid 42 //指向swa為ntp伺服器
驗證命令:
display ntp-service status //檢視ntp狀態,synchronized既完成同步
》配置帶驗證的廣播ntp伺服器
swa: ntp-service refclock-master 3 //使用本地時鐘為ntp的主時鐘,層數3
swa: ntp-service suthentication enable //啟用ntp 認證
swa: ntp-service authentication-keyid 16 authentication-mode hmac-sha256 cipher 123456
//配置驗證秘鑰
swa:ntp-service reliable authentication-keyid 16 //宣告該id可信
swa:inte***ce vlanif 10
ntp-service broadcast-server authentication-keyid 16 //從vlan10傳送ntp廣播報文並指定秘鑰16加密
swa:undo ntp-service server disable // 使能ntp伺服器功能
swb:ntp-service authentication enable
swb:ntp-service authentication-keyid 16 authentication-mode hmac-sha256 cipher 123456
swb: ntp-service reliable authentication-keyid 16
swb: inte***ce vlanif 10
ntp-service broadcast-client //從vlan10 偵聽ntp廣播報文
》配置ntp組播模式
swa:ntp-service refclock-master 2
swa: inte***ce vlanif 10
ntp-service multicast-server //從vlan10傳送ntp組播報文
swa:undo ntp-service server disable
swb: inte***ce vlanif 10
ntp-server multicast-client //從vlan10偵聽ntp組播報文
NTP 網路時間協議
gmt 格林威治標準時間 utc 世界協調時間 屬於原子時鐘 cts 北京標準時間 不停地時間同步,可以保證時間的相對準確,但是永遠無法精確 網路通訊延遲影響時間同精度 ntp通過網路進行時間同步,提供時間服務和協議。ntp協議分為17層 第0層 第16層,0代表時間源。和0層時間伺服器同步的是1層...
NTP網路時間協議
網路時間協議,英文名稱 network time protocol ntp 是用來使計算機時間同步化的一種協議,它可以使計算機對其伺服器或時鐘源 如石英鐘,gps等等 做同步化,它可以提供高精準度的時間校正 lan上與標準間差小於1毫秒,wan上幾十毫秒 且可介由加密確認的方式來防止惡毒的協議攻擊。...
NTP 網路時間協議
前言 搭建了乙個linux虛擬機器,發現跑著跑著時間有差異,查資料發現這個是正常的,因為系統時間和硬體時間是本地時間,會因各種原因導致跟標準時間utc時間有差異,所以計算機界的牛人發明了ntp協議,專門用來解決時間差異問題。概念 ntp,網路時間協議,專門用於不同主機間的時間同步,他是乙個層級結構,...