aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/make-dhcpd.pl
diff options
context:
space:
mode:
authorJoachim Tingvold <joachim@tingvold.com>2015-03-22 01:09:11 +0100
committerJoachim Tingvold <joachim@tingvold.com>2015-03-22 01:09:11 +0100
commit243410cc84d24d28a2625c7718acf6cb75e90978 (patch)
treee4bd61803492d82a92bfb6eb9609c9ec13f2d5f0 /bootstrap/make-dhcpd.pl
parent6669f020b17779cc6767a30ca2e7c51de766b9b8 (diff)
Added DHCP6-support.
Diffstat (limited to 'bootstrap/make-dhcpd.pl')
-rwxr-xr-xbootstrap/make-dhcpd.pl66
1 files changed, 55 insertions, 11 deletions
diff --git a/bootstrap/make-dhcpd.pl b/bootstrap/make-dhcpd.pl
index 802c2ad..d5f49cc 100755
--- a/bootstrap/make-dhcpd.pl
+++ b/bootstrap/make-dhcpd.pl
@@ -21,42 +21,86 @@ my $dhcpd_wlc_conf = $dhcpd_base . "v4-wlc.conf";
my $dhcpd_voip_conf = $dhcpd_base . "v4-voip.conf";
# primary
-my $pri_range = Net::IP->new($nms::config::pri_net) or die ("pri_range fail");
+my $pri_range = Net::IP->new($nms::config::pri_net_v4) or die ("pri_range fail");
my $pri_mask = $pri_range->mask();
my $pri_net = $pri_range->ip();
# secondary
-my $sec_range = Net::IP->new($nms::config::sec_net) or die ("sec_range fail");
+my $sec_range = Net::IP->new($nms::config::sec_net_v4) or die ("sec_range fail");
my $sec_mask = $sec_range->mask();
my $sec_net = $sec_range->ip();
+(my $sec_last = NetAddr::IP->new($v4_net)->last()) =~ s/\/[0-9]{1,2}//;
+(my $sec_gw = NetAddr::IP->new($v4_net)->first()) =~ s/\/[0-9]{1,2}//;
+my $sec_num = NetAddr::IP->new($v4_net)->num();
+my $sec_n = $sec_num - int($sec_num / 4); # don't use more than 1/4 of the net for DHCP
+(my $sec_first = NetAddr::IP->new($v4_net)->nth($sec_n)) =~ s/\/[0-9]{1,2}//;
-# Create PXE-boot configuration file for DHCP
+# Create main configuration file for DHCP
if ( not -f $dhcpd_conf )
{
print STDERR "Creating file " . $dhcpd_conf . "\n";
open DHCPDFILE, ">" . $dhcpd_conf or die ( $! . " " . $dhcpd_conf);
+ my $network = Net::IP->new($v4_net)->ip();
+ my $netmask = Net::IP->new($v4_net)->mask();
+ (my $first = NetAddr::IP->new($v4_net)->nth(3)) =~ s/\/[0-9]{1,2}//; # we reserve the three first addresses
+ (my $last = NetAddr::IP->new($v4_net)->last()) =~ s/\/[0-9]{1,2}//;
+ (my $gw = NetAddr::IP->new($v4_net)->first()) =~ s/\/[0-9]{1,2}//;
+
print DHCPDFILE <<"EOF";
# GENERATED BY make-dhcpd.pl
-#
-# Central concept: as little config in the main .conf,
-# include almost everything from separate files..
-#
-# log-facility local7;
-option domain-name "$nms::config::tgname.gathering.org";
-option domain-name-servers $nms::config::pri_v4, $nms::config::sec_v4;
+
+# 60 min leasetime, 120 min max
default-lease-time 3600;
max-lease-time 7200;
+
+# make server authorative
authoritative;
+# Don't let clients set their own FQDN
+ignore client-updates;
+
+# enable DDNS
ddns-update-style interim;
+
+# set ddns-hostname
+if exists host-name {
+ ddns-hostname = lcase(option host-name);
+} elsif exists fqdn.hostname {
+ ddns-hostname = lcase(option fqdn.hostname);
+} else {
+ ddns-hostname = binary-to-ascii(10, 8, "-", leased-address);
+}
+
+# Domain name (unless overriden elsewhere)
+option domain-name "$nms::config::tgname.gathering.org";
+option domain-name-servers $nms::config::pri_v4, $nms::config::sec_v4;
+
key DHCP_UPDATER {
algorithm HMAC-MD5.SIG-ALG.REG.INT;
secret $nms::config::ddns_key;
}
+# Servernetwork, Tele
subnet $pri_net netmask $pri_mask {}
-subnet $sec_net netmask $sec_mask {}
+
+# Servernetwork, NOC
+# Add small range at the end for PXE
+subnet $sec_net netmask $sec_mask {
+ option subnet-mask $sec_mask;
+ option routers $sec_gw;
+
+ # No DDNS
+ ddns-updates off;
+ ddns-hostname = none;
+ ddns-domainname = none;
+
+ # supershort leasetime
+ default-lease-time 300;
+ max-lease-time 600;
+
+ range $sec_first $sec_last;
+}
include "/etc/dhcp/v4-revzones.conf";
include "/etc/dhcp/v4-generated-include.conf";