一.安裝ntp軟件
1.檢查是否安裝了ntp相關包。
rpm -qa | grep ntp
2.安裝ntp軟件。
yum -y install ntp
二.參數講解
ignore :關閉所有的 NTP 聯機服務
nomodify:客戶端不能更改服務端的時間參數,但是客戶端可以通過服務端進行網絡校時。
notrust :客戶端除非通過認證,否則該客戶端來源將被視為不信任子網
noquery :不提供客戶端的時間查詢:用戶端不能使用ntpq,ntpc等命令來查詢ntp服務器
notrap :不提供trap遠端登陸:拒絕為匹配的主機提供模式 6 控制消息陷阱服務。陷阱服務是 ntpdq 控制消息協議的子系統,用于遠程事件日志記錄程序。
nopeer :用于阻止主機嘗試與服務器對等,并允許欺詐性服務器控制時鐘
kod : 訪問違規時發送 KoD 包。
三.修改配置文件
1.查看未修改的配置文件
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor
1.設置允許任何IP的客戶機都可以進行時間同步(修改后的配置文件)
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/driftrestrict default nomodify notraprestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor
2.只允許192.168.1.0網段的客戶機進行時間同步(修改后的配置文件)
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1restrict 192.168.1.0 mask 255.255.255.0 nomodify notrapserver 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor
四.啟動NTP服務和防火墻
systemctl start ntpd
systemctl enable ntpd
iptables -A INPUT -p UDP -i eno16777736 -s 192.168.1.0/24 --dport 123 -j ACCEPT
setsebool -P ntp_disable_trans 1#SELinux設置
vi /etc/sysconfig/ntpd#允許BIOS與系統時間同步,添加下面一行。
SYNC_HWCLOCK=yes
五.檢測NTP
1.檢測NTP服務是否運行
# netstat -tlunp | grep ntpudp 0 0 192.168.1.101:123 0.0.0.0:* 2563/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 2563/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 2563/ntpd udp6 0 0 fe80::20c:29ff:fe7b:123 :::* 2563/ntpd udp6 0 0 ::1:123 :::* 2563/ntpd udp6 0 0 :::123 :::* 2563/ntpd
新聞熱點
疑難解答