{"id":43,"date":"2023-07-11T21:25:59","date_gmt":"2023-07-11T21:25:59","guid":{"rendered":"http:\/\/thejonas.net\/?page_id=43"},"modified":"2023-07-13T20:32:47","modified_gmt":"2023-07-14T03:32:47","slug":"dns-and-dhcp","status":"publish","type":"page","link":"https:\/\/www.thejonas.net\/?page_id=43","title":{"rendered":"DNS and DHCP"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">DNS DHCP<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">DNS: with Bind9 \/ DHCP <strong><em>\u201cUbuntu 14.04 and *Ubuntu 18.04<\/em> <em>LTS\u201d<\/em><\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Domain info<\/li>\n\n\n\n<li>server hostname: <strong>dcsrv<\/strong><\/li>\n\n\n\n<li>search-domain <strong>abc.lan<\/strong><\/li>\n\n\n\n<li>Domain Realm <strong>mydc<\/strong><em>\u201cfor the next tutorial setting up samba4\u201d<\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Edit host file: nano \/etc\/hosts\/\n127.0.0.1 localhost\n127.0.0.1 dcsrv.adc.lan dcsrv\n10.0.2.99 ns.abc.lan ns\n10.0.2.99 mydc.acb.lan mydc<\/strong><\/pre>\n\n\n\n<p>&nbsp;Setup static IP:&nbsp; \/etc\/network\/interfaces<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">auto eth0\niface eth0 inet static\n   address 10.1.200.3\n   gateway 10.1.200.1\n   netmask 255.255.255.0\n   dns-nameservers  8.8.8.8<\/pre>\n\n\n\n<p>Update your system, then reboot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo apt-get update\nsudo apt-get dist-upgrade\nsudo reboot\n<\/strong><\/pre>\n\n\n\n<p>Install Bind9 and DHCP.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo apt-get install isc-dhcp-server bind9<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;Configuring DNS<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo nano \/etc\/bind\/named.conf.options\n<\/strong> \n<em><strong>acl internals {<\/strong><\/em><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><em><strong>    localhost;\n    localnets;\n};<\/strong><\/em>\n&nbsp;\noptions {\n   directory \"\/var\/cache\/bind\";\n&nbsp;\n   \/\/ If there is a firewall between you and nameservers you want\n   \/\/ to talk to, you may need to fix the firewall to allow multiple\n   \/\/ ports to talk.  See http:\/\/www.kb.cert.org\/vuls\/id\/800113\n&nbsp;\n   \/\/ If your ISP provided one or more IP addresses for stable\n   \/\/ nameservers, you probably want to use them as forwarders.\n   \/\/ Uncomment the following block, and insert the addresses replacing\n   \/\/ the all-0's placeholder.\n&nbsp;\n  <strong> forwarders {\n       \/\/ DNS to the internet you could also add the DNS servers from your ISP\n       8.8.8.8;\n   };<\/strong>\n   allow-query {\n      internals;\n   };\n   \/\/ restrict recursion\n   allow-recursion {\n      internals;\n   };\n   allow-transfer {\n      internals;\n   };\n   \/\/========================================================================\n   \/\/ If BIND logs error messages about the root key being expired,\n   \/\/ you will need to update your keys.  See https:\/\/www.isc.org\/bind-keys\n   \/\/========================================================================\n   \/\/ turn off zone encryption. The auto flag still generates warnings in the log file\n   <strong>dnssec-enable no;<\/strong>\n   <strong>\/\/ dnssec-validation auto;\n&nbsp;\n   listen-on-v6 { any; };\n   auth-nxdomain no;    # conform to RFC1035\n};<\/strong><\/pre>\n\n\n\n<p>The installation process creates the crypto file needed when the new DHCP server communicates with the DNS server. The command below creates a file <strong>\/etc\/bind\/rndc.key<\/strong> which replaces the file generated by the install process.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">To view current rndc-key file created during the install:\n<strong>nano \/etc\/bind\/rndc.key<\/strong>\nExample of rndc-key below:\n<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">key \"rndc-key\" {\n  algorithm hmac-md5;\n  secret \"wrhfunsh45k\/wodkqtfhsnv==\";\n};<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Recommend to change key using this command:\n<strong>sudo<\/strong><strong> \/usr\/sbin\/rndc-confgen -a<\/strong><\/pre>\n\n\n\n<p>Set permissions on key to keep it safe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo chown root:bind \/etc\/bind\/rndc.key\nsudo chmod 640 \/etc\/bind\/rndc.key<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Adding DNS Zones<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/bind\/named.conf.local<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/\n\/\/ Do any local configuration here\n\/\/\n<strong>include \"\/etc\/bind\/rndc.key\";\n&nbsp;\nzone \"abc.lan\" {\n     type master;\n     file \"\/var\/lib\/bind\/abc.lan.zone\";\n     allow-update { key rndc-key; };\n};\n&nbsp;\n\nzone \"2.0.10.in-addr.arpa\" {\n     type master;\n     file \"\/var\/lib\/bind\/abc.lan.rev.zone\";\n     allow-update { key rndc-key; };\n};<\/strong>\n&nbsp;\n\/\/ Consider adding the 1918 zones here, if they are not used in your\n\/\/ organization\n\/\/include \"\/etc\/bind\/zones.rfc1918\";<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo nano \/var\/lib\/bind\/abc.lan.zone<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">$ORIGIN .\n$TTL 907200\t; 1 week 3 days 12 hours\nabc.lan\t\tIN SOA\tns.abc.lan. admin.abc.lan. (\n\t\t\t\t2014071403 ; serial\n\t\t\t\t28800      ; refresh (8 hours)\n\t\t\t\t3600       ; retry (1 hour)\n\t\t\t\t604800     ; expire (1 week)\n\t\t\t\t38400      ; minimum (10 hours 40 minutes)\n\t\t\t\t)\n\t\t\tNS\tns.abc.lan.\n$ORIGIN abc.lan.\nrouter01\t\tA\t10.0.2.1\nns                      A       10.0.2.99\ndnsserver               CNAME   ns\nmydc                    CNAME   ns<\/pre>\n\n\n\n<p>Reverse lookup zone:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo nano \/var\/lib\/bind\/abc.lan.rev.zone<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">$ORIGIN .\n$TTL 907200\t; 1 week 3 days 12 hours\n2.0.10.in-addr.arpa IN SOA\tns.abc.lan. admin.abc.lan. (\n\t\t\t\t2014071402 ; serial\n\t\t\t\t28800      ; refresh (8 hours)\n\t\t\t\t604800     ; retry (1 week)\n\t\t\t\t604800     ; expire (1 week)\n\t\t\t\t86400      ; minimum (1 day)\n\t\t\t\t)\n\t\t\tNS\tns.abc.lan.\n$ORIGIN 2.0.10.in-addr.arpa.\n1\t\t\tPTR\trouter01.abc.lan.\n<strong>3                                            <\/strong> PTR     mydc.abc.lan\n3                       PTR     dnsserver.abc.lan\n                        PTR     abc.lan<\/pre>\n\n\n\n<p>Change the permissions on the two new zone files that were created.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo chown root:bind \/var\/lib\/bind\/*zone<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo service bind9 restart<\/strong><\/pre>\n\n\n\n<p>DHCP Configuration<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/dhcp\/dhcpd.conf\nRemove your current information in the dhcp.conf and add the\ninformation below; then modify to your needs.<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">ddns-updates on;\nddns-update-style interim;\nupdate-static-leases on;\nauthoritative;\ninclude \"\/etc\/dhcp\/ddns-keys\/rndc.key\";\nallow unknown-clients;\nuse-host-decl-names on;\ndefault-lease-time 86400; #24  hours\nmax-lease-time 86400; #21 hours\nlog-facility local7;\n&nbsp;\n<strong># abd.lan DNS zones\nzone abc.lan.<\/strong> {\n<strong>  primary 127.0.0.1; # This server is the primary DNS server for the zone\n  key rndc-key;       # Use the key we defined earlier for dynamic updates\n<em>}<\/em><em>\nzone 2.0.10.in-addr.arpa. {\n  primary 127.0.0.1; # This server is the primary reverse DNS server for the zone\n  key rndc-key;       # Use the key we defined earlier for dynamic updates\n}<\/em><\/strong>\n&nbsp;\n<em><strong># abc.lan LAN range\nsubnet 10.0.2.0 netmask 255.255.255.0<\/strong><\/em> {\n  <em><strong>range 10.0.2.100 10.0.2.200;\n  option subnet-mask 255.255.255.0;\n  option routers 10.0.2.1;\n  option domain-name-servers 10.0.2.99;\n  option domain-name \"abc.lan\";\n  ddns-domainname \"abc.lan.\";\n  ddns-rev-domainname \"2.0.10.in-addr.arpa.\";\n<\/strong><\/em><strong>}<\/strong>\n&nbsp;\n<\/pre>\n\n\n\n<p>Apply these commands to create some links and set permissions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sudo ln \/etc\/bind\/rndc.key \/etc\/dhcp\/ddns-keys\/rndc.key\nsudo ls -l \/etc\/dhcp\/ddns-keys\/rndc.key\nsudo chown root:bind \/etc\/dhcp\/ddns-keys\/rndc.key<\/strong><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>restart services<\/strong><\/li>\n\n\n\n<li><strong>sudo service bind9 restart<\/strong><\/li>\n\n\n\n<li><strong>sudo service isc-dhcp-server restart<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Next, let\u2019s build a Samba4 domain controller around the DNS\/DHCP server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DNS DHCP DNS: with Bind9 \/ DHCP \u201cUbuntu 14.04 and *Ubuntu 18.04 LTS\u201d Edit host file: nano \/etc\/hosts\/ 127.0.0.1 localhost 127.0.0.1 dcsrv.adc.lan dcsrv 10.0.2.99 ns.abc.lan ns 10.0.2.99 mydc.acb.lan mydc &nbsp;Setup static IP:&nbsp; \/etc\/network\/interfaces auto eth0 iface eth0 inet static address &hellip; <a href=\"https:\/\/www.thejonas.net\/?page_id=43\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":37,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-43","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/pages\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejonas.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43"}],"version-history":[{"count":2,"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/pages\/43\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/pages\/43\/revisions\/83"}],"up":[{"embeddable":true,"href":"https:\/\/www.thejonas.net\/index.php?rest_route=\/wp\/v2\/pages\/37"}],"wp:attachment":[{"href":"https:\/\/www.thejonas.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}