Configure NTP in ESXi from the command line

Display NTP settings

~ # cat /etc/ntp.conf
restrict 127.0.0.1
restrict default kod nomodify notrap
driftfile /etc/ntp.drift

This is a freshly installed server and there’s no ntp server configured.

Configure NTP server

We will use NTP Pool Project servers.

# vi /etc/ntp.conf
# cat /etc/ntp.conf
restrict 127.0.0.1
restrict default kod nomodify notrap
server 0.pool.ntp.org
server 1.pool.ntp.org
driftfile /etc/ntp.drift

Restart NTP

~ # /etc/init.d/ntpd restart
Stopping ntpd
Starting ntpd

Display NTP peers

~ # ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
ns02.hns.net.in .INIT. 16 u - 64 0 0.000 0.000 0.000
123.108.200.124 .INIT. 16 u - 64 0 0.000 0.000 0.000

It could take sometime to sync.

~ # ntpq -p
 remote refid st t when poll reach delay offset jitter
 ==============================================================================
 +123.108.200.124 103.252.195.20 3 u 46 64 377 81.459 4.968 3.615
 *web10.hnshostin 158.43.128.33 2 u 44 64 377 38.879 5.120 5.157

Enable NTP service

~ # chkconfig ntpd on
~ # chkconfig --list | grep ntpd
ntpd on

Replace NTP server

sed -i 's/ntpserver/newntpserver/' /etc/ntp.conf

Remove NTP server

sed -i 's/ntpserver//' /etc/ntp.conf

Remove blank lines in ntp.conf

sed -i '/^\s*$/d' /etc/ntp.conf

Replace ntp.conf with new settings

    ~ # cat > /etc/ntp.conf
     restrict 127.0.0.1
     restrict default kod nomodify notrap
     server 0.pool.ntp.org
     server 1.pool.ntp.org
     driftfile /etc/ntp.drift
     EOF
 ~ # cat /etc/ntp.conf
 restrict 127.0.0.1
 restrict default kod nomodify notrap
 server 0.pool.ntp.org
 server 1.pool.ntp.org
 driftfile /etc/ntp.drift

Run the commands over ssh

 ssh root@servername "command_to_run"

Repeat the commands for multiple hosts over ssh

cat > server_list
Paste the list of servers
Ctrl+D
for i in `cat server_list`
do
ssh root@$i "command_to_run"
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s