Created
January 13, 2016 21:24
-
-
Save paulc/25febe2101ac0a238a3a to your computer and use it in GitHub Desktop.
dhclient-exit-hoot to reconfigure SSHD ListenAddress if IP address changes
This file contains hidden or 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
# Reconfigure SSHD ListenAddress if ip address changes | |
LOGGER="/usr/bin/logger -s -p user.notice -t dhclient-exit-hook" | |
old_ip_address=$(sysrc -n sshd_flags | \ | |
sed -e 's/.*ListenAddress=\([0-9\.]*\) .*/\1/') | |
$LOGGER "($reason) SSHD ListenAddress ${old_ip_address} -> ${new_ip_address}" | |
if [ ! -z "${new_ip_address}" -a "${old_ip_address}" != "${new_ip_address}" ] | |
then | |
sshd_flags=$(sysrc -n sshd_flags | \ | |
sed -e "s/\(ListenAddress=\)[0-9\.]*/\1${new_ip_address}/") | |
$LOGGER Reconfiguring SSHD flags: \"$sshd_flags\" | |
sysrc sshd_flags="$sshd_flags" | |
$LOGGER Restarting SSHD | |
service sshd restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment