From ffd25cdb04f6a40bc9b95afd507042717b2f7fc5 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 10 Jul 2025 10:36:10 +0300 Subject: Generate specific dhclient.conf to coerce the ISP to offer the same IP --- templates/usr_local_bin_gen_dhclient_conf.sh.j2 | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 templates/usr_local_bin_gen_dhclient_conf.sh.j2 (limited to 'templates/usr_local_bin_gen_dhclient_conf.sh.j2') diff --git a/templates/usr_local_bin_gen_dhclient_conf.sh.j2 b/templates/usr_local_bin_gen_dhclient_conf.sh.j2 new file mode 100644 index 0000000..8c05f70 --- /dev/null +++ b/templates/usr_local_bin_gen_dhclient_conf.sh.j2 @@ -0,0 +1,38 @@ +#!/bin/sh + +set -eu + +IP=$(ifconfig wan0 | awk '/inet / {print $2}' | head -n1) +HOSTNAME=$(hostname) +CONFFILE=/etc/dhclient.conf +NEWFILE=$(mktemp) +if [ -f "${CONFFILE}" ]; then + OLDHASH=$(md5 -q "${CONFFILE}") +else + OLDHASH="doesnotexist" +fi + +cat < "${NEWFILE}" +# This file is generated by $0 periodically. +# Changes will be overwritten. + +interface "wan0" { + send host-name "${HOSTNAME}"; +EOF + +if [ ! -z "$IP" ]; then +cat <> "${NEWFILE}" + send dhcp-requested-address $IP; +EOF +fi + +echo "}" >> "${NEWFILE}" + +mv "${NEWFILE}" "${CONFFILE}" + +# If changed, restart dhclient wan0 +md5 -c "${OLDHASH}" "${CONFFILE}" 1>/dev/null 2>/dev/null +if [ ! "$?" = 0 ]; then + echo "Generated ${CONFFILE} has changed, restarting dhclient on wan0 (IP: ${IP})" + service dhclient restart wan0 +fi -- cgit v1.3