linux時間同步ntp和rdate

一 、 ntpdate工具和ntp服務

ntp服務,走的是udp協議,默認端口爲123。

安裝vim

#yum install ntp -y

設置centos

#vim /etc/ntp.conf

添加和修改:bash

restrict 192.168.11.0 mask 255.255.255.0 notrust nomodify notrap
server 0.centos.pool.ntp.org iburst

server的地址能夠改爲國內的某個時間服務器的地址服務器

啓動:tcp

#service ntpd start
#chkconfig ntpd on
#chkconfig ntpd --list

防火牆:工具

iptables -I INPUT 4 -p tcp --dport 123 -j ACCEPT
iptables -I INPUT 4 -p udp --dport 123 -j ACCEPT
iptables -I INPUT 4 -p tcp --sport 123 -j ACCEPT
iptables -I INPUT 4 -p udp --sport 123 -j ACCEPT

iptables -A OUTPUT -p tcp --sport 123 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 123 -j ACCEPT
iptables -A OUTPUT -p udp --sport 123 -j ACCEPT
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT

service iptables status

#根據本身需求來

使用:spa

#ntpdate 192.168.11.201

 

 

二 、rdate工具和time服務

​​​​​​​(time-dgram和time-stream,分別是upd和tcp協議的time服務)
time服務有2種分別是udp和tcp協議,默認端口37。

 安裝:rest

#yum install xinetd -y

 設置:code

vim /etc/xinetd.d/time-stream 
vim /etc/xinetd.d/time-dgram
把默認的disable = yes改成disable = no

啓動:server

#service xinetd start
#telnet 127.0.0.1 37

防火牆:

#iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 37 -j ACCEPT
#iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --sport 37 -j ACCEPT
#service iptables status
#service iptables save

使用:

#rdate -s 192.168.11.221
相關文章
相關標籤/搜索