Last active
January 12, 2023 05:45
-
-
Save paul-chambers/b114fb9aa7841559c380475231fbd666 to your computer and use it in GitHub Desktop.
/etc/dhcp/dhclient-enter-hooks.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some custom Scripts to update things that depend on the WAN IP address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This script is meant to be called by dhclient from /etc/dhcp/dhclient-enter-hooks.d/ | |
# | |
# It writes a config file for dnsmasq to injest for settings that are wan/isp-specific | |
# | |
# Tips: | |
# * Be careful about changing the environment since this is sourced | |
# * This script fragment uses bash features | |
# | |
_dest="/etc/dnsmasq.d/isp.conf" | |
case "${reason}" in | |
BOUND|RENEW|REBIND|REBOOT) | |
_lan_ip=$(ip addr show dev lanbr | sed -n -e '1,5 s/ *inet \([0-9\.]*\).*/\1/ p') | |
echo "# Do Not Edit - automatically generated\n" > "${_dest}" | |
echo "alias=${new_ip_address},${_lan_ip}\n" >> "${_dest}" | |
_isp_domains=$( expr match "${new_domain_name}" ".*\.\([^\.]*\.[^\.]*\)\." ) | |
case "${_isp_domains}" in | |
"comcast.net") | |
_isp_domains="comcast.net comcast.com xfinity.net xfinity.com" | |
;; | |
esac | |
for _isp_domain in ${_isp_domains} | |
do | |
for _dns_ip in ${new_domain_name_servers} | |
do | |
echo "server=/${_isp_domain}/${_dns_ip}" >> "${_dest}" | |
done | |
unset _dns_ip | |
echo "ipset=/${_isp_domain}/isp,isp6\n" >> "${_dest}" | |
done | |
unset _isp_domain | |
unset _isp_domains | |
unset _lan_ip | |
systemctl restart dnsmasq.service | |
;; | |
esac | |
unset _dest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This script is meant to be called from the /etc/dhcp/dhclient-enter-hooks.d/ | |
# | |
# It prods inadyn, if it's installed, to update public IP just assigned in the | |
# dynamic DNS service(s) that inadyn is configured to upate. | |
# | |
# Tips: | |
# * Be careful about changing the environment since this is sourced | |
# * This script fragment uses bash features | |
# | |
case "$reason" in | |
BOUND|RENEW|REBIND|REBOOT) | |
/usr/sbin/inadyn --once --foreground --syslog | |
;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This script is meant to be called from the /etc/dhcp/dhclient-enter-hooks.d/ | |
# It updates a set of aliases with the first few hops as reported by traceroute | |
# so that they can be included in your smokeping configuration, but will be | |
# updated when the DHCP lease changes. | |
# | |
# Tips: | |
# * Be careful about changing the environment since this is sourced | |
# * This script fragment uses bash features | |
# | |
logger "dhclient script: ${reason} ${new_ip_address}" | |
destination="/var/lib/smokeping/firsthops.inc" | |
case "$reason" in | |
BOUND|RENEW|REBIND|REBOOT) | |
gateway=$(ip route list | sed -n -e 's/default via \([0-9\.]*\) dev \(.*\)/\1/p') | |
echo "@define gateway ${gateway}" > "${destination}" | |
counter=1 | |
for hop in $(/usr/sbin/traceroute -m 4 -n 8.8.8.8 | /usr/bin/sed -n -e '2,5 s/ *[0-9] *\([0-9.]*\) .*$/\1/ p') | |
do | |
echo "@define hop-${counter} ${hop}" | |
counter=$((counter+1)) | |
done >> "${destination}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment