Skip to content

Instantly share code, notes, and snippets.

@brandocorp
Last active May 1, 2019 00:20
Show Gist options
  • Save brandocorp/f762139d53cf3344f5c1 to your computer and use it in GitHub Desktop.
Save brandocorp/f762139d53cf3344f5c1 to your computer and use it in GitHub Desktop.
Ghetto DDNS
#! /bin/bash
#
# ddns Apply DDNS Configuration on first boot
#
# chkconfig: 2345 09 90
# description: Applies DDNS configuration to DHCP network interfaces
#
# Source function library.
. /etc/init.d/functions
CWD=$(pwd)
cd /etc/sysconfig/network-scripts
. ./network-functions
# find all the interfaces besides loopback.
# ignore aliases, alternative configurations, and editor backup files
interfaces=$(ls ifcfg* | \
LANG=C sed -e "$__sed_discard_ignored_files" \
-e '/\(ifcfg-lo$\|:\|ifcfg-.*-range\)/d' \
-e '/ifcfg-[A-Za-z0-9#\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \
LANG=C sort -k 1,1 -k 2n | \
LANG=C sed 's/ //')
rc=0
[ "$EUID" != "0" ] && exit 4
rc=0
vlaninterfaces=""
xdslinterfaces=""
bridgeinterfaces=""
# add the short hostname to the interface configuration as the value for DHCP_HOSTNAME
for i in $interfaces; do
unset DEVICE TYPE SLAVE
eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
eval $(LANG=C fgrep "SLAVE=" ifcfg-$i)
if [ -z "$DEVICE" ] ; then
DEVICE="$i"; fi
if LANG=C egrep -L "^DHCP_HOSTNAME=" ifcfg-$i >/dev/null 2>&1 ; then
sed -i '/DHCP_HOSTNAME/d' ifcfg-$i
fi
sed -i '/BOOTPROTO/a DHCP_HOSTNAME='"$(hostname -s)" ifcfg-$i
[ $? -ne 0 ] && rc=1
done
exit $rc
# vSphere is managing the bulk of this file
HWADDR=00:50:56:8c:8e:3e
NAME=eth1
DNS1=10.250.4.50
DEVICE=eth1
ONBOOT=yes
USERCTL=no
BOOTPROTO=dhcp
DHCP_HOSTNAME=vm-0
PEERDNS=no
check_link_down() {
return 1;
}
$ORIGIN .
$TTL 38400 ; 10 hours 40 minutes
private.net IN SOA ddns.priate.net. root.ddns.private.net. (
16 ; serial
10800 ; refresh (3 hours)
3600 ; retry (1 hour)
604800 ; expire (1 week)
38400 ; minimum (10 hours 40 minutes)
)
NS ddns.private.net.
A 10.250.4.50
$ORIGIN private.net.
ddns A 10.250.4.50
$ORIGIN .
$TTL 86400 ; 1 day
1.1.10.in-addr.arpa IN SOA private.net. ddns.private.net. (
16 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
2419200 ; expire (4 weeks)
86400 ; minimum (1 day)
)
NS ddns.private.net.
$ORIGIN 1.1.10.in-addr.arpa.
1 PTR ddns.private.net.
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
include "/etc/rndc.key";
zone private.net. {
primary 10.1.1.1;
key rndc-key;
}
zone 1.1.10.in-addr.arpa. {
primary 10.1.1.1;
key rndc-key;
}
ddns-updates on;
ddns-domainname "private.net";
ddns-update-style interim;
allow client-updates;
lease-file-name "/var/lib/dhcpd/dhcpd.leases";
authoritative;
default-lease-time 86400; # 24 Hours
max-lease-time 172800; # 48 Hours
subnet 10.1.1.0 netmask 255.255.255.0 {
allow client-updates;
allow unknown-clients;
ddns-updates on;
ddns-domainname "private.net";
ddns-rev-domainname "in-addr.arpa";
ddns-update-style interim;
option subnet-mask 255.255.255.0;
option domain-name "private.net";
option domain-name-servers 10.1.1.1;
range dynamic-bootp 10.1.1.5 10.1.1.250;
}
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
include "/etc/rndc.key";
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "private.net" IN {
type master;
file "dynamic/db.private.net";
allow-update { key rndc-key; };
};
zone "1.1.10.in-addr.arpa" IN {
type master;
file "dynamic/db.reverse-10.1.1";
allow-update { key rndc-key; };
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
// include "/etc/named.rfc1912.zones";
// include "/etc/named.root.key";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment