<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BIND &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/bind/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Thu, 05 Nov 2020 22:05:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>CentOS: Install an authoritative DNS server (BIND)</title>
		<link>https://blog.andreev.it/2018/12/141-centos-install-an-authoritative-dns-server-bind/</link>
					<comments>https://blog.andreev.it/2018/12/141-centos-install-an-authoritative-dns-server-bind/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 19 Dec 2018 20:50:09 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[BIND]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[DNS]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=4219</guid>

					<description><![CDATA[In this post I&#8217;ll explain how to install and configure BIND DNS server to&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll explain how to install and configure BIND DNS server to act as an authoritative server for a public domain in a master/slave configuration. This is not a setup for a server that will act as a DNS server in your local environment and does DNS resolution for your local network. In this post, the DNS server won&#8217;t resolve any DNS queries except for the domain that it is authoritative. The domain that I&#8217;ll use is <strong>cloudwerk.us</strong> registered with Go Daddy, so some of the configurations will apply to Go Daddy only. The IPs and keys that I&#8217;ll use will be visible. The setup will be gone by the time you read this.<br />
So, I have my master server, <strong>ns1.cloudwerk.us (67.205.160.87)</strong> and the slave server <strong>ns2.cloudwerk.us (104.248.184.142)</strong>.<br />
I will be using CentOS 7.5 and BIND 9.9.4-72. Before you start, make sure you have your domain purchased and you have 2 servers with public IPs up and running. You can leave the default registrant&#8217;s DNS servers for now. </p>
<h1>Installation, startup and control</h1>
<p>First, I&#8217;ll install BIND on both servers. All commands below are executed as root.</p>
<pre class="brush: bash; title: ; notranslate">
yum -y install bind
</pre>
<p>Then, we have to configure the <strong>rndc (Remote Name Daemon Control) </strong>utility. This utility allows management of the <strong>named </strong>(DNS) daemon. Moreover, you can manage remote DNS servers and I&#8217;ll explain how. So, let&#8217;s create the keys (highlighted line is what you type, the rest is output). DO this on the master server only.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
rndc-confgen -a -r /dev/urandom 
wrote key file &quot;/etc/rndc.key&quot; 
</pre>
<p>As you can see, there is a file called <strong>rndc.key</strong> created under <strong>/etc</strong> directory. This is the default directory where BIND expects to find its config files. The zone files are under <strong>/var</strong>.<br />
Now, copy this file to the second server in the same location. You can use scp, copy &#038; paste in a terminal session, it doesn&#8217;t matter. What matters is that you have to change the permissions and the owner of the file. BIND runs under the <strong>named </strong>user, not root. Do this on both servers. </p>
<pre class="brush: bash; title: ; notranslate">
cd /etc
chown root:named rndc.key
chmod 640 rndc.key
</pre>
<p>Let&#8217;s make sure that BIND starts on boot. On both servers, execute:</p>
<pre class="brush: bash; title: ; notranslate">
systemctl enable named  
</pre>
<p>Now, we can start the BIND daemon on both. </p>
<pre class="brush: bash; title: ; notranslate">
systemctl start named 
</pre>
<p>Check the logs.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
tail /var/log/messages
Dec 19 16:33:40 master named&#x5B;1308]: zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
Dec 19 16:33:40 master named&#x5B;1308]: zone localhost.localdomain/IN: loaded serial 0
Dec 19 16:33:40 master named&#x5B;1308]: zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
Dec 19 16:33:40 master named&#x5B;1308]: all zones loaded
Dec 19 16:33:40 master named&#x5B;1308]: running
Dec 19 16:33:40 master systemd: Started Berkeley Internet Name Domain (DNS).
Dec 19 16:33:40 master systemd: Reached target Host and Network Name Lookups.
Dec 19 16:33:40 master systemd: Starting Host and Network Name Lookups.
Dec 19 16:33:40 master named&#x5B;1308]: network unreachable resolving './DNSKEY/IN': 2001:500:84::b#53
Dec 19 16:33:40 master named&#x5B;1308]: network unreachable resolving './NS/IN': 2001:500:84::b#53
</pre>
<p>We can&#8217;t start the server with the <strong>rndc </strong>utility, but we can stop it if needed with <strong>rndc stop</strong> or simply <strong>systemctl stop named</strong>.<br />
To control the slave server from the master, we have to modify the main BIND configuration file, <strong>named.conf</strong> on the slave server. Also, the keys have to be the same, but we already took care of that part above.<br />
So, in the same <strong>/etc</strong> directory, edit <strong>named.conf</strong> and add these lines, right before the <strong>options </strong>directive. Do this on the slave server, not the master.</p>
<pre class="brush: bash; title: ; notranslate">
include &quot;/etc/rndc.key&quot;;

controls {
        inet 127.0.0.1 allow { localhost; } keys { &quot;rndc-key&quot;; };
        inet 104.248.184.142 allow { 67.205.160.87; } keys { &quot;rndc-key&quot;; };
};
</pre>
<p>If you look at my IPs above, this means that the rndc utility will be accepted from the localhost and from the the IP 67.205.160.87 which is the master server. But, we also have to tell BIND to listen on the public IP. By default, it listens on the <strong>localhost </strong>only.<br />
Do this on BOTH servers. In <strong>named.conf</strong> find the <strong>options </strong>directive and modify the <strong>listen-on</strong> option so it looks like this. You should put the public IP of each server there, so the line will differ on both servers. </p>
<pre class="brush: bash; title: ; notranslate">
//Master server
listen-on       { 127.0.0.1; 67.205.160.87; };
</pre>
<pre class="brush: bash; title: ; notranslate">
//Slave server
listen-on       { 127.0.0.1; 104.248.184.142; };
</pre>
<p>Allow traffic on the firewalls if you have them enabled. Do this on both.</p>
<pre class="brush: bash; title: ; notranslate">
firewall-cmd --add-port=53/tcp --permanent 
firewall-cmd --add-port=53/udp --permanent 
</pre>
<p>On the master node, do this.</p>
<pre class="brush: bash; title: ; notranslate">
firewall-cmd --permanent --zone=public --add-rich-rule=' 
  rule family=&quot;ipv4&quot; 
  source address=&quot;104.248.184.142/32&quot; 
  port protocol=&quot;tcp&quot; port=&quot;953&quot; accept'
</pre>
<p>On the slave node, do this.</p>
<pre class="brush: bash; title: ; notranslate">
firewall-cmd --permanent --zone=public --add-rich-rule=' 
  rule family=&quot;ipv4&quot; 
  source address=&quot;67.205.160.87/32&quot; 
  port protocol=&quot;tcp&quot; port=&quot;953&quot; accept'
</pre>
<p>Reload the rules on both.</p>
<pre class="brush: bash; title: ; notranslate">
firewall-cmd --reload
</pre>
<p>Restart BIND on both.</p>
<pre class="brush: bash; title: ; notranslate">
systemctl restart named
</pre>
<p>Now, you can manage them with rndc.</p>
<pre class="brush: bash; title: ; notranslate">
rndc reload
rndc status
</pre>
<p>From the master server, try to reload the slave server.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
rndc -s 104.248.184.142 reload
server reload successful
</pre>
<p>What we also want to do is tell the OS that from now on, the default DNS server will be our local DNS.<br />
So, edit <strong>/etc/resolv.conf</strong> and add this line as the first line on both. </p>
<pre class="brush: bash; title: ; notranslate">
nameserver 127.0.0.1
</pre>
<p>If we try to ping google.com we should get a response or at least an IP resolved. That&#8217;s good. From another computer, try to use any of our servers as a DNS. This is what you should get: Query refused. That&#8217;s good too, because we don&#8217;t want our server to be used as a DNS server for other domains. We want to access the Internet from the server, e.g. to update the server, so we need to be able to use the local server to resolve any domains but only from localhost. </p>
<pre class="brush: bash; highlight: [1,5,9]; title: ; notranslate">
C:\Users\klimenta&gt;nslookup
Default Server:  google-public-dns-a.google.com
Address:  8.8.8.8

&gt; server 67.205.160.87
Default Server:  &#x5B;67.205.160.87]
Address:  67.205.160.87

&gt; www.google.com
Server:  &#x5B;67.205.160.87]
Address:  67.205.160.87

*** &#x5B;67.205.160.87] can't find www.google.com: Query refused
</pre>
<p>You can allow this server to act as a forwarder by including <strong>recursion yes</strong>; option under <strong>options </strong>and <strong>allow-access</strong> to all IPs (0.0.0.0/0), but that&#8217;s not the intended use of an authoritative DNS server. </p>
<h1>Zone file</h1>
<p>Now that we have the servers up and running, let&#8217;s create the zone file. The zone file tells where the records can be found. On the master server only, edit <strong>named.conf</strong> and add these two lines right after the <strong>listen-on</strong> option. We are allowing the transfer of the zones to the slave server only</p>
<pre class="brush: bash; title: ; notranslate">
allow-transfer { localhost; 104.248.184.142; };
notify yes;
</pre>
<p>Go all the way at the bottom and add these line to define the zone file.<br />
<strong>NOTE:</strong> If you have SELinux enabled, you can&#8217;t define your zone anywhere. Make sure you use <strong>/var/named</strong> for your zone file.).</p>
<pre class="brush: bash; title: ; notranslate">
zone &quot;cloudwerk.us&quot; {
        type master;
        file &quot;/var/named/db.cloudwerk.us&quot;;
};
</pre>
<p>Now, go to the <strong>/var/named </strong>directory and create the zone file to look like this. The file should be called <strong>db.cloudwerk.us</strong>. Do this on the master server only. You might want to read the following <a href="https://help.dyn.com/how-to-format-a-zone-file" rel="noopener noreferrer" target="_blank">link </a>if you are not familiar with the syntax of a zone file. </p>
<pre class="brush: bash; title: ; notranslate">
$TTL    604800
@       IN      SOA     ns1.cloudwerk.us.       admin.cloudwerk.us. (
                        2018121901;     Serial
                        3H;             Refresh
                        15M;            Retry
                        2W;             Expiry
                        1D );           Minimum

; name servers - NS records
        IN      NS      ns1.cloudwerk.us.
        IN      NS      ns2.cloudwerk.us.

; name servers - A records
ns1.cloudwerk.us.       IN      A       67.205.160.87
ns2.cloudwerk.us.       IN      A       104.248.184.142

; other servers - A records
www.cloudwerk.us.       IN      A       52.71.63.84
</pre>
<p>All you have to do now is to reload the new config with <strong>rndc reload</strong>. At this point we have the master server up and running. Now, we have to configure the slave server. Edit the <strong>named.conf</strong> file and add these lines at the bottom. Very self-explanatory. </p>
<pre class="brush: bash; title: ; notranslate">
zone &quot;cloudwerk.us&quot; {
        type slave;
        masters { 67.205.160.87; };
        file &quot;/var/named/slaves/db.cloudwerk.us&quot;;
};
</pre>
<p>Restart the <strong>named </strong>daemon and if you go to <strong>/var/named/slaves</strong> directory, you&#8217;ll see that the zone file replicated from the master. Finally, on both servers you have to allow the queries from the Internet. Edit <strong>named.con</strong>f and comment this line.</p>
<pre class="brush: bash; title: ; notranslate">
//allow-query     { localhost; }; 
</pre>
<p>Reload with <strong>rndc reload</strong> on both after.<br />
At this point, we have both the master and the slave servers configured, up and running. But no one on the Internet knows that our servers are authoritative servers. You have to make this change at your domain registrant. In my case, I&#8217;ve purchased the domain from Go Daddy, so I went to the DNS management panel and added two A records for ns1.cloudwerk.us and ns2.cloudwerk.us. Then, at the bottom of the web control panel, I&#8217;ve changed the DNS from xy.domaincontrol.com to custom and added my servers. I&#8217;ve encountered some issues, but the on-line chat with the support resolved this in 5 minutes. In essence, if you open up the DNS console, scroll all the way down and under <strong>Advanced Features</strong>, you&#8217;ll see <strong>Host names</strong> link. Click on this one and create two records, ns1 and ns2 with your IPs. Now, you can switch to <strong>Custom Nameserves</strong> on the same page.<br />
Leave some time for replication. It might take up to 24 hrs, but in my case it took less than 20 mins.<br />
You should know that you are in charge when these commands return your servers. In Windows:</p>
<pre class="brush: bash; highlight: [1,5,6,19,20]; title: ; notranslate">
C:\Users\klimenta&gt;nslookup
Default Server:  google-public-dns-a.google.com
Address:  8.8.8.8

&gt; set query=soa
&gt; cloudwerk.us
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Non-authoritative answer:
cloudwerk.us
        primary name server = ns1.cloudwerk.us
        responsible mail addr = admin.cloudwerk.us
        serial  = 2018121901
        refresh = 10800 (3 hours)
        retry   = 900 (15 mins)
        expire  = 1209600 (14 days)
        default TTL = 86400 (1 day)
&gt; set query=ns
&gt; cloudwerk.us
Server:  google-public-dns-a.google.com
Address:  8.8.8.8

Non-authoritative answer:
cloudwerk.us    nameserver = ns1.cloudwerk.us
cloudwerk.us    nameserver = ns2.cloudwerk.us
</pre>
<p>In Linux/BSD if you use <strong>dig</strong>:</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
dig +short NS cloudwerk.us
ns2.cloudwerk.us.
ns1.cloudwerk.us.
</pre>
<p>Or, if you want to do it <a href="https://mxtoolbox.com/dnscheck.aspx" rel="noopener noreferrer" target="_blank">on-line</a>.<br />
This is what I got.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-01.png" alt="" width="1342" height="412" class="aligncenter size-full wp-image-8296" /></a><br />
It says that the slave server is leaking the zone which means anyone can list all the records. In order to prevent that, we have to edit <strong>named.conf</strong> on the slave server and add this line after <strong>listen-on </strong>option.</p>
<pre class="brush: bash; title: ; notranslate">
allow-transfer { localhost; 67.205.160.87; };
</pre>
<p>Do <strong>rndc reload</strong> after and if you re-execute the test, you&#8217;ll see that everything looks OK.</p>
<h1>DNSSEC (optional)</h1>
<p>I won&#8217;t go into details of what is DNSSEC, I&#8217;ll just explain how to configure and secure your DNS server. It&#8217;s pretty much a PKI infrastructure for securing your records by signing them with a private key. If you need more info, you can find tons of info by googling DNSSEC.<br />
On the master server, add this line after <strong>dnssec-validation yes;</strong> option in <strong>named.conf</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
key-directory &quot;/var/named/keys&quot;;
</pre>
<p>On the slave server don&#8217;t do anything.<br />
Add these lines in the same file (named.conf) on the master server  only. They should be below <strong>file </strong>directive where your zone is defined (at the bottom of the file). These lines are part of your zone config, not separate directives.</p>
<pre class="brush: bash; title: ; notranslate">
auto-dnssec maintain;
inline-signing yes;
</pre>
<p>Let&#8217;s create the KSK and ZSK keys. Master server only.</p>
<pre class="brush: bash; title: ; notranslate">
cd /var/named/keys
dnssec-keygen -r /dev/urandom -a RSASHA256 -b 2048 -f KSK -n ZONE cloudwerk.us
ls -l
echo &quot;Take a note of the key file that ends with .key&quot;
dnssec-keygen -r /dev/urandom -a RSASHA256 -b 2048 -n ZONE cloudwerk.us
</pre>
<p>You&#8217;ll see 4 files created. Scribble down the first key file that was created (.key), see the output from above. Reload the config on the master but make sure BIND can access the keys.</p>
<pre class="brush: bash; title: ; notranslate">
chown -R named:named /var/named/keys
rndc reload
</pre>
<p>You&#8217;ll see two more files (.jbk and .signed) under <strong>/var/named</strong>. These are the signed files. If you check the <strong>slaves </strong>directory on the slave node, you&#8217;ll see a signed file there as well.<br />
Let&#8217;s do a test. Go to this <a href="https://dnssec-analyzer.verisignlabs.com/" rel="noopener noreferrer" target="_blank">link</a>, type your domain name and hit enter.<br />
You should see something like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-02.png" alt="" width="717" height="763" class="aligncenter size-full wp-image-8297" /></a><br />
Now, stop the master server with <strong>rndc stop</strong> and refresh the web page. The test will take a little bit longer, because NS1 is down, but eventually you&#8217;ll get something like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-03.png" alt="" width="796" height="782" class="aligncenter size-full wp-image-8298" /></a><br />
That&#8217;s normal. It tells us that ns1 is down. What&#8217;s not normal is the red X mark that says <strong>&#8220;No DS records found for coudwerk.us in the us zone&#8221;</strong>. This translates as, yes you signed your zone, but no one can validate it. It&#8217;s like a fake certificate. So, we need to tell our registrant that we really own the domain and that we signed it.<br />
This portion is also registrant&#8217;s  dependent. I&#8217;ll describe how to overcome this error with Go Daddy.<br />
So, go to the <strong>keys </strong>directory and execute this command against the first file, that one that you took note about. </p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
cd /var/named/keys
dnssec-dsfromkey Kcloudwerk.us.+008+23956.key
cloudwerk.us. IN DS 23956 8 1 2DA94FECA549E0A2B137FA6C64D09D2CBADF8864
cloudwerk.us. IN DS 23956 8 2 8CC2CB79E1B8A6767F11230485C7499D52162135E1F6DAA503ADEC4470E417A9
</pre>
<p>Now go to the DNS management panel for your domain at Go Daddy and you&#8217;ll see something like this. Click on <strong>DNSSEC</strong> and then click <strong>ADD</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-04.png" alt="" width="419" height="529" class="aligncenter size-full wp-image-8299" /></a><br />
Looks confusing but it&#8217;s very simple. Just look at the output from the <strong>dnssec-dsfromkey</strong> and add accordingly. You&#8217;ll have to add both hash values.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-05.png" alt="" width="800" height="573" class="aligncenter size-full wp-image-8300" /></a><br />
For <strong>Key Tag</strong> enter <strong>23956</strong>, <strong>Algorithm</strong> is <strong>8</strong>, <strong>Digest Type</strong> is <strong>1</strong>, <strong>Digest </strong>is the hash value and <strong>Key Data Algorithm</strong> is also <strong>8</strong>, the value of <strong>Algorithm</strong>. Click <strong>Update </strong>, do the 2nd line of the output and wait 30-45 mins. Sometimes, even more. It depends on your registrant.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-06.png" alt="" width="861" height="892" class="aligncenter size-full wp-image-8301" /></a><br />
At the end it should look like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-07.png" alt="" width="1478" height="325" class="aligncenter size-full wp-image-8302" /></a><br />
And if you analyze your domain again, the result should look like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/12/P118-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/12/P118-08.png" alt="" width="713" height="929" class="aligncenter size-full wp-image-8303" /></a><br />
Or if you use dig, use the Google&#8217;s DNS server to check.</p>
<pre class="brush: bash; title: ; notranslate">
dig +trace +noadditional DS cloudwerk.us. @8.8.8.8 | grep DS
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/12/141-centos-install-an-authoritative-dns-server-bind/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FreeBSD: Install an authoritative DNS server (BIND)</title>
		<link>https://blog.andreev.it/2018/10/137-freebsd-install-an-authoritative-dns-server-bind/</link>
					<comments>https://blog.andreev.it/2018/10/137-freebsd-install-an-authoritative-dns-server-bind/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Tue, 23 Oct 2018 14:13:54 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[BIND]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[freebsd]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=4096</guid>

					<description><![CDATA[In this post I&#8217;ll explain how to install and configure BIND DNS server to&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll explain how to install and configure BIND DNS server to act as an authoritative server for a public domain in a master/slave configuration. This is not a setup for a server that will act as a DNS server in your local environment and does DNS resolution for your local network. In this post, the DNS server won&#8217;t resolve any DNS queries except for the domain that it is authoritative for. The domain that I&#8217;ll use is <strong>cloudwerk.us</strong> registered with Go Daddy, so some of the configurations will apply to Go Daddy only. The IPs and keys that I&#8217;ll use will be visible. The setup will be gone by the time you read this.<br />
So, I have my master server, <strong>ns1.cloudwerk.us (104.248.47.54)</strong> and the slave server <strong>ns2.cloudwerk.us (142.93.201.231)</strong>.<br />
I will be using FreeBSD 11.2 and BIND 9.12.2-P2. Before you start, make sure you have your domain purchased and you have 2 servers with public IPs up and running. You can leave the default registrant&#8217;s DNS servers for now. </p>
<h1>Installation, startup and control</h1>
<p>First, I&#8217;ll install BIND on both servers. All commands below are executed as root.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install bind912
</pre>
<p>When the installation is done after 10-15 seconds, you&#8217;ll see some text that requires attention. I am not using a jailed install, so I can skip that part. The only part that&#8217;s important is to create the key for the <strong>rndc (Remote Name Daemon Control) </strong>utility. This utility allows management of the <strong>named </strong>(DNS) daemon. Moreover, you can manage remote DNS servers and I&#8217;ll explain how. So, let&#8217;s create the keys (highlighted line is what you type, the rest is output). Do this on the master server only.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
rndc-confgen -a
wrote key file &quot;/usr/local/etc/namedb/rndc.key&quot;
</pre>
<p>As you can see, there is a file called <strong>rndc.key</strong> created under <strong>/usr/local/etc/namedb</strong> directory. This is the default directory where BIND expects to find its config files and zones.<br />
Now, copy this file to the second server in the same location. You can use scp, copy &#038; paste in a terminal session, it doesn&#8217;t matter. What matters is that you have to change the permissions and the owner of the file. BIND runs under the <strong>bind </strong>user, not root. Do this on both servers. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc/namedb
chown root:bind rndc.key
chmod 640 rndc.key
</pre>
<p>Let&#8217;s make sure that BIND starts on boot. On both servers, execute:</p>
<pre class="brush: bash; title: ; notranslate">
sysrc named_enable=&quot;YES&quot;
</pre>
<p>Now, we can start the BIND daemon on both. </p>
<pre class="brush: bash; title: ; notranslate">
service named start
</pre>
<p>Check the logs.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
tail /var/log/messages
Oct 22 15:11:11 ns1 named&#x5B;1161]: ----------------------------------------------------
Oct 22 15:11:11 ns1 named&#x5B;1161]: BIND 9 is maintained by Internet Systems Consortium,
Oct 22 15:11:11 ns1 named&#x5B;1161]: Inc. (ISC), a non-profit 501(c)(3) public-benefit
Oct 22 15:11:11 ns1 named&#x5B;1161]: corporation.  Support and training for BIND 9 are
Oct 22 15:11:11 ns1 named&#x5B;1161]: available at https://www.isc.org/support
Oct 22 15:11:11 ns1 named&#x5B;1161]: ----------------------------------------------------
Oct 22 15:11:11 ns1 named&#x5B;1161]: command channel listening on 127.0.0.1#953
Oct 22 15:11:11 ns1 named&#x5B;1161]: command channel listening on ::1#953
Oct 22 15:11:11 ns1 named&#x5B;1161]: all zones loaded
Oct 22 15:11:11 ns1 named&#x5B;1161]: running
</pre>
<p>We can&#8217;t start the server with the <strong>rndc </strong>utility, but we can stop it if needed with <strong>rndc stop</strong> or simply <strong>service named stop</strong>.<br />
To control the slave server from the master, we have to modify the main BIND configuration file, <strong>named.conf</strong> on the slave server. Also, the keys have to be the same, but we already took care of that part above.<br />
So, in the same <strong>/usr/local/etc/namedb</strong> directory, edit <strong>named.conf</strong> and add these lines, right before the options directive. Do this on the slave server, not the master.</p>
<pre class="brush: bash; title: ; notranslate">
include &quot;/usr/local/etc/namedb/rndc.key&quot;;

controls {
        inet 127.0.0.1 allow { localhost; } keys { &quot;rndc-key&quot;; };
        inet 142.93.201.231 allow { 104.248.47.54; } keys { &quot;rndc-key&quot;; };
};
</pre>
<p>If you look at my IPs below, this means that the rndc utility will be accepted from the localhost and from the the IP 104.248.47.54 which is the master server. But, we also have to tell BIND to listen on the public IP. By default, it listens on the <strong>localhost </strong>only.<br />
Do this on BOTH servers. In <strong>named.conf</strong> find the <strong>options </strong>directive and modify the <strong>listen-on</strong> option so it looks like this. You should put the public IP of each server there, so the line will differ on both servers. </p>
<pre class="brush: bash; title: ; notranslate">
//Master server
listen-on       { 127.0.0.1; 104.248.47.54; };
</pre>
<pre class="brush: bash; title: ; notranslate">
//Slave server
listen-on       { 127.0.0.1; 142.93.201.231; };
</pre>
<p>Restart BIND on both.</p>
<pre class="brush: bash; title: ; notranslate">
service named restart
</pre>
<p>Now, you can manage them with rndc.</p>
<pre class="brush: bash; title: ; notranslate">
rndc reload
rndc status
</pre>
<p>From the master server, try to reload the slave server.</p>
<pre class="brush: bash; title: ; notranslate">
rndc -s 142.93.201.231 reload
server reload successful
</pre>
<p>If you have a firewall, make sure port 953 TCP is open for communication.<br />
What we also want to do is tell the OS that from now on, the default DNS server will be our local DNS.<br />
So, edit <strong>/etc/resolv.conf</strong> and add this line as the first line on both. </p>
<pre class="brush: bash; title: ; notranslate">
nameserver 127.0.0.1
</pre>
<p>If we try to ping google.com we should get a response or at least an IP resolved. That&#8217;s good. From another computer, try to use any of our servers as a DNS. This is what you should get: Query refused. That&#8217;s good too, because we don&#8217;t want our server to be used as a DNS server for other domains. But, also, we want to access the Internet from the server, for example to update the server. Name resolution for other domains from localhost is OK, but not OK from outside. </p>
<pre class="brush: bash; highlight: [1,5,9]; title: ; notranslate">
C:\Users\Elite&gt;nslookup
Default Server:  ns-cache.above.net
Address:  207.126.96.248

&gt; server 142.93.201.231
Default Server:  ns2.cloudwerk.us
Address:  142.93.201.231

&gt; www.google.com
Server:  ns2.cloudwerk.us
Address:  142.93.201.231

*** ns2.cloudwerk.us can't find www.google.com: Query refused
</pre>
<p>You can allow this server to act as a forwarder by including <strong>recursion yes</strong>; option under <strong>options </strong>and <strong>allow-access</strong> to all IPs, but that&#8217;s not the intended use of an authoritative DNS server. </p>
<h1>Zone file</h1>
<p>Now that we have the servers up and running, let&#8217;s create the zone file. The zone file tells where the records can be found. On the master server only, edit <strong>named.conf</strong> and add these two lines right after the <strong>listen-on</strong> option. We are allowing the transfer of the zones to the slave server only</p>
<pre class="brush: bash; title: ; notranslate">
allow-transfer { localhost; 142.93.201.231; };
notify yes;
</pre>
<p>Go all the way at the bottom and add these line to define the zone file.<br />
<strong>NOTE:</strong> If you don&#8217;t want to use the dynamic directory, make sure that your zone file directory is owned by the <strong>bind </strong>user and group (e.g. <em>mkdir somedir, chown -R bind:bind somedir</em>).</p>
<pre class="brush: bash; title: ; notranslate">
zone &quot;cloudwerk.us&quot; {
        type master;
        file &quot;/usr/local/etc/namedb/dynamic/db.cloudwerk.us&quot;;
};
</pre>
<p>Now, go to the <strong>/usr/local/etc/namedb/dynamic </strong>directory and create the zone file to look like this. The file should be called <strong>db.cloudwerk.us</strong>. Do this on the master server only. You might want to read the following <a href="https://help.dyn.com/how-to-format-a-zone-file" rel="noopener noreferrer" target="_blank">link </a>if you are not familiar with the syntax of a zone file. </p>
<pre class="brush: bash; title: ; notranslate">
$TTL    604800
@       IN      SOA     ns1.cloudwerk.us.       admin.cloudwerk.us. (
                        2018101901;     Serial
                        3H;             Refresh
                        15M;            Retry
                        2W;             Expiry
                        1D );           Minimum

; name servers - NS records
        IN      NS      ns1.cloudwerk.us.
        IN      NS      ns2.cloudwerk.us.

; name servers - A records
ns1.cloudwerk.us.       IN      A       104.248.47.54
ns2.cloudwerk.us.       IN      A       142.93.201.231

; other servers - A records
www.cloudwerk.us.       IN      A       52.71.63.84
</pre>
<p>All you have to do now is to reload the new config with <strong>rndc reload</strong>. At this point we have the master server up and running. Now, we have to configure the slave server. Edit the <strong>named.conf</strong> file and add these lines at the bottom. Very self-explanatory. </p>
<pre class="brush: bash; title: ; notranslate">
zone &quot;cloudwerk.us&quot; {
        type slave;
        masters { 104.248.47.54; };
        file &quot;/usr/local/etc/namedb/dynamic/db.cloudwerk.us&quot;;
};
</pre>
<p>Restart the <strong>named </strong>daemon and if you go to <strong>/usr/local/etc/namedb/dynamic</strong> directory, you&#8217;ll see that the zone file replicated from the master.<br />
At this point, we have both the master and the slave servers configured, up and running. But no one on the Internet knows that our servers are authoritative servers. You have to make this change at your domain registrant. In my case, I&#8217;ve purchased the domain from Go Daddy, so I went to the DNS management panel and add two A records for ns1.cloudwerk.us and ns2.cloudwerk.us. Then, at the bottom of the web contol panel, I&#8217;ve changed the DNS from xy.domaincontrol.com to custom and added my servers. I&#8217;ve encountered some issues, but the on-line chat with the support resolved this in 5 minutes. In essence, if you open up the DNS console, scroll all the way down and under <strong>Advanced Features</strong>, you&#8217;ll see <strong>Host names</strong> link. Click on this one and create two records, ns1 and ns2 with your IPs. Now, you can switch to <strong>Custom Nameserves</strong> on the same page.<br />
Leave some time for replication. It might take up to 24 hrs, but in my case it took less than 20 mins.<br />
You should know that you are in charge when these commands return your servers. In Windows:</p>
<pre class="brush: bash; highlight: [1,5,6]; title: ; notranslate">
C:\Users\Elite&gt;nslookup
Default Server:  ns-cache.above.net
Address:  207.126.96.248

&gt; set query=soa
&gt; cloudwerk.us
Server:  ns-cache.above.net
Address:  207.126.96.248

Non-authoritative answer:
cloudwerk.us
        primary name server = ns1.cloudwerk.us
        responsible mail addr = admin.cloudwerk.us
        serial  = 2018101901
        refresh = 10800 (3 hours)
        retry   = 900 (15 mins)
        expire  = 1209600 (14 days)
        default TTL = 86400 (1 day)

cloudwerk.us    nameserver = ns2.cloudwerk.us
cloudwerk.us    nameserver = ns1.cloudwerk.us
ns1.cloudwerk.us        internet address = 104.248.47.54
ns2.cloudwerk.us        internet address = 149.93.201.231
</pre>
<p>In Linux/BSD if you use <strong>dig</strong>:</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
dig +short NS cloudwerk.us
ns2.cloudwerk.us.
ns1.cloudwerk.us.
</pre>
<p>Or, if you want to do it <a href="https://mxtoolbox.com/dnscheck.aspx" rel="noopener noreferrer" target="_blank">on-line</a>.<br />
This is what I got.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-01.png" alt="" width="1482" height="764" class="aligncenter size-full wp-image-8279" /></a><br />
It says that the slave server is leaking the zone which means anyone can list all the records. In order to prevent that, we have to edit <strong>named.con</strong>f on the slave server and add this line after <strong>listen-on </strong>option.</p>
<pre class="brush: bash; title: ; notranslate">
allow-transfer { localhost; 104.248.47.54; };
</pre>
<p>Do <strong>rndc reload</strong> after and if you re-execute the test, you&#8217;ll see that everything looks OK.</p>
<h1>DNSSEC (optional)</h1>
<p>I won&#8217;t go into details of what is DNSSEC, I&#8217;ll just explain how to configure and secure your DNS server. It&#8217;s pretty much a PKI infrastructure for securing your records by signing them with a private key. If you need more info, you can find tons of info by googling DNSSEC.<br />
On the master server, add these lines after <strong>listen-on</strong> option in <strong>named.conf</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
dnssec-enable yes;
key-directory &quot;/usr/local/etc/namedb/keys&quot;;
</pre>
<p>On the slave server, add this line after <strong>listen-on</strong> option in <strong>named.conf</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
dnssec-enable yes;
</pre>
<p>Add these lines in the same file on the master server  only. They should be below <strong>file </strong>directive where your zone is defined (at the bottom of the file).</p>
<pre class="brush: bash; title: ; notranslate">
auto-dnssec maintain;
inline-signing yes;
</pre>
<p>On the master server only, create they <strong>keys </strong>directory.</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /usr/local/etc/namedb/keys
cd /usr/local/etc/namedb/keys
</pre>
<p>Let&#8217;s create the KSK and ZSK keys. Master server only.</p>
<pre class="brush: bash; title: ; notranslate">
dnssec-keygen -r /dev/urandom -a RSASHA256 -b 2048 -f KSK -n ZONE cloudwerk.us
ls -l
echo &quot;Take a note of the key file&quot;
dnssec-keygen -r /dev/urandom -a RSASHA256 -b 2048 -n ZONE cloudwerk.us
</pre>
<p>You&#8217;ll see 4 files created. Scribble down the first key file that was created, see the output from above. Step one directory up and change the ownership so BIND can read these files.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc/namedb
chown -R bind:bind keys
rndc reload
</pre>
<p>If you go to the <strong>dynamic </strong>directory where your zone file is, you&#8217;ll see three more files. These are the signed files.</p>
<pre class="brush: bash; title: ; notranslate">
ls -l /usr/local/etc/namedb/dynamic
</pre>
<p>If you go on the slave server in the same <strong>dynamic </strong>directory, you&#8217;ll see that signed <strong>.jnl</strong> file also transferred.<br />
Let&#8217;s do a test. Go to this <a href="https://dnssec-analyzer.verisignlabs.com/" rel="noopener noreferrer" target="_blank">link</a>, type your domain name and hit enter.<br />
You should see something like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-02.png" alt="" width="470" height="519" class="aligncenter size-full wp-image-8280" /></a><br />
Now, stop the master server with <strong>rndc stop</strong> and refresh the web page. The test will take a little bit longer, because NS1 is down, but eventually you&#8217;ll get something like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-03.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-03.png" alt="" width="504" height="540" class="aligncenter size-full wp-image-8281" /></a><br />
That&#8217;s normal. It tells us that ns1 is down. What&#8217;s not normal is the red X mark that says <strong>&#8220;No DS records found for coudwerk.us in the us zone&#8221;</strong>. This translates as, yes you signed your zone, but no one can validate it. It&#8217;s like a fake certificate. So, we need to tell our registrant that we really own the domain and that we signed it.<br />
This portion is also registrant&#8217;s  dependent. I&#8217;ll describe how to overcome this error with Go Daddy.<br />
So, go to the <strong>keys </strong>directory and execute this command against the first file. </p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
cd /usr/local/etc/namedb/keys
dnssec-dsfromkey Kcloudwerk.us.+008+23956.key
cloudwerk.us. IN DS 23956 8 1 2DA94FECA549E0A2B137FA6C64D09D2CBADF8864
cloudwerk.us. IN DS 23956 8 2 8CC2CB79E1B8A6767F11230485C7499D52162135E1F6DAA503ADEC4470E417A9
</pre>
<p>Now go to the DNS management panel for your domain at Go Daddy and you&#8217;ll see something like this. Click on <strong>DNSSEC</strong> and then click <strong>ADD</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-04.png" alt="" width="419" height="529" class="aligncenter size-full wp-image-8282" /></a><br />
Looks confusing but it&#8217;s very simple. Just look at the output from the <strong>dnssec-dsfromkey</strong> and add accordingly. You&#8217;ll have to add both hash values.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-05.png" alt="" width="800" height="573" class="aligncenter size-full wp-image-8283" /></a><br />
For <strong>Key Tag</strong> enter <strong>23956</strong>, <strong>Algorithm</strong> is <strong>8</strong>, <strong>Digest Type</strong> is <strong>1</strong>, <strong>Digest </strong>is the hash value and <strong>Key Data Algorithm</strong> is also <strong>8</strong>, the value of <strong>Algorithm</strong>. Click <strong>Update </strong>, do the 2nd line of the output and wait 30-45 mins. Sometimes, even more. It depends on your registrant.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-06.png" alt="" width="861" height="892" class="aligncenter size-full wp-image-8284" /></a><br />
At the end it should look like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-07.png" alt="" width="1478" height="325" class="aligncenter size-full wp-image-8285" /></a><br />
And if you analyze your domain again, the result should look like this.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/10/P114-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/10/P114-08.png" alt="" width="713" height="929" class="aligncenter size-full wp-image-8286" /></a><br />
Or if you use dig, use the Google&#8217;s DNS server to check.</p>
<pre class="brush: bash; title: ; notranslate">
dig +trace +noadditional DS cloudwerk.us. @8.8.8.8 | grep DS
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/10/137-freebsd-install-an-authoritative-dns-server-bind/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FreeBSD: SAMBA 4 as a domain controller running on a public IP (OpenVPN, BIND, pf) on FreeBSD 10</title>
		<link>https://blog.andreev.it/2014/07/freebsd-10-samba-4-as-a-domain-controller-running-on-a-public-ip-openvpn-bind-pf/</link>
					<comments>https://blog.andreev.it/2014/07/freebsd-10-samba-4-as-a-domain-controller-running-on-a-public-ip-openvpn-bind-pf/#comments</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 27 Jul 2014 17:13:49 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[BIND]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[pf]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=1436</guid>

					<description><![CDATA[In this post I’ll describe how to install Samba 4 to act as a&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I’ll describe how to install Samba 4 to act as a Windows domain controller on a FreeBSD 10 server that sits in the cloud with a public IP. No worries, nothing will be exposed to the public. We’ll use OpenVPN + pf for that. What you need is a FreeBSD 10 server as a <a href="http://en.wikipedia.org/wiki/Virtual_private_server" target="_blank" rel="noopener noreferrer">VPS</a> with public IP, a Windows 7 computer with Internet connection that will join the domain, some patience and willing to troubleshoot reading logs if something goes haywire. </p>
<h1>Prep work</h1>
<p>Get yourself a FreeBSD 10 server somewhere in the cloud with a public IP. Make sure that none of the ports are blocked, not on your server but on your VPS provider&#8217;s firewall. It doesn&#8217;t matter if some ports necessary to run a domain controller (135, 139) are blocked on your home network. E.g. my home Internet provided Comcast blocks these ports. If the port tree is missing, fetch it with <a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports-using.html" target="_blank" rel="noopener noreferrer">portsnap</a>. If the pf firewall is enabled on the BSD server, disable it (<strong>pfctl -d</strong>). You&#8217;ll enable it later. You can keep your Windows firewall enabled all the time and no changes will be necessary on your Windows computer except installing OpenVPN. If you want your NetBIOS domain to be named <strong>SOMETHING</strong>, then your FreeBSD hostname can&#8217;t be <strong>something.domain.com</strong>. In the examples below, my FreeBSD host will be <strong>dc.fluffycloud.us</strong> and my NetBIOS domain will be <strong>IANDREEV</strong>. I won&#8217;t hide any IPs or passwords. This is a sandbox server that will be long gone when you read this.<br />
OK. Let&#8217;s get started. </p>
<h1>Install OpenVPN 2.3.4 server</h1>
<p>In my latest <a href="https://blog.andreev.it/?p=1376" target="_blank" rel="noopener noreferrer">post</a> I’ve described how to install OpenVPN, but this time, it’s going to be slightly different. Instead of <strong>tun</strong>, we’ll use <strong>tap</strong> adapter. The reason behind this is that Samba 4 can’t use tun, because tun adapters do not have a broadcast address. OpenVPN server can be installed from the ports.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/security/openvpn
make all install clean
</pre>
<p>Select the defaults.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-01.png" alt="" width="664" height="232" class="aligncenter size-full wp-image-7095" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-01.png 664w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-01-300x105.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-01-585x204.png 585w" sizes="(max-width: 664px) 100vw, 664px" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-02.png" alt="" width="674" height="168" class="aligncenter size-full wp-image-7096" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-02.png 674w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-02-300x75.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-02-585x146.png 585w" sizes="(max-width: 674px) 100vw, 674px" /></a><br />
Once completed, edit <strong>/etc/rc.conf</strong> and add:</p>
<pre class="brush: bash; title: ; notranslate">
openvpn_enable=&quot;YES&quot;
</pre>
<p>This will allow OpenVPN server to start on boot. Now, let’s create the configuration file. By default, OpenVPN will look at <strong>openvpn.conf</strong> file at <strong>/usr/local/etc/openvpn/</strong> directory. We’ll use one of the example files that came with OpenVPN. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc
mkdir openvpn
cd /usr/local/share/examples/openvpn/sample-config-files/
cp server.conf /usr/local/etc/openvpn/openvpn.conf
</pre>
<p>Edit <strong>openvpn.conf</strong> and make sure that these directives below exist. For example, if you uncomment <strong>dev tap</strong>, you’ll have to comment <strong>dev tun</strong>. Both can’t work at the same time. What each line does is beyond the scope of this post. In essence, this configuration file will allow OpenVPN server to start in bridged mode, listening on port 1194 UDP and it will use certificates for authentication. In addition, the VPN IP address of the server will be <strong>10.8.0.1</strong> and it will act as a DHCP server for all clients, assigning a range of IPs from <strong>10.8.0.50</strong> to <strong>10.8.0.100</strong> with <strong>10.8.0.1</strong> and <strong>8.8.8.8</strong> as DNS servers. Finally, <strong>client-to-client</strong> will allow clients to see each other. </p>
<pre class="brush: bash; title: ; notranslate">
port 1194
proto udp
dev tap
ca ca.crt
cert server.crt
key server.key  # This file should be kept secret
dh dh1024.pem
ifconfig-pool-persist ipp.txt
server-bridge 10.8.0.1 255.255.255.0 10.8.0.50 10.8.0.100
server-bridge
push &quot;dhcp-option DNS 10.8.0.1 8.8.8.8&quot;
client-to-client
keepalive 10 120
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
verb 3
</pre>
<p>Now it’s time to create the certificates. First, we’ll build the certificate authority CA, then the server certificate and one client certificate. </p>
<pre class="brush: bash; title: ; notranslate">
﻿cd /usr/local/share/easy-rsa/
sh
. ./vars
./clean-all
./build-ca
</pre>
<p>This is the output. Change the values to match your needs. </p>
<pre class="brush: plain; title: ; notranslate">Generating a 1024 bit RSA private key
...................................++++++
..++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#x5B;US]:US
State or Province Name (full name) &#x5B;CA]:NJ
Locality Name (eg, city) &#x5B;SanFrancisco]:Lawrenceville
Organization Name (eg, company) &#x5B;Fort-Funston]:iAndreev
Organizational Unit Name (eg, section) &#x5B;changeme]:.
Common Name (eg, your name or your server's hostname) &#x5B;changeme]:dc.fluffycloud.us
Name &#x5B;changeme]:iAndreev
Email Address &#x5B;mail@host.domain]:klimenta@fluffycloud.us
</pre>
<p>Let’s build the server certificate. </p>
<pre class="brush: bash; title: ; notranslate">
./build-key-server server
</pre>
<p>This is the output. Change the values to match your needs.</p>
<pre class="brush: plain; title: ; notranslate">
Generating a 1024 bit RSA private key
......++++++
..........++++++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#x5B;US]:US
State or Province Name (full name) &#x5B;CA]:NJ
Locality Name (eg, city) &#x5B;SanFrancisco]:Lawrenceville
Organization Name (eg, company) &#x5B;Fort-Funston]:iAndreev
Organizational Unit Name (eg, section) &#x5B;changeme]:.
Common Name (eg, your name or your server's hostname) &#x5B;server]:dc.fluffycloud.us
Name &#x5B;changeme]:iAndreev
Email Address &#x5B;mail@host.domain]:klimenta@fluffycloud.us

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password &#x5B;]:
An optional company name &#x5B;]:
Using configuration from /usr/local/share/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
stateOrProvinceName   :PRINTABLE:'NJ'
localityName          :PRINTABLE:'Lawrenceville'
organizationName      :PRINTABLE:'iAndreev'
commonName            :PRINTABLE:'dc.fluffycloud.us'
name                  :PRINTABLE:'iAndreev'
emailAddress          :IA5STRING:'klimenta@fluffycloud.us'
Certificate is to be certified until Jul 22 14:52:51 2024 GMT (3650 days)
Sign the certificate? &#x5B;y/n]:y

1 out of 1 certificate requests certified, commit? &#x5B;y/n]y
Write out database with 1 new entries
Data Base Updated</pre>
<p>﻿Now, let’s create a certificate for one client. In my case, the hostname is liquid. The name of the client host doesn’t matter, it’s more like a unique description, but make sure that the common name is unique. Otherwise, you’ll receive an error saying “<strong>failed to update database, TXT_DB error number 2</strong>“.Sign the certificate as well.</p>
<pre class="brush: bash; title: ; notranslate">
./build-key liquid
</pre>
<p>This is the output. Change the values to match your needs. </p>
<pre class="brush: plain; title: ; notranslate">Generating a 1024 bit RSA private key
.....++++++
............++++++
writing new private key to 'liquid.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) &#x5B;US]:
State or Province Name (full name) &#x5B;CA]:NJ
Locality Name (eg, city) &#x5B;SanFrancisco]:Lawrenceville
Organization Name (eg, company) &#x5B;Fort-Funston]:iAndreev
Organizational Unit Name (eg, section) &#x5B;changeme]:.
Common Name (eg, your name or your server's hostname) &#x5B;liquid]:liquid
Name &#x5B;changeme]:iAndreev
Email Address &#x5B;mail@host.domain]:klimenta@fluffycloud.us

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password &#x5B;]:
An optional company name &#x5B;]:
Using configuration from /usr/local/share/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
stateOrProvinceName   :PRINTABLE:'NJ'
localityName          :PRINTABLE:'Lawrenceville'
organizationName      :PRINTABLE:'iAndreev'
commonName            :PRINTABLE:'liquid'
name                  :PRINTABLE:'iAndreev'
emailAddress          :IA5STRING:'klimenta@fluffycloud.us'
Certificate is to be certified until Jul 22 14:54:28 2024 GMT (3650 days)
Sign the certificate? &#x5B;y/n]:y

1 out of 1 certificate requests certified, commit? &#x5B;y/n]y
Write out database with 1 new entries
Data Base Updated
</pre>
<p>Build the certificate parameters.<br />
﻿</p>
<pre class="brush: bash; title: ; notranslate">
./build-dh
</pre>
<p>It doesn&#8217;t take that long. Less than a minute.</p>
<pre class="brush: plain; title: ; notranslate">Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..........................+...........+.........................+
....................................................+.............
.............................+...................+................
...................+....................................++*++*++*
</pre>
<p>Now that the certificates are generated, go to the directory where certificates are stored and copy them to our openvpn config folder.<br />
﻿</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/share/easy-rsa/keys
cp server.crt /usr/local/etc/openvpn/
cp dh1024.pem /usr/local/etc/openvpn/
cp server.key /usr/local/etc/openvpn/
cp ca.crt /usr/local/etc/openvpn/
</pre>
<p>We don’t need to copy the client certificates. They belong to the client. </p>
<p>In case you want to revoke the client certificate for client liquid, do:</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/share/easy-rsa
sh
. ./vars
./revoke-full liquid	 
</pre>
<h1>Install bridged network adapter</h1>
<p>This is how my <strong>/etc/rc.conf</strong> looks like at this point. The command <strong>cloned_interfaces</strong> tells FreeBSD to create two interfaces <strong>tap0 </strong>and <strong>bridge0</strong>, where <strong>bridge0</strong> is the actual bridge interface. For more details, check this <a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-bridging.html" target="_blank" rel="noopener noreferrer">link</a>. I assigned <strong>10.8.0.1</strong> to the tap interface first and then I am adding <strong>tap0</strong> and <strong>vtnet0 </strong>as member interfaces of the bridge.<br />
﻿</p>
<pre class="brush: bash; title: ; notranslate">
ifconfig_vtnet0=&quot;inet 209.222.2.147 netmask 255.255.255.224&quot;
defaultrouter=&quot;209.222.2.129&quot;
hostname=”dc.fluffycloud.us&quot;
cloned_interfaces=&quot;tap0 bridge0&quot;
ifconfig_tap0=&quot;10.8.0.1/24&quot;
ifconfig_bridge0=&quot;addm tap0 addm vtnet0 up&quot;
sshd_enable=YES
openvpn_enable=&quot;YES&quot;
</pre>
<p>Make sure that you create the bridged interface before you start OpenVPN. At this point, reboot the server. When it comes up, do:</p>
<pre class="brush: bash; title: ; notranslate">
ps –waux | grep openvpn
</pre>
<p>You should see an output like this.</p>
<p><code>nobody    966   0.0  0.6 21492 4704  -  Ss    3:19PM 0:00.00 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon openvpn -<br />
</code><br />
Then, check the network with:</p>
<pre class="brush: bash; title: ; notranslate">
ifconfig -a
</pre>
<p>This is my output.</p>
<pre class="brush: bash; title: ; notranslate">
vtnet0: flags=8943&lt;UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
options=6c00b9&lt;RXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6&gt;
	ether 52:54:00:83:38:f9
	inet &lt;209.222.2.147 netmask 0xffffffe0 broadcast 209.222.2.159
	inet6 fe80::5054:ff:fe83:38f9%vtnet0 prefixlen 64 scopeid 0x1 
	nd6 options=29&lt;PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL&gt;
	media: Ethernet 10Gbase-T &lt;full-duplex&gt;
	status: active
lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; metric 0 mtu 16384
	options=600003&lt;RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6&gt;
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
	inet 127.0.0.1 netmask 0xff000000 
	nd6 options=21&lt;PERFORMNUD,AUTO_LINKLOCAL&gt;
tap0: flags=8943&lt;UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
	options=80000&lt;LINKSTATE&gt;
	ether 00:bd:b6:00:00:00
	inet 10.8.0.1 netmask 0xffffff00 broadcast 10.8.0.255 
	inet6 fe80::2bd:b6ff:fe00:0%tap0 prefixlen 64 scopeid 0x3 
	nd6 options=29&lt;PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL&gt;
	media: Ethernet autoselect
	status: active
	Opened by PID 964
bridge0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
	ether 02:d1:f9:85:8a:00
	nd6 options=9&lt;PERFORMNUD,IFDISABLED&gt;
	id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
	maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
	root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
	member: vtnet0 flags=143&lt;LEARNING,DISCOVER,AUTOEDGE,AUTOPTP&gt;
	        ifmaxaddr 0 port 1 priority 128 path cost 2000
	member: tap0 flags=143&lt;LEARNING,DISCOVER,AUTOEDGE,AUTOPTP&gt;
	        ifmaxaddr 0 port 3 priority 128 path cost 2000000
</pre>
<h1>Install OpenVPN client</h1>
<p>On your Windows machine, install the OpenVPN from <a href="http://openvpn.net/index.php/download/community-downloads.html" target="_blank" rel="noopener noreferrer">here</a>. Go to <strong>C:\Program Files\OpenVPN</strong> and copy the <strong>client.ovpn</strong> file from <strong>sample-config</strong> folder to the <strong>config</strong> folder. Edit the <strong>client.ovpn</strong> file and change the values for the <strong>server</strong> and the path to the client certificates. You&#8217;ll have to copy these three client certificate files (<strong>ca.crt, liquid.crt and liquid.key</strong>) from the FreeBSD server to the client. Actually, <strong>ca.crt</strong> is the public server key. I used <a href="http://winscp.net/eng/index.php" target="_blank" rel="noopener noreferrer">WinSCP</a> to copy the files over. I’ve also decided to keep the certificates under <strong>c:\keys</strong>. (Note: use double back-slash in the config file). If you are having problems saving the file under <strong>C:\Program Files\OpenVPN\config</strong>, save it on the desktop first and then manually copy it over to <strong>C:\Program Files\OpenVPN\config</strong> folder. Here is my <strong>client.ovpn</strong>.</p>
<pre class="brush: plain; title: ; notranslate">
client
dev tap
proto udp
remote dc.fluffycloud.us 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca c:\\keys\\ca.crt
cert c:\\keys\\liquid.crt
key c:\\keys\\liquid.key
ns-cert-type server
keepalive 10 120
comp-lzo
verb 3
</pre>
<p>Make sure that the <strong>openvpn-gui</strong> executable always starts with full admin privileges. Go to the <strong>bin</strong> folder, right click the executable, click <strong>Properties</strong> and check <strong>Run this program as administrator</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-03.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-03.png" alt="" width="409" height="525" class="aligncenter size-full wp-image-7097" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-03.png 409w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-03-234x300.png 234w" sizes="(max-width: 409px) 100vw, 409px" /></a><br />
The <strong>OpenVPN GUI</strong> creates an icon in the tray, right-click that icon and click <strong>Connect</strong>. If everything is fine, you should see that openvpn client is connected and that you can ping the server. In case something is wrong, right-click the same <strong>OpenVPN GUI</strong> icon and choose <strong>View log</strong>.<br />
It is possible to have multiple client configuration files. Put them in the same folder and <strong>OpenVPN GUI</strong> will recognize them. Next time you want to connect to another server, right-click on the tray icon and you’ll see all these entries. </p>
<h1>Install BIND DNS 9.9.5P1_3</h1>
<p>Samba 4 comes with its own DNS server, but it won’t work with our scenario. Therefore we’ll install <a href="http://www.isc.org/downloads/bind/" target="_blank" rel="noopener noreferrer">BIND 9.9.5P1_3</a>. In order to install BIND, do:</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/dns/bind99
make all install clean
</pre>
<p>Accept the defaults for the dependencies. Make sure that named starts on boot. Edit <strong>/etc/rc.conf</strong> and add:</p>
<pre class="brush: bash; title: ; notranslate">
named_enable=”YES”
</pre>
<p>after <strong>ssh_enable=&#8221;YES&#8221;</strong> and before <strong>openvpn_enable=&#8221;YES&#8221;</strong>.</p>
<p>Go to the BIND’s folder and create a security key so you can manage the DNS service. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc/namedb
rndc-confgen –a
</pre>
<p>This will create a file <strong>rndc.key</strong>. We will include this file in the main configuration file. Edit <strong>named.conf</strong> and change the values for the listener, the forwarder and create a reverse zone. The primary zone is not needed, Samba will take care of this. </p>
<pre class="brush: plain; title: ; notranslate">
listen-on       { 127.0.0.1; 10.8.0.1; };
        forwarders {
                8.8.8.8;
        };
/* Put the lines below all the way at the end */
zone &quot;0.8.10.in-addr.arpa&quot; {
        type master;
        file &quot;/usr/local/etc/namedb/master/0.8.10.in-addr.arpa.db&quot;;
};

controls {
  inet 127.0.0.1 allow { localhost; } keys { &quot;rndc-key&quot;; };
};
include &quot;/usr/local/etc/namedb/rndc.key&quot;;
</pre>
<p>Create the reverse zone file under <strong>/usr/local/etc/namedb/master</strong>. The file name is <strong>0.8.10.in-addr.arpa.db</strong>.</p>
<pre class="brush: plain; title: ; notranslate">
@ IN SOA        dc.fluffycloud.us. klimenta.fluffycloud.us. (
                   2014071201           ; Serial
                         3600           ; Refresh &#x5B;1h]
                          600           ; Retry   &#x5B;10m]
                        86400           ; Expire  &#x5B;1d]
                          600 )         ; Negative Cache TTL &#x5B;1h]
;
@       IN      NS      dc.fluffycloud.us.

1       IN      PTR     dc.fluffycloud.us.
</pre>
<p>Now, edit<strong> /etc/resolv.conf</strong> and tell BSD where to lookup first for all the queries. </p>
<pre class="brush: plain; title: ; notranslate">
domain dc.fluffycloud.us
nameserver 10.8.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4
</pre>
<p>NOTE: If you use a DHCP provided address, <strong>/etc/resolv.conf</strong> will be overwritten. Create the following file <strong>/etc/resolvconf.conf</strong> and add these two lines.</p>
<pre class="brush: plain; title: ; notranslate">
search_domains=&quot;fluffycloud.us&quot;
name_servers=&quot;10.8.0.1&quot;
</pre>
<p>Then execute </p>
<pre class="brush: plain; title: ; notranslate">
resolvconf -u
</pre>
<p>It’s time to start the DNS now.</p>
<pre class="brush: bash; title: ; notranslate">
service named start
ps -waux | grep named
</pre>
<p>You should see something like this.<br />
<code><br />
bind     58068   0.0  2.5 45672 18904  -  Ss    6:46PM    0:00.04 /usr/local/sbin/named -u bind -c /usr/local/etc/namedb/named.conf<br />
</code></p>
<p>From  the client computer that&#8217;s connected to your OpenVPN server, verify that <strong>10.8.0.1</strong> is your DNS server and check if the actual name resolution works. Type:</p>
<pre class="brush: plain; title: ; notranslate">
ipconfig /all | more
</pre>
<p>And the output:</p>
<pre class="brush: plain; title: ; notranslate">
Windows IP Configuration

    Host Name . . . . . . . . . . . . : WIN-15VO4PNDU6T
    Primary Dns Suffix  . . . . . . . :
    Node Type . . . . . . . . . . . . : Hybrid
    IP Routing Enabled. . . . . . . . : No
    WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection 2:

    Connection-specific DNS Suffix  . :
    Description . . . . . . . . . . . : TAP-Windows Adapter V9
    Physical Address. . . . . . . . . : 00-FF-AB-E2-00-0B
    DHCP Enabled. . . . . . . . . . . : Yes
    Autoconfiguration Enabled . . . . : Yes
    Link-local IPv6 Address . . . . . : 
fe80::2d71:58da:776e:e903%15(Preferred)
    IPv4 Address. . . . . . . . . . . : 10.8.0.51(Preferred)
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Lease Obtained. . . . . . . . . . : Thursday, July 24, 2014 11:27:39 AM
    Lease Expires . . . . . . . . . . : Friday, July 24, 2015 11:27:38 AM
    Default Gateway . . . . . . . . . :
    DHCP Server . . . . . . . . . . . : 10.8.0.0
    DHCPv6 IAID . . . . . . . . . . . : 335609771
    DHCPv6 Client DUID. . . . . . . . : 
00-01-00-01-1B-46-4F-25-00-0C-29-60-32-7E
    DNS Servers . . . . . . . . . . . : 10.8.0.1
    NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Local Area Connection:
</pre>
<p>And type&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
nslookup
</pre>
<p>You should see something like this. Test with slashdot.org. This will test the forwarder, meaning your DNS server doesn&#8217;t know where is slashdot.org, but the forwarder 8.8.8.8 knows. </p>
<pre class="brush: plain; title: ; notranslate">
Default Server:  UnKnown
Address:  10.8.0.1

&gt; slashdot.org
Server:  UnKnown
Address:  10.8.0.1

Non-authoritative answer:
Name:    slashdot.org
Address:  216.34.181.45
</pre>
<h1>Enable ACL on the filesystem(s)</h1>
<p>Before we install Samba we have to enable ACLs (<a href="http://www.freebsd.org/doc/handbook/fs-acl.html" target="_blank" rel="noopener noreferrer">Access Control Lists</a>). Just add <strong>acls</strong> directive in <strong>/etc/fstab</strong>. In my case it looks like this.</p>
<pre class="brush: plain; title: ; notranslate">
# Device		Mountpoint		FStype		Options	Dump Pass
/dev/label/rootfs0	/		ufs	rw,noatime,acls	1	1
/dev/label/swap0	none		swap	sw	0	0
</pre>
<p>Do this for all file systems where you plan to have a Windows share. There is no need to reboot, just do:</p>
<pre class="brush: bash; title: ; notranslate">
mount -o acls /
</pre>
<h1>Configure time zone and ntpdate</h1>
<p>Find your time zone from this file <strong>/usr/share/zoneinfo</strong>. List the directory:</p>
<pre class="brush: bash; title: ; notranslate">
ls –l /usr/share/zoneinfo
</pre>
<p>In my case it’s <strong>America/New_York</strong> so I have to do:</p>
<pre class="brush: bash; title: ; notranslate">
cp /usr/share/zoneinfo/America/New_York /etc/localtime
</pre>
<p>If you have UTC which is default, after copying this file you’ll see that time will change to EDT. Type <strong>date</strong> to confirm: </p>
<pre class="brush: bash; title: ; notranslate">
date
</pre>
<p>In order to synchronize the time with an NTP server, execute:</p>
<pre class="brush: bash; title: ; notranslate">
ntpdate –v –b 0.north-america.pool.ntp.org
</pre>
<p>where <strong>0.north-america.pool.ntp.org</strong> is an <strong>NTP</strong> server that’s in US. Check the following <a href="http://www.pool.ntp.org" target="_blank" rel="noopener noreferrer">site</a> and pick up NTP server that’s closest to you.<br />
To start the time sync on boot, edit <strong>/etc/rc.conf</strong> and add these two lines after hostname.</p>
<pre class="brush: plain; title: ; notranslate">
ntpdate_enable=”YES”
ntpdate_hosts=”0.north-america.pool.ntp.org“
</pre>
<h1>Install Samba 4.1.9 server</h1>
<p>Samba depends on a lot of dependencies, so the compilation from source is going to take some time. Because we want to use BIND instead of built-in Samba DNS, we have to compile it from the source. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/net/samba41
make all install clean
</pre>
<p>Scroll down from the initial menu and choose BIND99 instead of NSUPDATE.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-04.png" alt="" width="586" height="318" class="aligncenter size-full wp-image-7098" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-04.png 586w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-04-300x163.png 300w" sizes="(max-width: 586px) 100vw, 586px" /></a><br />
After some time, when everything is done we have to provision the domain. These steps are crucial. If you mess up something or if you get an error, delete the following two files and start with the provisioning again. </p>
<pre class="brush: bash; title: ; notranslate">
rm /usr/local/etc/smb4.conf
rm -Rf /var/db/samba4/private
</pre>
<p>OK. So, let&#8217;s start. Again, my hostname is <strong>dc.fluffycloud.us</strong> and I want my NetBIOS domain to be <strong>IANDREEV</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
samba-tool domain provision --use-rfc2307 --host-ip=10.8.0.1 --interactive
</pre>
<p>This is the output. Replace the values to suit your needs. </p>
<pre class="brush: plain; title: ; notranslate">
Realm &#x5B;FLUFFYCLOUD.US]: FLUFFYCLOUD.US
Domain &#x5B;FLUFFYCLOUD]: IANDREEV
Server Role (dc, member, standalone) &#x5B;dc]: dc
DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) &#x5B;SAMBA_INTERNAL]: BIND9_DLZ
Administrator password: Password01
Retype password: Password01
Looking up IPv6 addresses
No IPv6 address will be assigned
Setting up share.ldb
Setting up secrets.ldb
Setting up the registry
Setting up the privileges database
Setting up idmap db
Setting up SAM db
Setting up sam.ldb partitions and settings
Setting up sam.ldb rootDSE
Pre-loading the Samba 4 and AD schema
Adding DomainDN: DC=fluffycloud,DC=us
Adding configuration container
Setting up sam.ldb schema
Setting up sam.ldb configuration data
Setting up display specifiers
Modifying display specifiers
Adding users container
Modifying users container
Adding computers container
Modifying computers container
Setting up sam.ldb data
Setting up well known security principals
Setting up sam.ldb users and groups
Setting up self join
Adding DNS accounts
Creating CN=MicrosoftDNS,CN=System,DC=fluffycloud,DC=us
Creating DomainDnsZones and ForestDnsZones partitions
Populating DomainDnsZones and ForestDnsZones partitions
See /var/db/samba4/private/named.conf for an example configuration include file for BIND
and /var/db/samba4/private/named.txt for further documentation required for secure DNS updates
Setting up sam.ldb rootDSE marking as synchronized
Fixing provision GUIDs
A Kerberos configuration suitable for Samba 4 has been generated at /var/db/samba4/private/krb5.conf
Setting up fake yp server settings
Once the above files are installed, your Samba4 server will be ready to use
Server Role:           active directory domain controller
Hostname:              dc
NetBIOS Domain:        IANDREEV
DNS Domain:            fluffycloud.us
DOMAIN SID:            S-1-5-21-3839416751-3718245204-1409092853
</pre>
<p>Before we start samba, we have to modify <strong>named.conf</strong> again. Edit <strong>/usr/local/etc/namedb/named.conf</strong> and add this line at the end.</p>
<pre class="brush: bash; title: ; notranslate">
include &quot;/var/db/samba4/private/named.conf&quot;;
</pre>
<p>Now edit file <strong>/var/db/samba4/private/named.conf</strong> and uncomment the line for 9.9 and comment the line for 9.8 like this.</p>
<pre class="brush: plain; title: ; notranslate">
dlz &quot;AD DNS Zone&quot; {
    # For BIND 9.8.0
    # database &quot;dlopen /usr/local/lib/shared-modules/bind9/dlz_bind9.so&quot;;

    # For BIND 9.9.0
    database &quot;dlopen /usr/local/lib/shared-modules/bind9/dlz_bind9_9.so&quot;;
};
</pre>
<p>Restart BIND with:</p>
<pre class="brush: bash; title: ; notranslate">
service named restart. 
</pre>
<p>Finally, start samba.</p>
<pre class="brush: bash; title: ; notranslate">
samba
</pre>
<p>Do some tests. </p>
<pre class="brush: bash; title: ; notranslate">
sockstat -4 | grep samba
</pre>
<p>If everything is OK, you&#8217;ll see a lot of output, if nothing comes up, check <strong>/var/log/messages</strong>.<br />
Do another test of the name resolution on the server, not on the client.</p>
<pre class="brush: plain; title: ; notranslate">
nslookup
</pre>
<p>Type <strong>dc.fluffycloud.us</strong> and it should return <strong>10.8.0.1</strong>.<br />
Another test. </p>
<pre class="brush: bash; title: ; notranslate">
smbclient -L localhost -U%
</pre>
<p>Output:</p>
<pre class="brush: plain; title: ; notranslate">
Domain=&#x5B;IANDREEV] OS=&#x5B;Unix] Server=&#x5B;Samba 4.1.9]

        Sharename       Type      Comment
        ---------       ----      -------
        netlogon        Disk
        sysvol          Disk
        IPC$            IPC       IPC Service (Samba 4.1.9)
Domain=&#x5B;IANDREEV] OS=&#x5B;Unix] Server=&#x5B;Samba 4.1.9]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
</pre>
<p>Another test. </p>
<pre class="brush: bash; title: ; notranslate">
smbclient //localhost/netlogon -UAdministrator -c 'ls'
</pre>
<p>And the output.</p>
<pre class="brush: plain; title: ; notranslate">
Enter Administrator's password:Password01
Domain=&#x5B;IANDREEV] OS=&#x5B;Unix] Server=&#x5B;Samba 4.1.9]
  .                                   D        0  Fri Jul 25 20:41:48 2014
  ..                                  D        0  Fri Jul 25 20:41:54 2014

                51697 blocks of size 262144. 37389 blocks available
</pre>
<p>More tests. </p>
<pre class="brush: bash; title: ; notranslate">
host -t SRV _ldap._tcp.fluffycloud.us.
</pre>
<p><code><br />
_ldap._tcp.fluffycloud.us has SRV record 0 100 389 dc.fluffycloud.us.<br />
</code></p>
<pre class="brush: bash; title: ; notranslate">
host -t SRV _kerberos._udp.fluffycloud.us.
</pre>
<p><code><br />
_kerberos._udp.fluffycloud.us has SRV record 0 100 88 dc.fluffycloud.us.<br />
</code></p>
<pre class="brush: bash; title: ; notranslate">
host -t A dc.fluffycloud.us.
</pre>
<p><code><br />
dc.fluffycloud.us has address 10.8.0.1<br />
</code></p>
<pre class="brush: bash; title: ; notranslate">
kinit administrator@FLUFFYCLOUD.US
</pre>
<p>administrator@FLUFFYCLOUD.US&#8217;s Password:Password01<br />
<code><br />
There shouldn't be any output.<br />
</code></p>
<pre class="brush: bash; title: ; notranslate">
klist
</pre>
<p><code><br />
Credentials cache: FILE:/tmp/krb5cc_0<br />
        Principal: administrator@FLUFFYCLOUD.US</p>
<p>  Issued                Expires               Principal<br />
Jul 25 20:50:15 2014  Jul 26 06:50:15 2014  krbtgt/FLUFFYCLOUD.US@FLUFFYCLOUD.US<br />
</code></p>
<p>If all tests passed, you are all set. You just have to add:</p>
<pre class="brush: bash; title: ; notranslate">
samba_server_enable=&quot;YES&quot;
</pre>
<p>in your <strong>/etc/rc.conf</strong> so Samba starts automatically on boot.<br />
The order of the commands is important, so here is my <strong>/etc/rc.conf</strong>.</p>
<pre class="brush: plain; title: ; notranslate">
ifconfig_vtnet0=&quot;inet 209.222.2.147 netmask 255.255.255.224&quot;
defaultrouter=&quot;209.222.2.129&quot;
hostname=&quot;dc.fluffycloud.us&quot;
ntpdate_enable=&quot;YES&quot;
ntpdate_hosts=&quot;0.north-america.pool.ntp.org&quot;
cloned_interfaces=&quot;tap0 bridge0&quot;
ifconfig_tap0=&quot;10.8.0.1/24&quot;
ifconfig_bridge0=&quot;addm tap0 addm vtnet0 up&quot;
sshd_enable=YES
named_enable=&quot;YES&quot;
openvpn_enable=&quot;YES&quot;
samba_server_enable=&quot;YES&quot;
</pre>
<h1>Testing and managing the domain controller</h1>
<p>On your Windows computer, install <strong>DcDiag</strong> from <a href="http://www.microsoft.com/en-us/download/details.aspx?id=31063" target="_blank" rel="noopener noreferrer">here</a>. Make sure that you are connected to the OpenVPN server and that you have an IP in that range (<strong>10.8.0.0/24</strong>). Do <strong>nslookup</strong> from command prompt. It should return <strong>10.8.0.1</strong>. Also, make sure that when you query for your FQDN it actually returns <strong>10.8.0.1</strong>, not the public IP. This is how it should look like.</p>
<pre class="brush: plain; title: ; notranslate">
C:\Users\Kliment&gt;nslookup
Default Server:  UnKnown
Address:  10.8.0.1
&gt; dc.fluffycloud.us
Server:  UnKnown
Address:  10.8.0.1

Name:    dc.fluffycloud.us
Address:  10.8.0.1
</pre>
<p>Go to <strong>c:\Program Files (x86)\Resource Kit</strong> folder and do:</p>
<pre class="brush: plain; title: ; notranslate">
c:\Program Files (x86)\Resource Kit&gt;dcdiag /s:dc.fluffycloud.us /u:andreev\Administrator /p:Password01
</pre>
<p>You will see that some tests will fail. That&#8217;s OK. As long as the output looks like mine below, you should be OK.</p>
<pre class="brush: plain; title: ; notranslate">
Domain Controller Diagnosis

Performing initial setup:
   Done gathering initial info.

Doing initial required tests

   Testing server: Default-First-Site-Name\DC
      Starting test: Connectivity
         ......................... DC passed test Connectivity

Doing primary tests

   Testing server: Default-First-Site-Name\DC
      Starting test: Replications
         ......................... DC passed test Replications
      Starting test: NCSecDesc
         ......................... DC passed test NCSecDesc
      Starting test: NetLogons
         ......................... DC passed test NetLogons
      Starting test: Advertising
         ......................... DC passed test Advertising
      Starting test: KnowsOfRoleHolders
         ......................... DC passed test KnowsOfRoleHolders
      Starting test: RidManager
         ......................... DC passed test RidManager
      Starting test: MachineAccount
         ......................... DC passed test MachineAccount
      Starting test: Services
            Could not open Dnscache Service on &#x5B;DC]:failed with 8: Not enough st
orage is available to process this command.
            Could not open NtFrs Service on &#x5B;DC]:failed with 8: Not enough stora
ge is available to process this command.
            Could not open IsmServ Service on &#x5B;DC]:failed with 8: Not enough sto
rage is available to process this command.
            Could not open kdc Service on &#x5B;DC]:failed with 8: Not enough storage
 is available to process this command.
            Could not open SamSs Service on &#x5B;DC]:failed with 8: Not enough stora
ge is available to process this command.
            Could not open LanmanServer Service on &#x5B;DC]:failed with 8: Not enoug
h storage is available to process this command.
            Could not open LanmanWorkstation Service on &#x5B;DC]:failed with 8: Not
enough storage is available to process this command.
            Could not open RpcSs Service on &#x5B;DC]:failed with 8: Not enough stora
ge is available to process this command.
            Could not open w32time Service on &#x5B;DC]:failed with 8: Not enough sto
rage is available to process this command.
         ......................... DC failed test Services
      Starting test: ObjectsReplicated
         Failed to read object metadata on DC, error The request is not supporte
d.
         Failed to read object metadata on DC, error The request is not supporte
d.
         ......................... DC passed test ObjectsReplicated
      Starting test: frssysvol
         The SysVol is not ready.  This can cause the DC to not advertise
         itself as a DC for netlogon after dcpromo.  Also trouble with FRS
         SysVol replication can cause Group Policy problems.  Check the FRS
         event log on this DC.
         ......................... DC failed test frssysvol
      Starting test: frsevent
         Error 161 opening FRS eventlog \\DC:File Replication Service:
 The specified path is invalid.
         ......................... DC failed test frsevent
      Starting test: kccevent
         Error 161 opening FRS eventlog \\DC:Directory Service:
 The specified path is invalid.
         Failed to enumerate event log records, error The specified path is inva
lid.
         ......................... DC failed test kccevent
      Starting test: systemlog
         Error 161 opening FRS eventlog \\DC:System:
 The specified path is invalid.
         Failed to enumerate event log records, error The specified path is inva
lid.
         ......................... DC failed test systemlog
      Starting test: VerifyReferences
         Some objects relating to the DC DC have problems:
            &#x5B;1] Problem: Missing Expected Value
             Base Object: CN=DC,OU=Domain Controllers,DC=fluffycloud,DC=us
             Base Object Description: &quot;DC Account Object&quot;
             Value Object Attribute Name: frsComputerReferenceBL
             Value Object Description: &quot;SYSVOL FRS Member Object&quot;
             Recommended Action: See Knowledge Base Article: Q312862

            &#x5B;1] Problem: Missing Expected Value
             Base Object:
            CN=NTDS Settings,CN=DC,CN=Servers,CN=Default-First-Site-Name,CN=Site
s,CN=Configuration,DC=fluffycloud,DC=us
             Base Object Description: &quot;DSA Object&quot;
             Value Object Attribute Name: serverReferenceBL
             Value Object Description: &quot;SYSVOL FRS Member Object&quot;
             Recommended Action: See Knowledge Base Article: Q312862

         ......................... DC failed test VerifyReferences

   Running partition tests on : Configuration
      Starting test: CrossRefValidation
         ......................... Configuration passed test CrossRefValidation
      Starting test: CheckSDRefDom
         ......................... Configuration passed test CheckSDRefDom

   Running partition tests on : Schema
      Starting test: CrossRefValidation
         ......................... Schema passed test CrossRefValidation
      Starting test: CheckSDRefDom
         ......................... Schema passed test CheckSDRefDom

   Running partition tests on : fluffycloud
      Starting test: CrossRefValidation
         ......................... fluffycloud passed test CrossRefValidation
      Starting test: CheckSDRefDom
         ......................... fluffycloud passed test CheckSDRefDom

   Running partition tests on : DomainDnsZones
      Starting test: CrossRefValidation
         ......................... DomainDnsZones passed test CrossRefValidation

      Starting test: CheckSDRefDom
            The application directory partition
            DC=DomainDnsZones,DC=fluffycloud,DC=us is missing a security
            descriptor reference domain.  The administrator should set the
            msDS-SD-Reference-Domain attribute on the cross reference object
            CN=a3a9e7bb-205b-44d8-9427-7647f64cb839,CN=Partitions,CN=Configurati
on,DC=fluffycloud,DC=us
            to the DN of a domain.
         ......................... DomainDnsZones failed test CheckSDRefDom

   Running partition tests on : ForestDnsZones
      Starting test: CrossRefValidation
         ......................... ForestDnsZones passed test CrossRefValidation

      Starting test: CheckSDRefDom
            The application directory partition
            DC=ForestDnsZones,DC=fluffycloud,DC=us is missing a security
            descriptor reference domain.  The administrator should set the
            msDS-SD-Reference-Domain attribute on the cross reference object
            CN=a4b7fc27-1dd7-4b9f-8443-d0c445ee817f,CN=Partitions,CN=Configurati
on,DC=fluffycloud,DC=us
            to the DN of a domain.
         ......................... ForestDnsZones failed test CheckSDRefDom

   Running enterprise tests on : fluffycloud.us
      Starting test: Intersite
         ......................... fluffycloud.us passed test Intersite
      Starting test: FsmoCheck
         ......................... fluffycloud.us passed test FsmoCheck
</pre>
<p>At this point you can join the domain. For the domain, type the REALM name, not the FQDN. See below.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-05.png" alt="" width="330" height="385" class="aligncenter size-full wp-image-7099" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-05.png 330w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-05-257x300.png 257w" sizes="(max-width: 330px) 100vw, 330px" /></a><br />
Once you join the domain, you&#8217;ll be prompted to restart your computer. Do that, but log back to your computer as local admin. If you try to log in as the domain administrator, you&#8217;ll receive an error that there are no logon servers available. Why? Because, once you restart, the VPN connection to the domain is gone. What you can do is, log as local admin, establish VPN again and then click to switch user and log as the domain admin. Next time you reboot, you don&#8217;t have to be logged as the domain admin because of the cached credentials. But, that&#8217;s not the way I wanted it. I want to be able to log to the domain at anytime. Unfortunately, OpenVPN client doesn&#8217;t work as a service, but we can do a trick. In the same <strong>bin</strong> folder (<strong>C:\Program Files\OpenVPN\bin\</strong>) where <strong>openvpn-gui</strong> is, there is another executable &#8211; <strong>openvpn.exe</strong>. This is the CLI version. In order to connect to a server, you have to specify the path to the config file with the <strong>&#8211;config</strong> parameter.<br />
This is what we will do. Go to <strong>Accessories</strong>, <strong>System Tools</strong> and start the <strong>Task Scheduler</strong>. Click to <strong>Create Basic Task</strong>&#8230;Follow the screenshots below.</p>
<p>Type a description here and click Next.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-06.png" alt="" width="702" height="490" class="aligncenter size-full wp-image-7100" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-06.png 702w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-06-300x209.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-06-585x408.png 585w" sizes="(max-width: 702px) 100vw, 702px" /></a><br />
Choose when the Computer starts and Next.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-07.png" alt="" width="698" height="482" class="aligncenter size-full wp-image-7101" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-07.png 698w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-07-300x207.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-07-585x404.png 585w" sizes="(max-width: 698px) 100vw, 698px" /></a><br />
Select Start a program and Next.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-08.png" alt="" width="700" height="485" class="aligncenter size-full wp-image-7102" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-08.png 700w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-08-300x208.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-08-585x405.png 585w" sizes="(max-width: 700px) 100vw, 700px" /></a><br />
For the program type <strong>&#8220;C:\Program Files\OpenVPN\bin\openvpn.exe&#8221;</strong> and for the arguments use <strong>&#8211;config &#8220;C:\Program Files\OpenVPN\config\client.ovpn&#8221;<br />
</strong><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-09.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-09.png" alt="" width="698" height="494" class="aligncenter size-full wp-image-7103" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-09.png 698w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-09-300x212.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-09-585x414.png 585w" sizes="(max-width: 698px) 100vw, 698px" /></a><br />
Select to open the properties dialog and click Finish.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-10.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-10.png" alt="" width="702" height="493" class="aligncenter size-full wp-image-7104" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-10.png 702w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-10-300x211.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-10-585x411.png 585w" sizes="(max-width: 702px) 100vw, 702px" /></a><br />
Click on <strong>Change User or Group </strong>and choose <strong>SYSTEM</strong>. Select <strong>Run with highest privileges</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-11.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-11.png" alt="" width="637" height="481" class="aligncenter size-full wp-image-7105" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-11.png 637w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-11-300x227.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-11-585x442.png 585w" sizes="(max-width: 637px) 100vw, 637px" /></a><br />
Reboot and you should be able to log as domain admin. You won&#8217;t see any icons in the tray, but if you hit <strong>CTRL-ALT-DEL</strong> you&#8217;ll see the openvpn.exe running.</p>
<p>Finally, go to this <a href="http://www.microsoft.com/en-us/download/details.aspx?id=7887" target="_blank" rel="noopener noreferrer">site</a> and download <strong>Remote Server Administration Tools for Windows 7 with SP1</strong>. Once installed, go to <strong>Control Panel</strong>, <strong>Programs and Features</strong>, <strong>Turn Windows Features on or off</strong> and select the tools that you want to show up under <strong>Administrative Tools</strong> in your Start Menu. These tools are for managing users, computers, DNS etc&#8230;<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-12.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-12.png" alt="" width="637" height="450" class="aligncenter size-full wp-image-7106" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-12.png 637w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-12-300x212.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-12-585x413.png 585w" sizes="(max-width: 637px) 100vw, 637px" /></a><br />
Finally, here is how to create a Windows share and map it through a logon script. I&#8217;ve used this <a href="https://wiki.samba.org/index.php/Setup_and_configure_file_shares_with_Windows_ACLs" target="_blank" rel="noopener noreferrer">link</a>. Because we don&#8217;t have a member server, first thing is to grant some rights to the domain administrator.</p>
<pre class="brush: bash; title: ; notranslate">
net rpc rights grant 'IANDREEV\Domain Admins' SeDiskOperatorPrivilege -Uadministrator
</pre>
<p>Edit <strong>/usr/local/etc/smb4.conf</strong> and define the share.</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;share]
        path = /home/folder
        read only = no
</pre>
<p>Then reload the config with:</p>
<pre class="brush: bash; title: ; notranslate">
smbcontrol all reload-config
</pre>
<p>In Windows 7, Open <strong>Computer Management</strong> (compmgmt.msc). Right-click on <strong>Computer Management (Local)</strong> and choose to connect to another computer (fluffycloud.us). Expand System Tools, Shared Folders and your new share will be there.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P045-13.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P045-13.png" alt="" width="551" height="131" class="aligncenter size-full wp-image-7107" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P045-13.png 551w, https://blog.andreev.it/wp-content/uploads/2014/07/P045-13-300x71.png 300w" sizes="(max-width: 551px) 100vw, 551px" /></a><br />
Right-click on the share and if you don&#8217;t see the Permissions tab, <a href="http://www.7tutorials.com/how-disable-sync-center-offline-files-windows-7" target="_blank" rel="noopener noreferrer">disable the Offline files</a>. Reboot. If you still don&#8217;t see the Permissions tab, just log off and log back on. Now, create a text file called <strong>logon.bat</strong> with the following inside.</p>
<pre class="brush: bash; title: ; notranslate">
@echo off
net use h: \\dc\share /persistent:YES
</pre>
<p>Copy this file under \\dc\netlogon folder and change the user settings in AD to use this logon script. You might not see this share mapped automatically, because how we setup OpenVPN, but if you double-click the batch file, you&#8217;ll see the folder mapped thru reboots.</p>
<h1>Configure the pf firewall</h1>
<p>If you did all these steps and everything works, great! But, this is how your server will look like on the Internet after a basic port scan. Make sure you are <strong>NOT</strong> connected to the VPN. </p>
<pre class="brush: plain; title: ; notranslate">
c:\&gt;nmap -Pn dc.fluffycloud.us

Starting Nmap 6.46 ( http://nmap.org ) at 2014-07-26 18:32 Eastern Daylight Time

Nmap scan report for dc.fluffycloud.us (209.222.2.147)
Host is up (0.019s latency).
Not shown: 987 closed ports
PORT     STATE    SERVICE
22/tcp   open     ssh
25/tcp   filtered smtp
88/tcp   open     kerberos-sec
113/tcp  filtered ident
135/tcp  filtered msrpc
139/tcp  filtered netbios-ssn
389/tcp  open     ldap
445/tcp  filtered microsoft-ds
464/tcp  open     kpasswd5
636/tcp  open     ldapssl
1024/tcp open     kdm
3268/tcp open     globalcatLDAP
3269/tcp open     globalcatLDAPssl

Nmap done: 1 IP address (1 host up) scanned in 23.88 seconds
c:\&gt;
</pre>
<p>This is no-no. We&#8217;ll restrict the ports with pf firewall, so they are accessible only over VPN.<br />
Edit /etc/rc.conf and add these two lines at the end.</p>
<pre class="brush: bash; title: ; notranslate">
pf_enable=&quot;YES&quot;
pflog_enable=&quot;YES&quot;
</pre>
<p>Edit the firewall config file, <strong>/etc/pf.conf</strong> and paste these values. If you already have firewall rules there, you have to modify them.</p>
<pre class="brush: bash; title: ; notranslate">
# Interfaces
ext_if = &quot;vtnet0&quot;       # Internet Interface
vpn_if = &quot;tap0&quot;         # OpenVPN Interface

# Externally permitted inbound icmp types
icmp_types= &quot;echoreq&quot;

set loginterface $ext_if
set skip on lo0

# table &lt;bruteforce&gt; persist
# tcp_pass = &quot;{ 80 }&quot;

# Network address translation
nat on $ext_if from !($ext_if) -&gt; ($ext_if:0)

# NAT the VPN connections (for access to the remote secure networks)
nat on $vpn_if from !($ext_if) -&gt; ($vpn_if:0)

# Restrictive default rules
block all

# Allow SSH
# block quick from &lt;bruteforce&gt;
# pass quick proto { tcp, udp } from any to any port ssh \
    flags S/SA keep state \
    (max-src-conn 15, max-src-conn-rate 5/3, \
    overload &lt;bruteforce&gt; flush global)

# Allow tcp ports from tcp_pass table above
# pass log on $ext_if proto tcp to any port $tcp_pass keep state

# Allow permitted icmp (ping)
pass in on $ext_if inet proto icmp all icmp-type $icmp_types keep state

# VPN connections inbound
pass in on $ext_if proto udp from any to port 1194 keep state
pass quick on $vpn_if keep state

# Filter rules for $ext_if outbound
pass out on $ext_if keep state
</pre>
<p>Make sure you have an access to the console. After you reboot and apply these rules, your SSH sessions are GONE and you won&#8217;t be able to connect. Do another port scan without VPN connection. You are actually simulating how someone else will see your server. </p>
<p>If you think that these rules are too restrictive, allow SSH access from outside by removing comments from lines 11, 24 and 25. If you want other protocols, add them to the table at line 12 and uncomment both lines 12 and 31. </p>
<pre class="brush: plain; title: ; notranslate">
c:\&gt;nmap -Pn dc.fluffycloud.us

Starting Nmap 6.46 ( http://nmap.org ) at 2014-07-26 18:41 Eastern Daylight Time

Nmap scan report for dc.fluffycloud.us (209.222.2.147)
Host is up.
All 1000 scanned ports on dc.fluffycloud.us (209.222.2.147) are filtered

Nmap done: 1 IP address (1 host up) scanned in 214.71 seconds
</pre>
<p>Much better. Now try to establish a VPN connection. Start the task from <strong>Task Scheduler</strong> or use <strong>OpenVPN GUI</strong>. At this point, <strong>dc.fluffycloud.us</strong> should resolve as <strong>10.8.0.1</strong>. So, let&#8217;s do another port scan.</p>
<pre class="brush: plain; title: ; notranslate">
c:\&gt;nmap -Pn dc.fluffycloud.us

Starting Nmap 6.46 ( http://nmap.org ) at 2014-07-26 18:48 Eastern Daylight Time

Nmap scan report for dc.fluffycloud.us (10.8.0.1)
Host is up (0.016s latency).
Not shown: 988 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
53/tcp   open  domain
88/tcp   open  kerberos-sec
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
389/tcp  open  ldap
445/tcp  open  microsoft-ds
464/tcp  open  kpasswd5
636/tcp  open  ldapssl
1024/tcp open  kdm
3268/tcp open  globalcatLDAP
3269/tcp open  globalcatLDAPssl
MAC Address: 00:BD:B9:00:00:00 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 14.09 seconds
</pre>
<p>You are all set.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2014/07/freebsd-10-samba-4-as-a-domain-controller-running-on-a-public-ip-openvpn-bind-pf/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
