<?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>OpenVPN &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/openvpn/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Fri, 22 Nov 2024 16:36:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>FreeBSD: OpenVPN server in a LAN (local network) environment</title>
		<link>https://blog.andreev.it/2024/11/freebsd-openvpn-server-in-a-lan-local-network-environment/</link>
					<comments>https://blog.andreev.it/2024/11/freebsd-openvpn-server-in-a-lan-local-network-environment/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Fri, 22 Nov 2024 16:36:12 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[pf]]></category>
		<category><![CDATA[VPN]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=10074</guid>

					<description><![CDATA[In this post I&#8217;ll describe a use case that I am currently using. I&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll describe a use case that I am currently using. I have a standard Internet connection that goes to my Eero mesh router and behind that I have a homelab on 192.168.1.0/24 network as shown in the diagram. I have a port forwarding configured on the router so I can access one of my Linux servers, but if I want to access other servers, I have to either port forward SSH on some other-than-22/tcp port or use the Linux server as a jump-box. None of this is good, so I decided to create an OpenVPN server. Anytime I VPN to this server I can ssh/rdp to any of the internal servers. The OpenVPN server requires one nic.<br />
<strong>NOTE</strong>: This post is very FreeBSD specific so if you want to use some Linux server as OpenVPN server, this guide won&#8217;t help you at all.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2024/11/P177-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2024/11/P177-01.png" alt="" width="721" height="491" class="aligncenter size-full wp-image-10078" srcset="https://blog.andreev.it/wp-content/uploads/2024/11/P177-01.png 721w, https://blog.andreev.it/wp-content/uploads/2024/11/P177-01-300x204.png 300w, https://blog.andreev.it/wp-content/uploads/2024/11/P177-01-585x398.png 585w" sizes="(max-width: 721px) 100vw, 721px" /></a><br />
<strong>IMPORTANT</strong>: On your home router port-forward port 1194/udp to your OpenVPN server.</p>
<h1>OpenVPN server</h1>
<p>Let&#8217;s install OpenVPN server first.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install openvpn
</pre>
<p>Make sure it starts on boot and enable the NAT.</p>
<pre class="brush: bash; title: ; notranslate">
sysrc openvpn_enable=YES
sysrc gateway_enable=YES
</pre>
<p>Next, we need a directory where we&#8217;ll store our config files and the PKI.</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /usr/local/etc/openvpn
cd /usr/local/etc/openvpn
</pre>
<p>Create the PKI structure.</p>
<pre class="brush: bash; title: ; notranslate">
easyrsa init-pki
</pre>
<p>Go to the newly created <em>pki </em>directory and make a copy of the <em>vars.example</em> file.</p>
<pre class="brush: bash; title: ; notranslate">
cd pki
cp vars.example vars
</pre>
<p>Now edit this file and uncomment the following lines and change to match your needs. It&#8217;s optional and you can keep everything-as-is.</p>
<pre class="brush: bash; title: ; notranslate">
set_var EASYRSA_REQ_COUNTRY     &quot;US&quot;
set_var EASYRSA_REQ_PROVINCE    &quot;NJ&quot;
set_var EASYRSA_REQ_CITY        &quot;Allentown&quot;
set_var EASYRSA_REQ_ORG         &quot;iAndreev&quot;
set_var EASYRSA_REQ_EMAIL       &quot;mail@somemail.com&quot;
set_var EASYRSA_REQ_OU          &quot;iAndreev&quot;
set_var EASYRSA_CA_EXPIRE       3650
set_var EASYRSA_CERT_EXPIRE     825
</pre>
<p>Now create the Certificate Authority based on these values.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc/openvpn
easyrsa build-ca
</pre>
<p>This command will prompt you to create a password that you will you to sign the certificates for the server and the clients.<br />
Then create the DH parameters. It might take 30+ seconds.</p>
<pre class="brush: bash; title: ; notranslate">
easyrsa gen-dh
</pre>
<p>Create the server request and sign it.</p>
<pre class="brush: bash; title: ; notranslate">
easyrsa build-server-full server nopass
</pre>
<p>You have to type <em>yes </em>to confirm and then use the password that you created above to sign the cert.<br />
The command will create some files under the <em>pki </em>directory and we&#8217;ll need those later.<br />
Next, we&#8217;ll create the same for the client. In my case it&#8217;s a Dell laptop, so I use the word dell, but you can use client, client1, something-whatever&#8230;</p>
<pre class="brush: bash; title: ; notranslate">
easyrsa build-client-full dell nopass
</pre>
<p>Same thing, answer <em>yes </em>and then use the password to sign the certs.<br />
Copy the OpenVPN config example file that comes with the package.</p>
<pre class="brush: bash; title: ; notranslate">
cp /usr/local/share/examples/openvpn/sample-config-files/server.conf /usr/local/etc/openvpn/openvpn.conf
</pre>
<p>Edit<em> openvpn.conf</em> and make sure these values are changed and match the certs you created earlier.</p>
<pre class="brush: bash; title: ; notranslate">
ca /usr/local/etc/openvpn/pki/ca.crt
cert /usr/local/etc/openvpn/pki/issued/server.crt
key /usr/local/etc/openvpn/pki/private/server.key

dh /usr/local/etc/openvpn/pki/dh.pem
</pre>
<p>In addition to that, find the line that says push route and create a new one that matches your internal subnet. In my case it looks like this.</p>
<pre class="brush: bash; title: ; notranslate">
push &quot;route 192.168.1.0 255.255.255.0&quot;
</pre>
<p>If you have internal DNS and you want to send that as well, uncomment the following line and change to match your DNS IP.</p>
<pre class="brush: bash; title: ; notranslate">
push &quot;dhcp-option DNS 208.67.222.222&quot;
</pre>
<p>Now, you can start the OpenVPN server. Make sure you check the syslog for any errors.</p>
<pre class="brush: bash; title: ; notranslate">
service openvpn start
tail /var/log/messages
</pre>
<h1>OpenVPN client</h1>
<p>On your laptop that you want to use as a VPN client, download the OpenVPN client from <a href="https://openvpn.net/community-downloads/" target="_blank">here</a>. When you install the client, you&#8217;ll have a generic config file under <em>C:\Program Files\OpenVPN\sample-config</em> folder. Copy that file under <em>c:\users\[your_username]\OpenVPN\config</em>.<br />
Then, edit the file and change the following lines.</p>
<pre class="brush: bash; title: ; notranslate">
remote public-ip-or-hostname-of-your-router 1194
ca ca.crt
cert dell.crt
key dell.key
</pre>
<p>NOTE: Make sure you copy <em>ca.crt</em> from <em>/usr/local/etc/openvpn/pki</em>, <em>dell.crt</em> or client.crt or whatever.crt from <em>/usr/local/etc/openvpn/pki/issued</em> and<em> dell.key</em> or client.key or whatever.key from <em>/usr/local/etc/openvpn/pki/private</em> directories to the same <em>c:\users\[your-user-name]\OpenVPN\config</em> folder. There should be 4 files there. The config file, the CA certificate, the client certificate and the private key for the client.<br />
Start the OpenVPN client and connect. You shouldn&#8217;t have any problems and you&#8217;ll get 10.8.0.2 IP assigned to your laptop. If you try to ping 10.8.0.1 you&#8217;ll get a response. Do route print and you&#8217;ll see that the routes for 192.168.1.0 are going over 10.8.0.1. But, if you try to ping some server internally, e.g. 192.168.1.21, you won&#8217;t get any response. That&#8217;s because that server doesn&#8217;t know the route back. You can easily add the route to each server but it&#8217;s not practical. Let&#8217;s make one more change to the server.</p>
<h1>OpenVPN server</h1>
<p>Add these two lines to <em>/etc/rc.conf</em>. That&#8217;s the FreeBSD pf firewall.</p>
<pre class="brush: bash; title: ; notranslate">
pf_enable=&quot;YES&quot;
pf_rules=&quot;/etc/pf.conf&quot;
</pre>
<p>Now, create this config file in <em>/etc/pf.conf</em>. Many thanks to <a href="https://gundersen.net/openvpn-server-on-freebsd-with-pf-firewall/" target="_blank">this </a>guy. </p>
<pre class="brush: bash; title: ; notranslate">
vpnclients = &quot;10.8.0.0/24&quot;
# The name of your NIC. I am using a VM on ESXi and vmx0 is my NIC.
wanint = &quot;vmx0&quot;
# put your tunnel interface here, it is usually tun0
vpnint = &quot;tun0&quot;
# OpenVPN by default runs on udp port 1194
udpopen = &quot;{1194}&quot;
# Open the SSH port.
tcpopen = &quot;{22}&quot;
icmptypes = &quot;{echoreq, unreach}&quot;

set skip on lo
# the essential line
nat on $wanint inet from $vpnclients to any -&gt; $wanint

block in
pass in on $wanint proto udp from any to $wanint port $udpopen
pass in on $wanint proto tcp from any to $wanint port $tcpopen
# the following two lines could be made stricter if you don&#039;t trust the clients
pass out quick
pass in on $vpnint from any to any
pass in inet proto icmp all icmp-type $icmptypes
</pre>
<p>Reboot the OpenVPN server and if you reconnect from the client, you can use the internal IPs directly to connect.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2024/11/freebsd-openvpn-server-in-a-lan-local-network-environment/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 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 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>
		<item>
		<title>FreeBSD: openvpn 2.3.4 server on FreeBSD 10</title>
		<link>https://blog.andreev.it/2014/07/freebsd-10-openvpn-2-3-4/</link>
					<comments>https://blog.andreev.it/2014/07/freebsd-10-openvpn-2-3-4/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 02 Jul 2014 01:05:29 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[VPN]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=1376</guid>

					<description><![CDATA[In this post I&#8217;ll describe how to install openvpn running as a server on&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll describe how to install openvpn running as a server on FreeBSD 10 and then how to use a Windows 7 client to connect to it. The FreeBSD in my case runs in the cloud (public IP) and the Windows 7 runs at home.</p>
<p>First, let&#8217;s install <a href="https://openvpn.net/index.php/open-source/documentation/howto.html" target="_blank" rel="noopener noreferrer">openvpn</a>.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/security/openvpn
make all install clean
</pre>
<p>Accept the defaults for openvpn and lzo compression utility. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-01.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-01.png" alt="" width="664" height="232" class="aligncenter size-full wp-image-7079" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-01.png 664w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-01-300x105.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-01-585x204.png 585w" sizes="(max-width: 664px) 100vw, 664px" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-02.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-02.png" alt="" width="674" height="168" class="aligncenter size-full wp-image-7080" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-02.png 674w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-02-300x75.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-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>Go to</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/etc/rc.d
./openvpn
</pre>
<p>This is how you start, stop openvpn.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-03.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-03.png" alt="" width="730" height="88" class="aligncenter size-full wp-image-7081" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-03.png 730w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-03-300x36.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-03-585x71.png 585w" sizes="(max-width: 730px) 100vw, 730px" /></a><br />
Before we can start openvpn, we need the configuration file.</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 this file if you want to change something, in my case I didn&#8217;t have to change anything. </p>
<p>openvpn relies on certificates, so we can generate them like this.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/local/share/easy-rsa/
sh
. ./vars
./clean-all
./build-ca
</pre>
<p>See the example below for my settings, it&#8217;s pretty much self-explanatory. If you want a blank value, use &#8220;.&#8221; (dot).<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-04.png" alt="" width="730" height="190" class="aligncenter size-full wp-image-7082" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-04.png 730w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-04-300x78.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-04-585x152.png 585w" sizes="(max-width: 730px) 100vw, 730px" /></a><br />
That was the certificate authority, now we need a server certificate.</p>
<pre class="brush: bash; title: ; notranslate">
./build-key-server server
</pre>
<p>Same thing, see the example below. At the end, sign the certificate by typing &#8220;y&#8221;.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-05.png" alt="" width="712" height="355" class="aligncenter size-full wp-image-7083" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-05.png 712w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-05-300x150.png 300w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-05-585x292.png 585w" sizes="(max-width: 712px) 100vw, 712px" /></a><br />
Now, let&#8217;s create a certificate for one client. In my case, the hostname is liquid. The name of the client host doesn&#8217;t matter, it&#8217;s more like a unique description, but <strong>make sure that the common name is unique</strong>. Otherwise, you&#8217;ll receive an error saying &#8220;<em>failed to update database, TXT_DB error number 2</em>&#8220;.Sign the certificate as well.  </p>
<pre class="brush: bash; title: ; notranslate">
./build-key liquid
</pre>
<p>Finally, build the certificate parameters.</p>
<pre class="brush: bash; title: ; notranslate">
./build-dh
</pre>
<p>Now that the certificates are generated, go to that folder and copy the certificate to our openvpn config folder.</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>At this point, we can start the openvpn server.</p>
<pre class="brush: bash; title: ; notranslate">
/usr/local/etc/rc.d/openvpn start
</pre>
<p>Check <strong>/var/log/messages</strong> for any errors. </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>
<p>Once we have the server up and running, we should configure the client.<br />
On your Windows machine, install the openvpn from <a href="https://openvpn.net/index.php/open-source/downloads.html" target="_blank" rel="noopener noreferrer">here</a>. </p>
<p>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.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-06.png" alt="" width="442" height="213" class="aligncenter size-full wp-image-7084" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-06.png 442w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-06-300x145.png 300w" sizes="(max-width: 442px) 100vw, 442px" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-07.png" alt="" width="427" height="206" class="aligncenter size-full wp-image-7085" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-07.png 427w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-07-300x145.png 300w" sizes="(max-width: 427px) 100vw, 427px" /></a><br />
Edit the <strong>client.ovpn</strong> file and change the values for the server and the path to the client certificates. In my case I had to specify <strong>mycloudserver.org</strong> and I&#8217;ve decided to keep the certificates under <strong>c:\keys</strong>. (Note: use double back-slash). If you are having problems saving the file under <strong>C:\Program Files</strong>, save it on the desktop first and then manually copy it over to <strong>C:\Program Files\OpenVPN\config</strong> folder.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-08.png" alt="" width="298" height="162" class="aligncenter size-full wp-image-7086" /></a><br />
Copy these three files from the server (<strong>/usr/local/share/easy-rsa/keys</strong>) under <strong>c:\keys</strong> folder on your Windows 7 machine.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-09.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-09.png" alt="" width="250" height="83" class="aligncenter size-full wp-image-7087" /></a><br />
Then, make sure that openvpn executables always start with full admin privileges. Go to the <strong>bin</strong> folder, right click each 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/P044-10.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-10.png" alt="" width="376" height="263" class="aligncenter size-full wp-image-7088" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-10.png 376w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-10-300x210.png 300w" sizes="(max-width: 376px) 100vw, 376px" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-11.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-11.png" alt="" width="409" height="525" class="aligncenter size-full wp-image-7089" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-11.png 409w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-11-234x300.png 234w" sizes="(max-width: 409px) 100vw, 409px" /></a><br />
The OpenVPN GUI creates an icon in the tray, right-click that icon and click <strong>Connect</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-12.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-12.png" alt="" width="209" height="204" class="aligncenter size-full wp-image-7090" /></a><br />
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 OpenVPN GUI icon and choose <strong>View log</strong>. If you have a firewall enabled, allow port 1194 UDP.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-13.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-13.png" alt="" width="260" height="146" class="aligncenter size-full wp-image-7091" /></a><br />
<a href="https://blog.andreev.it/wp-content/uploads/2014/07/P044-14.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2014/07/P044-14.png" alt="" width="406" height="107" class="aligncenter size-full wp-image-7092" srcset="https://blog.andreev.it/wp-content/uploads/2014/07/P044-14.png 406w, https://blog.andreev.it/wp-content/uploads/2014/07/P044-14-300x79.png 300w" sizes="(max-width: 406px) 100vw, 406px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2014/07/freebsd-10-openvpn-2-3-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu: OpenVPN 2.0.9 client on Ubuntu 9.04</title>
		<link>https://blog.andreev.it/2011/12/openvpn-2-0-9-client-on-ubuntu-9-04/</link>
					<comments>https://blog.andreev.it/2011/12/openvpn-2-0-9-client-on-ubuntu-9-04/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 19:25:02 +0000</pubDate>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=222</guid>

					<description><![CDATA[This is a method to install OpenVPN client on Ubuntu 9.04. First, download OpenVPN&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>This is a method to install OpenVPN client on Ubuntu 9.04. First, download OpenVPN client from <a href="http://openvpn.net/release/openvpn-2.0.9.tar.gz">http://openvpn.net/release/openvpn-2.0.9.tar.gz</a>. Unpack it, but do not install it yet. Then, download lzo-2.03 compression library from <a href="http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz">http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz</a>.</p>
<p>Before installing it, do:</p>
<pre class="brush: bash; title: ; notranslate">apt-get install libcurl4-openssl-dev </pre>
<p>Then unpack lzo-2.03, cd to that folder and do:</p>
<pre class="brush: bash; title: ; notranslate">./configure
sudo make
sudo make check
sudo make test
sudo make install </pre>
<p>Once you are done with lzo install, cd to openvpn folder and do the following.</p>
<pre class="brush: bash; title: ; notranslate">./configure
sudo make
sudo make install </pre>
<p>Now, put your config file under <strong>/etc/client.ovpn</strong> and your keys under your Documents folder. Make sure that you update client.ovpn so it reflects the new path. You can start the client using:</p>
<pre class="brush: bash; title: ; notranslate">/usr/local/sbin/openvpn --config /etc/client.ovpn</pre>
<p>Next, you can create a shortcut or “Launcher”. Make a small script <strong>/usr/local/bin/openvpn.sh</strong> and put the following lines.</p>
<pre class="brush: bash; title: ; notranslate">#!/bin/bash
sudo /usr/local/sbin/openvpn --config /etc/client.ovpn
</pre>
<p>Change the permissions with <strong>chmod +x</strong> or <strong>chmod 744</strong> if you want to have exclusive execute rights and then do:</p>
<pre class="brush: bash; title: ; notranslate">sudo updatedb </pre>
<p>Right-click anywhere on the desktop, choose <strong>“Create Launcher”</strong>, choose <strong>“Application in Terminal” </strong>and browse for the .sh script that you just made.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/openvpn-2-0-9-client-on-ubuntu-9-04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Cisco:  OpenVPN and Cisco router</title>
		<link>https://blog.andreev.it/2011/12/cisco-router-and-openvpn/</link>
					<comments>https://blog.andreev.it/2011/12/cisco-router-and-openvpn/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Mon, 05 Dec 2011 20:24:43 +0000</pubDate>
				<category><![CDATA[Cisco]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=167</guid>

					<description><![CDATA[Recently, I bought a Cisco 3620 router with two Ethernet interfaces. I could’ve easily&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Recently, I bought a Cisco 3620 router with two Ethernet interfaces. I could’ve easily used one laptop running Linux/*BSD with two NICs, but I was planning to study IOS. My plan was to connect another laptop (172.16.1.2) to my existing network. I also access my computers from outside using OpenVPN so I wanted to be able to access the new laptop with its internal IP. The image below briefly shows my wanted configuration.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2011/12/P007-01.gif"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2011/12/P007-01.gif" alt="" width="1008" height="284" class="aligncenter size-full wp-image-5910" /></a><br />
First, I installed the router. I connected one cable from <strong>Eth0/0</strong> to the Cisco switch where all computers have <strong>192.168.1.0/24</strong> IP range. The second cable went from <strong>Eth0/1</strong> interface on the router to another Netgear switch. I connected my laptop to this switch and assigned it a static IP of <strong>172.16.1.2.</strong> Next, I configured my Cisco router. This is a very simple configuration but it suits my needs.</p>
<pre class="brush: bash; title: ; notranslate">
router&gt; ena
router# conf t
router(config)# int Eth0/0
router(config-if)# ip address 192.168.1.11 255.255.255.0
router(config-if)# no shut
router(config-if)# int Eth0/1
router(config-if)# ip address 172.16.1.1 255.255.0.0
router(config-if)# no shut
router(config-if)# router igrp 1
router(config-rou)# network 192.168.1.0
router(config-rou)# network 172.16.0.0
router(config-rou)# CTRL-Z
</pre>
<p>After this, I was able to ping both <strong>192.168.1.1</strong> and <strong>172.16.1.2</strong> from the router. But, when I tried to ping <strong>172.16.1.1 (Cisco 3600 router)</strong> from <strong>192.168.1.1 (FreeBSD server)</strong>, I was getting no response.  That’s because, there is no route to <strong>172.16.1.1</strong>. In order to make this happen, I have to do this on the <strong>FreeBSD box (192.168.1.1):</strong></p>
<pre class="brush: bash; title: ; notranslate">
route add -net 172.16.0.0/16 192.168.1.11 
</pre>
<p>Which means, “If I have to reach <strong>172.16.0.0</strong> network, use <strong>192.168.1.11</strong> as a gateway, not the default one.” In order this change to be permanent, I added the following in <strong>/etc/rc.conf:</strong></p>
<pre class="brush: bash; title: ; notranslate">
# Static route to 172.16.0.0/16
static_routes=&quot;internal1&quot;
route_internal1=&quot;-net 172.16.0.0/16 192.168.1.11&quot; 
</pre>
<p>You can check your route with <strong>“netstat -rn”</strong> on FreeBSD and Mac OS X and with <strong>“route print”</strong> on Windows.</p>
<p>Because I made this change on <strong>192.168.1.1</strong> which is a default router for all my computers on <strong>192.168.1.0/24</strong> subnet, I don’t have to go to each one of them and change the router settings. So, when I do <strong>ping 172.16.1.2</strong> on a computer with <strong>192.168.1.3</strong> IP and <strong>192.168.1.1</strong> as a gateway, the gateway (FreeBSD box) simply forwards these packets to <strong>192.168.1.11 (Cisco 3600 router)</strong>.<br />
I went back to <strong>172.16.1.2</strong> computer and I confirmed that I can ping <strong>192.168.1.1</strong>. There is no need to change routes on this network, because they use <strong>172.16.1.1</strong> as a gateway which knows how to route to <strong>192.168.1.0/24</strong>. Mind that <strong>192.168.1.0/24</strong> network is using two routes. One for the outside world <strong>(192.168.1.1)</strong> and one to access <strong>172.16.0.0/16</strong> network.<br />
Once I confirmed that I can route between two networks, I went back to Cisco router and added the following command:</p>
<pre class="brush: bash; title: ; notranslate">
router(config)# ip route 10.8.0.0 255.255.0.0 192.168.1.1 
</pre>
<p>which is very similar to <strong>route add -net</strong>. It means, use <strong>192.168.1.1</strong> as a gateway to reach <strong>10.8.0.0/16</strong> network.<br />
I also had to add the following line in <strong>openvpn.conf</strong> on the <strong>OpenVPN server (192.168.1.1):</strong></p>
<pre class="brush: bash; title: ; notranslate">
push &quot;route 192.168.1.0 255.255.255.0&quot;
# Line below was added 
push &quot;route 172.16.0.0 255.255.0.0&quot; 
</pre>
<p>Once this was done, I was able to access any device on my network.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/cisco-router-and-openvpn/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
