This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set extension for custom DNS (#3264)
- Loading branch information
1 parent
9455a82
commit e0cb223
Showing
2 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
# Add support for registering host on dns server. Must allow non-secure updates | ||
|
||
set -e | ||
|
||
DOMAINNAME=$1 | ||
|
||
echo $(date) " - Starting Script" | ||
|
||
cat > /etc/network/if-up.d/register-dns <<EOFDHCP | ||
#!/bin/sh | ||
# only execute on the primary nic | ||
if [ "\${IFACE}" = "eth0" ] | ||
then | ||
ip=\$(ip address show eth0 | awk '/inet / {print \$2}' | cut -d/ -f1) | ||
host=\$(hostname -s) | ||
nsupdatecmds=/var/tmp/nsupdatecmds | ||
echo "update delete \${host}.${DOMAINNAME} a" > \$nsupdatecmds | ||
echo "update add \${host}.${DOMAINNAME} 3600 a \${ip}" >> \$nsupdatecmds | ||
echo "send" >> \$nsupdatecmds | ||
nsupdate \$nsupdatecmds | ||
fi | ||
EOFDHCP | ||
|
||
chmod 755 /etc/network/if-up.d/register-dns | ||
|
||
if ! grep -Fq "${DOMAINNAME}" /etc/dhcp/dhclient.conf | ||
then | ||
echo $(date) " - Adding domain to dhclient.conf" | ||
|
||
echo "supersede domain-name \"${DOMAINNAME}\";" >> /etc/dhcp/dhclient.conf | ||
echo "prepend domain-search \"${DOMAINNAME}\";" >> /etc/dhcp/dhclient.conf | ||
fi | ||
|
||
# service networking restart | ||
echo $(date) " - Restarting network" | ||
sudo ifdown eth0 && sudo ifup eth0 |