# 8.华三交换机配置NTP

## 1 组网需求

如[图1](https://www.h3c.com/cn/d_202012/1371466_30005_0.htm#_Ref256147451)所示，网络中有一台时间服务器Device A，为网络中的其它设备提供精确的时间服务，为保证网络中的所有设备能保持一致、统一的时钟，现要求配置NTP服务器/客户端模式，使所有设备能从时间服务器Device A上获得时钟同步。

图1 配置NTP服务器/客户端模式组网图

![img](https://pic.chjina.com/2023/06/01/20201231_5475298_image001_1371466_30005_0.png)

## 2 配置步骤

### 1 Device A的配置

\# 配置NTP客户端，接受公网NTP校时。

\# 设置DNS

\[DeviceA] dns server 223.5.5.5

\# 开启NTP功能。

ntp-service enable

\# 通过NTP协议获取时间

\[DeviceA] clock protocol ntp

\# 设置时区为东八区

\[DeviceA] clock timezone BeiJing add 8

\# 设置NTP服务器地址

ntp-service unicast-server ntp.chjina.com

\# 设置本地时钟作为参考时钟，层数为2。

\[DeviceA] ntp-service refclock-master 2

### 2 Device B的配置

\# 配置接口的IP地址，配置步骤这里省略。

\# 开启NTP功能。

system-view

\[DeviceB] ntp-service enable

\# 设置NTP Server为Device B的时间服务器。

\[DeviceB] ntp-service unicast-server 1.0.1.11

## 3 验证配置

\# 以上配置完成后，Device B向Device A进行时间同步。查看NTP的运行状态。

```
[DeviceB] display ntp-service status
 Clock status: synchronized 
 Clock stratum: 3
 System peer: 1.0.1.11   
 Local mode: client     
 Reference clock ID: 1.0.1.11
 Leap indicator: 00     
 Clock jitter: 0.003479 s  
 Stability: 0.000 pps    
 Clock precision: 2^-19    
 Root delay: 1.95313 ms   
 Root dispersion: 28.38135 ms
 Reference time: d5ed8cd5.577006ea Wed, Sep 25 2019 16:24:53.341
```

此时Device B已经与Device A同步，层数比Device A的层数大1，为3。

\# 查看Device B的NTP会话信息，可以看到Device B与Device A建立了连接。

```
[DeviceB] display ntp-service sessions
​     source     reference    stra reach poll now offset delay disper
********************************************************************************
[12345]1.0.1.11    127.127.1.0    2  255  64  38 -10.22 1.9531 3.3416
Notes: 1 source(master), 2 source(peer), 3 selected, 4 candidate, 5 configured.
 Total sessions: 1
```

## 配置文件

· Device A上的配置

```
interface Vlan-interface2
 ip address 1.0.1.11 255.255.255.0
 dns server 223.5.5.5
 clock protocol ntp
 clock timezone BeiJing add 8
 ntp-service enable 
 ntp-service  refclock-master 2
 ntp-service unicast-server ntp.chjina.com
 ntp-service unicast-server 182.92.12.11
```

· Device B上的配置

```
interface Vlan-interface2
 ip address 1.0.1.12 255.255.255.0
 ntp-service enable
 ntp-service unicast-server 1.0.1.11
```

参考:

{% embed url="<https://www.h3c.com/cn/d_202201/1535193_30005_0.htm#_Toc93421431>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chjina.com/it-zhi-shi-ku/lu-you-jiao-huan/hua-san/8.-hua-san-jiao-huan-ji-pei-zhi-ntp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
