Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

linux搭建ntp服务器

作者:青灯寂焚   发布日期:2026-03-20   浏览:64

# 安装 NTP 服务
sudo apt-get update
sudo apt-get install ntp

# 编辑 NTP 配置文件
sudo nano /etc/ntp.conf

# 在配置文件中添加或修改以下内容:
# 指定上游 NTP 服务器
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

# 允许本地网络中的设备同步时间
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 保存并退出编辑器 (Ctrl+X, 然后按 Y, 最后按 Enter)

# 重启 NTP 服务以应用更改
sudo systemctl restart ntp

# 检查 NTP 服务状态
sudo systemctl status ntp

# 查看 NTP 同步状态
ntpq -p

解释说明:

  1. 安装 NTP 服务:使用 apt-get 命令来更新软件包列表并安装 NTP 服务。
  2. 编辑 NTP 配置文件:使用 nano 编辑 /etc/ntp.conf 文件,指定上游 NTP 服务器,并设置访问控制规则。
  3. 指定上游 NTP 服务器:通过 server 指令添加多个公共 NTP 服务器,确保时间同步的可靠性和冗余性。
  4. 允许本地网络中的设备同步时间:通过 restrict 指令设置访问控制规则,允许特定 IP 地址范围内的设备同步时间。
  5. 重启 NTP 服务:使用 systemctl 命令重启 NTP 服务以应用配置文件中的更改。
  6. 检查 NTP 服务状态:使用 systemctl status 命令查看 NTP 服务的运行状态。
  7. 查看 NTP 同步状态:使用 ntpq -p 命令查看当前 NTP 同步状态,确认时间同步是否正常工作。

上一篇:linux磁盘总容量命令

下一篇:linux系统怎么ping ip地址

大家都在看

linux常用命令查询端口是否正常

linux 发送邮件

linux长ping命令

linux groupadd

linux关机命令行

linux 安装 gcc

linux重启oracle命令

linux把一个文件夹移动到另一个文件夹里

linux查看系统运行时间

linux搭建sftp

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站