NTP: how to chroot
NTP: how to chroot

The following bash script will automate the configuration of ntp to run in a jail (chroot) for a debian/ubuntu.

#!/bin/bash

/etc/init.d/ntp stop

rootfs=/var/chroot/ntp
mkdir -p $rootfs/{etc,var/lib/ntp,var/log}

mv /etc/ntp.conf $rootfs/etc
ln -s $rootfs/etc/ntp.conf /etc/ntp.conf

if [ -e /var/lib/ntp/ntp.drift ]; then
    mv /var/lib/ntp/ntp.drift $rootfs/var/lib/ntp
fi
ln -s $rootfs/var/lib/ntp/ntp.drift \
    /var/lib/ntp/ntp.drift
chown -R ntp:ntp $rootfs/var/lib/ntp

mv /var/log/ntpstats $rootfs/var/log
ln -s $rootfs/var/log/ntpstats /var/log/ntpstats
chown -R ntp:ntp $rootfs/var/log/ntpstats

sed -e "s,'-g','-4 -i /var/chroot/ntp -g'," \
    /etc/default/ntp > /tmp/x && \
    mv /tmp/x /etc/default/ntp

sed -e "s,restrict -6,#restrict -6," \
    -e "s,restrict ::1,#restrict ::1," \
    /etc/ntp.conf > /tmp/x && \
    mv /tmp/x /etc/ntp.conf

/etc/init.d/ntp start

To check if the chroot is well configured, you can execute this command :

# ps -ef | grep ntp
ntp        696     1  0 08:52 ?        00:00:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -4 -i /var/chroot/ntp -g -u 110:119

Reference

Source

Script source

Access Control Commands and Options

Authentication Commands and Options

Server Commands and Options

Monitoring Commands and Options

Reference Clock Commands and Options

Miscellaneous Commands and Options

NTP: how to chroot

Leave a Reply

Your email address will not be published. Required fields are marked *