blob: d5d21c2c019eabe62ced3eb46320c358fdc6630f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/sh
# Ensure that NTP servers obtained from DHCP are made available to chronyd and
# that they are removed when releasing the DHCP lease.
set -e
added_servers="/run/chrony-helper/added_servers"
prepare_iface() {
modprobe dummy
ip link add name dummy0 type dummy
ip address add 192.168.1.1/24 dev dummy0
ip link set dev dummy0 up
}
dhcpd_config() {
cat <<EOF > /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
authorative;
subnet 192.168.1.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option ntp-servers 192.168.1.50;
range 192.168.1.42 192.168.1.100;
}
EOF
sed -i 's/INTERFACESv4=""/INTERFACESv4="dummy0"/' /etc/default/isc-dhcp-server
}
printf "Preparing the dummy network interface and dhcpd configuration…\n"
if prepare_iface && dhcpd_config; then
systemctl restart isc-dhcp-server && dhclient dummy0 && printf "Done!\n\n"
fi
printf "Check if the NTP server is made available to chronyd…\n"
grep -q 192.168.1.50 $added_servers && printf "SUCCESS!\n\n"
printf "Release the current lease and check if the NTP server has been correctly removed…\n"
dhclient -r dummy0 > /dev/null 2>&1 && [ ! -d "$added_servers" ] && printf "SUCCESS!\n\n"
|