centos NTP服务搭建

1.服务器端安装NTP服务
yum -y install ntp

2.修改NTP配置文件
vi /etc/ntp.conf

1)允许任何IP的客户机都可以进行时间同步

将“restrict default kod nomodify notrap nopeer noquery”这行修改成:restrict default nomodify

2)#新增:时间服务器列表.
server 0.cn.pool.ntp.org iburst
#新增:当外部时间不可用时,使用本地时间.

server 127.127.1.0     # local clock
fudge  127.127.1.0 stratum 10

3.修改完成后重启ntpd服务systemctl restart ntpd
使用ntpq -p 查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

4.防火墙开启UDP 123端口
firewall-cmd --add-port=123/udp --permanent 
重启防火墙
 firewall-cmd --reload
查看
firewall-cmd --list-all

在这里插入图片描述

测试:

LINUX下:

客户端安装:

yum install -y ntp

ntpdate 10.5.20.202  同步时间

在这里插入图片描述
扩展:Linux获取NTP通讯数据包

命令:
tcpdump -i ens33 -c 10 udp port 123 and host 10.5.20.202 -w ./target.cap
参数说明: 
-i 选择网卡
-c 抓取数据包个数
host 主机地址
-w 写入到文件

windows下

在windows的cmd命令行界面使用下面的命令可以检测NTP服务器是否可用:

w32tm /stripchart /computer:ntp_server_address

测试命令:
w32tm /stripchart /computer:IP

1.连接错误的情况
C:\Users\dong>w32tm /stripchart /computer:IP
当前时间是 2020/8/26 14:39:22。
14:39:22, 错误: 0x800705B4
14:39:25, 错误: 0x800705B4




2.连接正常的情况:
C:\Users\dong>w32tm /stripchart /computer:cn.pool.ntp.org
正在跟踪 cn.pool.ntp.org [185.209.85.222:123]。
当前时间是 2020/8/26 14:40:26。
14:40:40, d:+00.2904919s o:+01.1276825s  [       |  *         ]
14:40:42, d:+00.3456050s o:+01.0955438s  [       |  *         ] 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是在 CentOS 7 上搭建 NTP 服务器的步骤: 1. 安装 NTP:运行以下命令安装 NTP: ``` sudo yum install ntp ``` 2. 配置 NTP:编辑 `/etc/ntp.conf` 文件,配置服务器地址和允许访问的客户端地址。例如,以下是一个示例配置: ``` server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict <客户端IP地址> mask <子网掩码> nomodify notrap ``` 其中,`server` 指定 NTP 服务器地址,`restrict` 用于限制访问控制。 3. 启动 NTP:运行以下命令启动 NTP 服务并设置为开机自启: ``` sudo systemctl start ntpd sudo systemctl enable ntpd ``` 4. 验证 NTP:使用 `ntpq` 命令验证 NTP 是否正常工作。例如,运行以下命令: ``` ntpq -p ``` 如果 NTP 正常工作,将显示类似以下内容的输出: ``` remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.example.c .GPS. 1 u 154 256 377 0.862 -30.200 1.835 +ntp2.example.c .PPS. 1 u 173 256 377 0.991 -30.230 1.309 -ntp3.example.c .GPS. 1 u 130 256 377 1.003 -29.990 1.935 ``` 其中,`*` 表示当前服务器为 NTP服务器,`+` 表示当前服务器为 NTP 辅助服务器,`-` 表示当前服务器为 NTP 被动服务器。 以上就是在 CentOS 7 上搭建 NTP 服务器的步骤。希望能对你有所帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值