centos 搭建内网ntp时间服务器

在 CentOS 搭建内网 NTP 时间服务器,你可以按照以下步骤操作:

  1. 安装 NTP 服务

    打开终端并以 root 用户身份登录。使用以下命令安装 NTP 服务:

    复制代码
    sudo yum install ntp
  2. 配置 NTP 服务器

    打开 NTP 配置文件 /etc/ntp.conf,并编辑它以配置你的 NTP 服务器。你可以使用文本编辑器打开它,例如:

    复制代码
    sudo vi /etc/ntp.conf

    在文件中,你可以指定你的 NTP 服务器的配置。以下是一个示例:

    复制代码
    restrict default kod nomodify notrap nopeer noquery
    restrict -6 default kod nomodify notrap nopeer noquery
    
    # 允许本地服务器同步
    restrict 127.0.0.1
    restrict -6 ::1
    
    # 允许内网的子网同步(替换成你的内网子网掩码)
    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

    在上述示例中,我们配置了 NTP 服务器以允许本地服务器同步,并允许内网子网同步。你需要根据你的网络配置进行适当的修改。

  3. 启动和启用 NTP 服务

    使用以下命令启动 NTP 服务并将其设置为开机启动:

    复制代码
    sudo systemctl start ntpd
    sudo systemctl enable ntpd
  4. 防火墙配置

    如果你的 CentOS 服务器启用了防火墙,需要确保 UDP 123 端口对于 NTP 流量是开放的。你可以使用以下命令开放这个端口:

    复制代码
    sudo firewall-cmd --add-service=ntp --permanent
    sudo firewall-cmd --reload
  5. 测试 NTP 服务器

    你可以使用 ntpq 命令来测试你的 NTP 服务器。运行以下命令:

    复制代码
    ntpq -p

    这将显示 NTP 服务器的状态以及与其他 NTP 服务器的同步情况。

你的 CentOS 服务器现在应该已经成功搭建成内网的 NTP 时间服务器。其他内网计算机可以配置为使用该服务器进行时间同步,以确保内网设备的时间保持同步。

相关推荐
Macbethad10 分钟前
工业触摸屏技术指南:选型、难点与实战解决方案
服务器·前端·数据库
minihuabei22 分钟前
跨域拉镜像
linux
王 富贵1 小时前
【Linux】防火墙常用命令(iptables/firewalld/ufw)
linux·运维·服务器
写代码的【黑咖啡】1 小时前
Linux系统简介及常用命令分类详解
linux·运维·服务器
lang201509282 小时前
Sentinel限流核心:ThrottlingController设计详解
服务器·网络·sentinel
YFLICKERH2 小时前
【Linux系统】ubuntu 25.04 虚拟机联网与DNS域名问题排查案例
linux·ubuntu25.04
松涛和鸣2 小时前
DAY27 Linux File IO and Standard IO Explained: From Concepts to Practice
linux·运维·服务器·c语言·嵌入式硬件·ubuntu
GeniuswongAir2 小时前
飞牛NAS死机排查
linux·运维·服务器
hhcgchpspk2 小时前
linux查找并杀死进程部分方法
linux·运维·服务器·网络·经验分享
董世昌412 小时前
JavaScript 变量声明终极指南:var/let/const 深度解析(2025 版)
java·服务器·前端