<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Crondrift</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Crondrift"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Crondrift"/>
	<updated>2026-04-30T18:17:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15804</id>
		<title>Setting up a OpenVPN server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15804"/>
		<updated>2019-03-17T16:32:19Z</updated>

		<summary type="html">&lt;p&gt;Crondrift: /* Install programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This article describes how to set up an OpenVPN server with the Alpine Linux.&lt;br /&gt;
This is an ideal solution for allowing single users or devices to remotely connect to your network. To establish connectivity with a Remote Office or site, [http://wiki.alpinelinux.org/w/index.php?title=Using_Racoon_for_Remote_Sites Racoon/Opennhrp] would provide better functionality. &lt;br /&gt;
&lt;br /&gt;
It is recommended that you have a publicly routable static IP address in order for this to work. This means that your IP address cannot be in the private IP address ranges described here: [http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses WikiPedia]&lt;br /&gt;
&lt;br /&gt;
If your Internet-connected machine doesn&#039;t have a static IP address, [http://www.dyndns.com DynDNS] can be used for resolving DNS names to IP addresses.&lt;br /&gt;
&lt;br /&gt;
= Setup Alpine =&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
Follow [[Installing_Alpine]] to setup Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Install openvpn&lt;br /&gt;
{{Cmd|apk add openvpn}}&lt;br /&gt;
&lt;br /&gt;
Prepare autostart of OpenVPN&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add openvpn default}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe tun&lt;br /&gt;
echo &amp;quot;tun&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
Enable IP Forwarding&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;echo &amp;quot;net.ipv4.ip_forward = 1&amp;quot; &amp;gt;&amp;gt; /etc/sysctl.conf&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|sysctl -p /etc/sysctl.conf}}&lt;br /&gt;
&lt;br /&gt;
= Certificates =&lt;br /&gt;
One of the first things that needs to be done is to make sure that you have secure keys to work with. Alpine makes this easy by having a web interface to manage the certificates. Documentation for it can be found here: [[Generating_SSL_certs_with_ACF]]. It is a best practice not to have your certificate server be on the same machine as the router being used for remote connectivity.&lt;br /&gt;
&lt;br /&gt;
You will need to create a server (ssl_server_cert) certificate for the server and one client (ssl_client_cert) for each client. To use the certificates, you should download the .pfx file and extract it.&lt;br /&gt;
&lt;br /&gt;
To extract the three parts of each .pfx file, use the following commands:&lt;br /&gt;
 &lt;br /&gt;
To get the ca cert out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -cacerts -nokeys -out ca.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the cert file out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nokeys -clcerts -out cert.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the private key file out. Make sure this stays private.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nocerts -nodes -out key.pem}}&lt;br /&gt;
&lt;br /&gt;
On the VPN server, you can also install the &#039;&#039;&#039;acf-openvpn&#039;&#039;&#039; package, which contains a web page to automatically upload and extract the server certificate. There is also a button to automatically generate the Diffie Hellman parameters.&lt;br /&gt;
&lt;br /&gt;
If you would prefer to generate your certificates using OpenVPN utilities, see [[#Alternative Certificate Method]]&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN server =&lt;br /&gt;
Example configuration file for server. Place the following content in /etc/openvpn/openvpn.conf:&lt;br /&gt;
 local &amp;quot;Public Ip address&amp;quot;&lt;br /&gt;
 port 1194&lt;br /&gt;
 proto udp&lt;br /&gt;
 dev tun&lt;br /&gt;
 ca /etc/openvpn/easy-rsa/keys/ca.crt &lt;br /&gt;
 cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME&lt;br /&gt;
 key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME&lt;br /&gt;
 dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!&lt;br /&gt;
 server 10.0.0.0 255.255.255.0&lt;br /&gt;
 ifconfig-pool-persist ipp.txt&lt;br /&gt;
 push &amp;quot;route 10.0.0.0 255.0.0.0&amp;quot;&lt;br /&gt;
 push &amp;quot;dhcp-option DNS 10.0.0.1&amp;quot;&lt;br /&gt;
 keepalive 10 120&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 user nobody&lt;br /&gt;
 group nobody&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 status /var/log/openvpn-status.log&lt;br /&gt;
 log-append  /var/log/openvpn.log&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#server openvpn.net/howto.html#server]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
== Test your configuration ==&lt;br /&gt;
Test configuration and certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openvpn --config /etc/openvpn/openvpn.conf}}&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN client =&lt;br /&gt;
Example client.conf:&lt;br /&gt;
 client&lt;br /&gt;
 dev tun&lt;br /&gt;
 proto udp&lt;br /&gt;
 remote &amp;quot;public IP&amp;quot; 1194&lt;br /&gt;
 resolv-retry infinite&lt;br /&gt;
 nobind&lt;br /&gt;
 ns-cert-type server # This means that the certificate on the openvpn server needs to have this field. Prevents MitM attacks&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 ca client-ca.pem&lt;br /&gt;
 cert client-cert.pem&lt;br /&gt;
 key client-key.pem&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#client openvpn.net/howto.html#client]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
Don&#039;t forget to save all your settings if you are running a RAM-based system.&lt;br /&gt;
{{Cmd|lbu commit}}&lt;br /&gt;
&lt;br /&gt;
= More than one server or client =&lt;br /&gt;
&lt;br /&gt;
If you want more than one server or client running on the same alpine box, use the standard [[Multiple Instances of Services]] process.&lt;br /&gt;
&lt;br /&gt;
For example, to create a config named &amp;quot;AlphaBravo&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
* Create an approriate /etc/openvpn/openvpn.conf file, but name it &amp;quot;/etc/openvpn/AlphaBravo.conf&amp;quot; &lt;br /&gt;
* create a new symlink of the init.d script:&lt;br /&gt;
{{Cmd|ln -s /etc/init.d/openvpn /etc/init.d/openvpn.AlphaBravo}}&lt;br /&gt;
* Have the new service start automatically&lt;br /&gt;
{{Cmd|rc-update add openvpn.AlphaBravo}}&lt;br /&gt;
&lt;br /&gt;
= Alternative Certificate Method =&lt;br /&gt;
== Manual Certificate Commands ==&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#pki openvpn.net/howto.html#pki]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
=== Initial setup for administrating certificates ===&lt;br /&gt;
The following instructions assume that you want to save your configs, certs and keys in &#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
Start by moving to the &#039;&#039;&#039;/usr/share/openvpn/easy-rsa&#039;&#039;&#039; folder to execute commands&lt;br /&gt;
{{Cmd|apk add easy-rsa # from the community repo&lt;br /&gt;
cd /usr/share/easy-rsa}}&lt;br /&gt;
If not already done then create a folder where you will save your certificates and save a copy of your &#039;&#039;&#039;/usr/share/easy-rsa/vars&#039;&#039;&#039; for later use.&amp;lt;BR&amp;gt;&lt;br /&gt;
{{Cmd|mkdir /etc/openvpn/keys&lt;br /&gt;
cp ./vars.example ./vars    #easy-rsa v3&lt;br /&gt;
cp ./vars /etc/openvpn/keys #easy-rsa v2}}&lt;br /&gt;
&lt;br /&gt;
For EasyRSA v3 see: https://community.openvpn.net/openvpn/wiki/EasyRSA&lt;br /&gt;
&lt;br /&gt;
The instructions below are for EasyRSA v2:&lt;br /&gt;
&lt;br /&gt;
If not already done then edit &#039;&#039;&#039;/etc/openvpn/keys/vars&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
(&#039;&#039;This file is used for defining paths and other standard settings&#039;&#039;)&lt;br /&gt;
{{Cmd|vim /etc/openvpn/keys/vars}}&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_DIR=&#039;&#039;&#039; from &amp;quot;&#039;&#039;&#039;$EASY_RSA/keys&#039;&#039;&#039;&amp;quot; to &amp;quot;&#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_SIZE, CA_EXPIRE, KEY_EXPIRE, KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL&#039;&#039;&#039; to match your system.&lt;br /&gt;
source the &#039;&#039;&#039;vars&#039;&#039;&#039; to set properties&lt;br /&gt;
{{Cmd|source /etc/openvpn/keys/vars}}&lt;br /&gt;
{{Cmd|touch /etc/openvpn/keys/index.txt&lt;br /&gt;
echo 00 &amp;gt; /etc/openvpn/keys/serial}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;Certificate Authority&#039; (CA) ===&lt;br /&gt;
Clean up the &#039;&#039;&#039;keys&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./clean-all}}&lt;br /&gt;
&lt;br /&gt;
Generate Diffie Hellman parameters&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-dh}}&lt;br /&gt;
&lt;br /&gt;
Now lets make the CA certificates and keys&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-ca}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Server&#039; ===&lt;br /&gt;
Create server certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-key-server &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Client&#039; ===&lt;br /&gt;
Create client certificates&lt;br /&gt;
{{Cmd|./build-key &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Revoke a certificate ===&lt;br /&gt;
To revoke a certificate&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./revoke-full &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The revoke-full script will generate a CRL (certificate revocation list) file called &#039;&#039;&#039;crl.pem&#039;&#039;&#039; in the &#039;&#039;&#039;keys&#039;&#039;&#039; subdirectory.&amp;lt;BR&amp;gt;The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|crl-verify crl.pem}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
&lt;br /&gt;
= OpenVPN and LXC =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s call this LXC &amp;quot;mylxc&amp;quot;...&lt;br /&gt;
&lt;br /&gt;
On the host &amp;lt;pre&amp;gt;&lt;br /&gt;
modprobe tun&lt;br /&gt;
mkdir /var/lib/lxc/mylxc/rootfs/dev/net&lt;br /&gt;
mknod /var/lib/lxc/mylxc/rootfs/dev/net/tun c 10 200&lt;br /&gt;
chmod 666 /var/lib/lxc/mylxc/rootfs/dev/net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In /var/lib/lxc/mylxc/config &amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the guest &amp;lt;pre&amp;gt;&lt;br /&gt;
apk add openvpn&lt;br /&gt;
&amp;lt;/pre&amp;gt; Then config as usual...&lt;br /&gt;
&lt;br /&gt;
This should work both as server and as client.&lt;br /&gt;
&lt;br /&gt;
== persistent devices ==&lt;br /&gt;
lxc guest have their dev recreated on each restart in a tmpfs. This means all devices are reset and are not read from rootfs dev directory. &lt;br /&gt;
To make it persistent you can use an autodev script by adding the following to your lxc guest config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# tun (openvpn)&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
# audodev script to add devices&lt;br /&gt;
lxc.hook.autodev=/var/lib/lxc/CONTAINER/autodev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The autodev script would be as following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# dev is populated on earch container start.&lt;br /&gt;
# to make devices persistence we need to recreate them on each start.&lt;br /&gt;
&lt;br /&gt;
cd ${LXC_ROOTFS_MOUNT}/dev&lt;br /&gt;
mkdir net&lt;br /&gt;
mknod net/tun c 10 200&lt;br /&gt;
chmod 0666 net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crondrift</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15803</id>
		<title>Setting up a OpenVPN server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15803"/>
		<updated>2019-03-17T14:16:01Z</updated>

		<summary type="html">&lt;p&gt;Crondrift: /* Install programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This article describes how to set up an OpenVPN server with the Alpine Linux.&lt;br /&gt;
This is an ideal solution for allowing single users or devices to remotely connect to your network. To establish connectivity with a Remote Office or site, [http://wiki.alpinelinux.org/w/index.php?title=Using_Racoon_for_Remote_Sites Racoon/Opennhrp] would provide better functionality. &lt;br /&gt;
&lt;br /&gt;
It is recommended that you have a publicly routable static IP address in order for this to work. This means that your IP address cannot be in the private IP address ranges described here: [http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses WikiPedia]&lt;br /&gt;
&lt;br /&gt;
If your Internet-connected machine doesn&#039;t have a static IP address, [http://www.dyndns.com DynDNS] can be used for resolving DNS names to IP addresses.&lt;br /&gt;
&lt;br /&gt;
= Setup Alpine =&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
Follow [[Installing_Alpine]] to setup Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Install openvpn&lt;br /&gt;
{{Cmd|apk add openvpn}}&lt;br /&gt;
&lt;br /&gt;
Prepare autostart of OpenVPN&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add openvpn default}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe tun&lt;br /&gt;
echo &amp;quot;tun&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
Enable IP Forwarding&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;echo &amp;quot;net.ipv4.ip_forward = 1&amp;quot;&amp;gt;&amp;gt; /etc/sysctl.conf&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{{Cmd|sysctl -p /etc/sysctl.conf}}&lt;br /&gt;
&lt;br /&gt;
= Certificates =&lt;br /&gt;
One of the first things that needs to be done is to make sure that you have secure keys to work with. Alpine makes this easy by having a web interface to manage the certificates. Documentation for it can be found here: [[Generating_SSL_certs_with_ACF]]. It is a best practice not to have your certificate server be on the same machine as the router being used for remote connectivity.&lt;br /&gt;
&lt;br /&gt;
You will need to create a server (ssl_server_cert) certificate for the server and one client (ssl_client_cert) for each client. To use the certificates, you should download the .pfx file and extract it.&lt;br /&gt;
&lt;br /&gt;
To extract the three parts of each .pfx file, use the following commands:&lt;br /&gt;
 &lt;br /&gt;
To get the ca cert out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -cacerts -nokeys -out ca.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the cert file out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nokeys -clcerts -out cert.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the private key file out. Make sure this stays private.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nocerts -nodes -out key.pem}}&lt;br /&gt;
&lt;br /&gt;
On the VPN server, you can also install the &#039;&#039;&#039;acf-openvpn&#039;&#039;&#039; package, which contains a web page to automatically upload and extract the server certificate. There is also a button to automatically generate the Diffie Hellman parameters.&lt;br /&gt;
&lt;br /&gt;
If you would prefer to generate your certificates using OpenVPN utilities, see [[#Alternative Certificate Method]]&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN server =&lt;br /&gt;
Example configuration file for server. Place the following content in /etc/openvpn/openvpn.conf:&lt;br /&gt;
 local &amp;quot;Public Ip address&amp;quot;&lt;br /&gt;
 port 1194&lt;br /&gt;
 proto udp&lt;br /&gt;
 dev tun&lt;br /&gt;
 ca /etc/openvpn/easy-rsa/keys/ca.crt &lt;br /&gt;
 cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME&lt;br /&gt;
 key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME&lt;br /&gt;
 dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!&lt;br /&gt;
 server 10.0.0.0 255.255.255.0&lt;br /&gt;
 ifconfig-pool-persist ipp.txt&lt;br /&gt;
 push &amp;quot;route 10.0.0.0 255.0.0.0&amp;quot;&lt;br /&gt;
 push &amp;quot;dhcp-option DNS 10.0.0.1&amp;quot;&lt;br /&gt;
 keepalive 10 120&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 user nobody&lt;br /&gt;
 group nobody&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 status /var/log/openvpn-status.log&lt;br /&gt;
 log-append  /var/log/openvpn.log&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#server openvpn.net/howto.html#server]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
== Test your configuration ==&lt;br /&gt;
Test configuration and certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openvpn --config /etc/openvpn/openvpn.conf}}&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN client =&lt;br /&gt;
Example client.conf:&lt;br /&gt;
 client&lt;br /&gt;
 dev tun&lt;br /&gt;
 proto udp&lt;br /&gt;
 remote &amp;quot;public IP&amp;quot; 1194&lt;br /&gt;
 resolv-retry infinite&lt;br /&gt;
 nobind&lt;br /&gt;
 ns-cert-type server # This means that the certificate on the openvpn server needs to have this field. Prevents MitM attacks&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 ca client-ca.pem&lt;br /&gt;
 cert client-cert.pem&lt;br /&gt;
 key client-key.pem&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#client openvpn.net/howto.html#client]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
Don&#039;t forget to save all your settings if you are running a RAM-based system.&lt;br /&gt;
{{Cmd|lbu commit}}&lt;br /&gt;
&lt;br /&gt;
= More than one server or client =&lt;br /&gt;
&lt;br /&gt;
If you want more than one server or client running on the same alpine box, use the standard [[Multiple Instances of Services]] process.&lt;br /&gt;
&lt;br /&gt;
For example, to create a config named &amp;quot;AlphaBravo&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
* Create an approriate /etc/openvpn/openvpn.conf file, but name it &amp;quot;/etc/openvpn/AlphaBravo.conf&amp;quot; &lt;br /&gt;
* create a new symlink of the init.d script:&lt;br /&gt;
{{Cmd|ln -s /etc/init.d/openvpn /etc/init.d/openvpn.AlphaBravo}}&lt;br /&gt;
* Have the new service start automatically&lt;br /&gt;
{{Cmd|rc-update add openvpn.AlphaBravo}}&lt;br /&gt;
&lt;br /&gt;
= Alternative Certificate Method =&lt;br /&gt;
== Manual Certificate Commands ==&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#pki openvpn.net/howto.html#pki]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
=== Initial setup for administrating certificates ===&lt;br /&gt;
The following instructions assume that you want to save your configs, certs and keys in &#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
Start by moving to the &#039;&#039;&#039;/usr/share/openvpn/easy-rsa&#039;&#039;&#039; folder to execute commands&lt;br /&gt;
{{Cmd|apk add easy-rsa # from the community repo&lt;br /&gt;
cd /usr/share/easy-rsa}}&lt;br /&gt;
If not already done then create a folder where you will save your certificates and save a copy of your &#039;&#039;&#039;/usr/share/easy-rsa/vars&#039;&#039;&#039; for later use.&amp;lt;BR&amp;gt;&lt;br /&gt;
{{Cmd|mkdir /etc/openvpn/keys&lt;br /&gt;
cp ./vars.example ./vars    #easy-rsa v3&lt;br /&gt;
cp ./vars /etc/openvpn/keys #easy-rsa v2}}&lt;br /&gt;
&lt;br /&gt;
For EasyRSA v3 see: https://community.openvpn.net/openvpn/wiki/EasyRSA&lt;br /&gt;
&lt;br /&gt;
The instructions below are for EasyRSA v2:&lt;br /&gt;
&lt;br /&gt;
If not already done then edit &#039;&#039;&#039;/etc/openvpn/keys/vars&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
(&#039;&#039;This file is used for defining paths and other standard settings&#039;&#039;)&lt;br /&gt;
{{Cmd|vim /etc/openvpn/keys/vars}}&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_DIR=&#039;&#039;&#039; from &amp;quot;&#039;&#039;&#039;$EASY_RSA/keys&#039;&#039;&#039;&amp;quot; to &amp;quot;&#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_SIZE, CA_EXPIRE, KEY_EXPIRE, KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL&#039;&#039;&#039; to match your system.&lt;br /&gt;
source the &#039;&#039;&#039;vars&#039;&#039;&#039; to set properties&lt;br /&gt;
{{Cmd|source /etc/openvpn/keys/vars}}&lt;br /&gt;
{{Cmd|touch /etc/openvpn/keys/index.txt&lt;br /&gt;
echo 00 &amp;gt; /etc/openvpn/keys/serial}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;Certificate Authority&#039; (CA) ===&lt;br /&gt;
Clean up the &#039;&#039;&#039;keys&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./clean-all}}&lt;br /&gt;
&lt;br /&gt;
Generate Diffie Hellman parameters&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-dh}}&lt;br /&gt;
&lt;br /&gt;
Now lets make the CA certificates and keys&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-ca}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Server&#039; ===&lt;br /&gt;
Create server certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-key-server &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Client&#039; ===&lt;br /&gt;
Create client certificates&lt;br /&gt;
{{Cmd|./build-key &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Revoke a certificate ===&lt;br /&gt;
To revoke a certificate&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./revoke-full &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The revoke-full script will generate a CRL (certificate revocation list) file called &#039;&#039;&#039;crl.pem&#039;&#039;&#039; in the &#039;&#039;&#039;keys&#039;&#039;&#039; subdirectory.&amp;lt;BR&amp;gt;The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|crl-verify crl.pem}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
&lt;br /&gt;
= OpenVPN and LXC =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s call this LXC &amp;quot;mylxc&amp;quot;...&lt;br /&gt;
&lt;br /&gt;
On the host &amp;lt;pre&amp;gt;&lt;br /&gt;
modprobe tun&lt;br /&gt;
mkdir /var/lib/lxc/mylxc/rootfs/dev/net&lt;br /&gt;
mknod /var/lib/lxc/mylxc/rootfs/dev/net/tun c 10 200&lt;br /&gt;
chmod 666 /var/lib/lxc/mylxc/rootfs/dev/net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In /var/lib/lxc/mylxc/config &amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the guest &amp;lt;pre&amp;gt;&lt;br /&gt;
apk add openvpn&lt;br /&gt;
&amp;lt;/pre&amp;gt; Then config as usual...&lt;br /&gt;
&lt;br /&gt;
This should work both as server and as client.&lt;br /&gt;
&lt;br /&gt;
== persistent devices ==&lt;br /&gt;
lxc guest have their dev recreated on each restart in a tmpfs. This means all devices are reset and are not read from rootfs dev directory. &lt;br /&gt;
To make it persistent you can use an autodev script by adding the following to your lxc guest config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# tun (openvpn)&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
# audodev script to add devices&lt;br /&gt;
lxc.hook.autodev=/var/lib/lxc/CONTAINER/autodev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The autodev script would be as following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# dev is populated on earch container start.&lt;br /&gt;
# to make devices persistence we need to recreate them on each start.&lt;br /&gt;
&lt;br /&gt;
cd ${LXC_ROOTFS_MOUNT}/dev&lt;br /&gt;
mkdir net&lt;br /&gt;
mknod net/tun c 10 200&lt;br /&gt;
chmod 0666 net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crondrift</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15802</id>
		<title>Setting up a OpenVPN server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15802"/>
		<updated>2019-03-17T14:02:38Z</updated>

		<summary type="html">&lt;p&gt;Crondrift: /* Install programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This article describes how to set up an OpenVPN server with the Alpine Linux.&lt;br /&gt;
This is an ideal solution for allowing single users or devices to remotely connect to your network. To establish connectivity with a Remote Office or site, [http://wiki.alpinelinux.org/w/index.php?title=Using_Racoon_for_Remote_Sites Racoon/Opennhrp] would provide better functionality. &lt;br /&gt;
&lt;br /&gt;
It is recommended that you have a publicly routable static IP address in order for this to work. This means that your IP address cannot be in the private IP address ranges described here: [http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses WikiPedia]&lt;br /&gt;
&lt;br /&gt;
If your Internet-connected machine doesn&#039;t have a static IP address, [http://www.dyndns.com DynDNS] can be used for resolving DNS names to IP addresses.&lt;br /&gt;
&lt;br /&gt;
= Setup Alpine =&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
Follow [[Installing_Alpine]] to setup Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Install openvpn&lt;br /&gt;
{{Cmd|apk add openvpn}}&lt;br /&gt;
&lt;br /&gt;
Prepare autostart of OpenVPN&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add openvpn default}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe tun&lt;br /&gt;
echo &amp;quot;tun&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
Enable IP Forwarding&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;echo &amp;quot;net.ipv4.ip_forward = 1&amp;quot; &amp;gt;&amp;gt; /etc/sysctl.conf&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Certificates =&lt;br /&gt;
One of the first things that needs to be done is to make sure that you have secure keys to work with. Alpine makes this easy by having a web interface to manage the certificates. Documentation for it can be found here: [[Generating_SSL_certs_with_ACF]]. It is a best practice not to have your certificate server be on the same machine as the router being used for remote connectivity.&lt;br /&gt;
&lt;br /&gt;
You will need to create a server (ssl_server_cert) certificate for the server and one client (ssl_client_cert) for each client. To use the certificates, you should download the .pfx file and extract it.&lt;br /&gt;
&lt;br /&gt;
To extract the three parts of each .pfx file, use the following commands:&lt;br /&gt;
 &lt;br /&gt;
To get the ca cert out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -cacerts -nokeys -out ca.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the cert file out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nokeys -clcerts -out cert.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the private key file out. Make sure this stays private.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nocerts -nodes -out key.pem}}&lt;br /&gt;
&lt;br /&gt;
On the VPN server, you can also install the &#039;&#039;&#039;acf-openvpn&#039;&#039;&#039; package, which contains a web page to automatically upload and extract the server certificate. There is also a button to automatically generate the Diffie Hellman parameters.&lt;br /&gt;
&lt;br /&gt;
If you would prefer to generate your certificates using OpenVPN utilities, see [[#Alternative Certificate Method]]&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN server =&lt;br /&gt;
Example configuration file for server. Place the following content in /etc/openvpn/openvpn.conf:&lt;br /&gt;
 local &amp;quot;Public Ip address&amp;quot;&lt;br /&gt;
 port 1194&lt;br /&gt;
 proto udp&lt;br /&gt;
 dev tun&lt;br /&gt;
 ca /etc/openvpn/easy-rsa/keys/ca.crt &lt;br /&gt;
 cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME&lt;br /&gt;
 key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME&lt;br /&gt;
 dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!&lt;br /&gt;
 server 10.0.0.0 255.255.255.0&lt;br /&gt;
 ifconfig-pool-persist ipp.txt&lt;br /&gt;
 push &amp;quot;route 10.0.0.0 255.0.0.0&amp;quot;&lt;br /&gt;
 push &amp;quot;dhcp-option DNS 10.0.0.1&amp;quot;&lt;br /&gt;
 keepalive 10 120&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 user nobody&lt;br /&gt;
 group nobody&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 status /var/log/openvpn-status.log&lt;br /&gt;
 log-append  /var/log/openvpn.log&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#server openvpn.net/howto.html#server]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
== Test your configuration ==&lt;br /&gt;
Test configuration and certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openvpn --config /etc/openvpn/openvpn.conf}}&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN client =&lt;br /&gt;
Example client.conf:&lt;br /&gt;
 client&lt;br /&gt;
 dev tun&lt;br /&gt;
 proto udp&lt;br /&gt;
 remote &amp;quot;public IP&amp;quot; 1194&lt;br /&gt;
 resolv-retry infinite&lt;br /&gt;
 nobind&lt;br /&gt;
 ns-cert-type server # This means that the certificate on the openvpn server needs to have this field. Prevents MitM attacks&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 ca client-ca.pem&lt;br /&gt;
 cert client-cert.pem&lt;br /&gt;
 key client-key.pem&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#client openvpn.net/howto.html#client]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
Don&#039;t forget to save all your settings if you are running a RAM-based system.&lt;br /&gt;
{{Cmd|lbu commit}}&lt;br /&gt;
&lt;br /&gt;
= More than one server or client =&lt;br /&gt;
&lt;br /&gt;
If you want more than one server or client running on the same alpine box, use the standard [[Multiple Instances of Services]] process.&lt;br /&gt;
&lt;br /&gt;
For example, to create a config named &amp;quot;AlphaBravo&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
* Create an approriate /etc/openvpn/openvpn.conf file, but name it &amp;quot;/etc/openvpn/AlphaBravo.conf&amp;quot; &lt;br /&gt;
* create a new symlink of the init.d script:&lt;br /&gt;
{{Cmd|ln -s /etc/init.d/openvpn /etc/init.d/openvpn.AlphaBravo}}&lt;br /&gt;
* Have the new service start automatically&lt;br /&gt;
{{Cmd|rc-update add openvpn.AlphaBravo}}&lt;br /&gt;
&lt;br /&gt;
= Alternative Certificate Method =&lt;br /&gt;
== Manual Certificate Commands ==&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#pki openvpn.net/howto.html#pki]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
=== Initial setup for administrating certificates ===&lt;br /&gt;
The following instructions assume that you want to save your configs, certs and keys in &#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
Start by moving to the &#039;&#039;&#039;/usr/share/openvpn/easy-rsa&#039;&#039;&#039; folder to execute commands&lt;br /&gt;
{{Cmd|apk add easy-rsa # from the community repo&lt;br /&gt;
cd /usr/share/easy-rsa}}&lt;br /&gt;
If not already done then create a folder where you will save your certificates and save a copy of your &#039;&#039;&#039;/usr/share/easy-rsa/vars&#039;&#039;&#039; for later use.&amp;lt;BR&amp;gt;&lt;br /&gt;
{{Cmd|mkdir /etc/openvpn/keys&lt;br /&gt;
cp ./vars.example ./vars    #easy-rsa v3&lt;br /&gt;
cp ./vars /etc/openvpn/keys #easy-rsa v2}}&lt;br /&gt;
&lt;br /&gt;
For EasyRSA v3 see: https://community.openvpn.net/openvpn/wiki/EasyRSA&lt;br /&gt;
&lt;br /&gt;
The instructions below are for EasyRSA v2:&lt;br /&gt;
&lt;br /&gt;
If not already done then edit &#039;&#039;&#039;/etc/openvpn/keys/vars&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
(&#039;&#039;This file is used for defining paths and other standard settings&#039;&#039;)&lt;br /&gt;
{{Cmd|vim /etc/openvpn/keys/vars}}&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_DIR=&#039;&#039;&#039; from &amp;quot;&#039;&#039;&#039;$EASY_RSA/keys&#039;&#039;&#039;&amp;quot; to &amp;quot;&#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_SIZE, CA_EXPIRE, KEY_EXPIRE, KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL&#039;&#039;&#039; to match your system.&lt;br /&gt;
source the &#039;&#039;&#039;vars&#039;&#039;&#039; to set properties&lt;br /&gt;
{{Cmd|source /etc/openvpn/keys/vars}}&lt;br /&gt;
{{Cmd|touch /etc/openvpn/keys/index.txt&lt;br /&gt;
echo 00 &amp;gt; /etc/openvpn/keys/serial}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;Certificate Authority&#039; (CA) ===&lt;br /&gt;
Clean up the &#039;&#039;&#039;keys&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./clean-all}}&lt;br /&gt;
&lt;br /&gt;
Generate Diffie Hellman parameters&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-dh}}&lt;br /&gt;
&lt;br /&gt;
Now lets make the CA certificates and keys&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-ca}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Server&#039; ===&lt;br /&gt;
Create server certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-key-server &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Client&#039; ===&lt;br /&gt;
Create client certificates&lt;br /&gt;
{{Cmd|./build-key &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Revoke a certificate ===&lt;br /&gt;
To revoke a certificate&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./revoke-full &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The revoke-full script will generate a CRL (certificate revocation list) file called &#039;&#039;&#039;crl.pem&#039;&#039;&#039; in the &#039;&#039;&#039;keys&#039;&#039;&#039; subdirectory.&amp;lt;BR&amp;gt;The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|crl-verify crl.pem}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
&lt;br /&gt;
= OpenVPN and LXC =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s call this LXC &amp;quot;mylxc&amp;quot;...&lt;br /&gt;
&lt;br /&gt;
On the host &amp;lt;pre&amp;gt;&lt;br /&gt;
modprobe tun&lt;br /&gt;
mkdir /var/lib/lxc/mylxc/rootfs/dev/net&lt;br /&gt;
mknod /var/lib/lxc/mylxc/rootfs/dev/net/tun c 10 200&lt;br /&gt;
chmod 666 /var/lib/lxc/mylxc/rootfs/dev/net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In /var/lib/lxc/mylxc/config &amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the guest &amp;lt;pre&amp;gt;&lt;br /&gt;
apk add openvpn&lt;br /&gt;
&amp;lt;/pre&amp;gt; Then config as usual...&lt;br /&gt;
&lt;br /&gt;
This should work both as server and as client.&lt;br /&gt;
&lt;br /&gt;
== persistent devices ==&lt;br /&gt;
lxc guest have their dev recreated on each restart in a tmpfs. This means all devices are reset and are not read from rootfs dev directory. &lt;br /&gt;
To make it persistent you can use an autodev script by adding the following to your lxc guest config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# tun (openvpn)&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
# audodev script to add devices&lt;br /&gt;
lxc.hook.autodev=/var/lib/lxc/CONTAINER/autodev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The autodev script would be as following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# dev is populated on earch container start.&lt;br /&gt;
# to make devices persistence we need to recreate them on each start.&lt;br /&gt;
&lt;br /&gt;
cd ${LXC_ROOTFS_MOUNT}/dev&lt;br /&gt;
mkdir net&lt;br /&gt;
mknod net/tun c 10 200&lt;br /&gt;
chmod 0666 net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crondrift</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15801</id>
		<title>Setting up a OpenVPN server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15801"/>
		<updated>2019-03-17T13:57:50Z</updated>

		<summary type="html">&lt;p&gt;Crondrift: /* Install programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This article describes how to set up an OpenVPN server with the Alpine Linux.&lt;br /&gt;
This is an ideal solution for allowing single users or devices to remotely connect to your network. To establish connectivity with a Remote Office or site, [http://wiki.alpinelinux.org/w/index.php?title=Using_Racoon_for_Remote_Sites Racoon/Opennhrp] would provide better functionality. &lt;br /&gt;
&lt;br /&gt;
It is recommended that you have a publicly routable static IP address in order for this to work. This means that your IP address cannot be in the private IP address ranges described here: [http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses WikiPedia]&lt;br /&gt;
&lt;br /&gt;
If your Internet-connected machine doesn&#039;t have a static IP address, [http://www.dyndns.com DynDNS] can be used for resolving DNS names to IP addresses.&lt;br /&gt;
&lt;br /&gt;
= Setup Alpine =&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
Follow [[Installing_Alpine]] to setup Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Install openvpn&lt;br /&gt;
{{Cmd|apk add openvpn}}&lt;br /&gt;
&lt;br /&gt;
Prepare autostart of OpenVPN&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add openvpn default}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe tun&lt;br /&gt;
echo &amp;quot;tun&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
&lt;br /&gt;
Enable IP Forwarding&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;net.ipv4.ip_forward = 1&amp;quot; &amp;gt;&amp;gt; /etc/sysctl.conf&lt;br /&gt;
&lt;br /&gt;
= Certificates =&lt;br /&gt;
One of the first things that needs to be done is to make sure that you have secure keys to work with. Alpine makes this easy by having a web interface to manage the certificates. Documentation for it can be found here: [[Generating_SSL_certs_with_ACF]]. It is a best practice not to have your certificate server be on the same machine as the router being used for remote connectivity.&lt;br /&gt;
&lt;br /&gt;
You will need to create a server (ssl_server_cert) certificate for the server and one client (ssl_client_cert) for each client. To use the certificates, you should download the .pfx file and extract it.&lt;br /&gt;
&lt;br /&gt;
To extract the three parts of each .pfx file, use the following commands:&lt;br /&gt;
 &lt;br /&gt;
To get the ca cert out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -cacerts -nokeys -out ca.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the cert file out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nokeys -clcerts -out cert.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the private key file out. Make sure this stays private.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nocerts -nodes -out key.pem}}&lt;br /&gt;
&lt;br /&gt;
On the VPN server, you can also install the &#039;&#039;&#039;acf-openvpn&#039;&#039;&#039; package, which contains a web page to automatically upload and extract the server certificate. There is also a button to automatically generate the Diffie Hellman parameters.&lt;br /&gt;
&lt;br /&gt;
If you would prefer to generate your certificates using OpenVPN utilities, see [[#Alternative Certificate Method]]&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN server =&lt;br /&gt;
Example configuration file for server. Place the following content in /etc/openvpn/openvpn.conf:&lt;br /&gt;
 local &amp;quot;Public Ip address&amp;quot;&lt;br /&gt;
 port 1194&lt;br /&gt;
 proto udp&lt;br /&gt;
 dev tun&lt;br /&gt;
 ca /etc/openvpn/easy-rsa/keys/ca.crt &lt;br /&gt;
 cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME&lt;br /&gt;
 key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME&lt;br /&gt;
 dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!&lt;br /&gt;
 server 10.0.0.0 255.255.255.0&lt;br /&gt;
 ifconfig-pool-persist ipp.txt&lt;br /&gt;
 push &amp;quot;route 10.0.0.0 255.0.0.0&amp;quot;&lt;br /&gt;
 push &amp;quot;dhcp-option DNS 10.0.0.1&amp;quot;&lt;br /&gt;
 keepalive 10 120&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 user nobody&lt;br /&gt;
 group nobody&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 status /var/log/openvpn-status.log&lt;br /&gt;
 log-append  /var/log/openvpn.log&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#server openvpn.net/howto.html#server]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
== Test your configuration ==&lt;br /&gt;
Test configuration and certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openvpn --config /etc/openvpn/openvpn.conf}}&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN client =&lt;br /&gt;
Example client.conf:&lt;br /&gt;
 client&lt;br /&gt;
 dev tun&lt;br /&gt;
 proto udp&lt;br /&gt;
 remote &amp;quot;public IP&amp;quot; 1194&lt;br /&gt;
 resolv-retry infinite&lt;br /&gt;
 nobind&lt;br /&gt;
 ns-cert-type server # This means that the certificate on the openvpn server needs to have this field. Prevents MitM attacks&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 ca client-ca.pem&lt;br /&gt;
 cert client-cert.pem&lt;br /&gt;
 key client-key.pem&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#client openvpn.net/howto.html#client]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
Don&#039;t forget to save all your settings if you are running a RAM-based system.&lt;br /&gt;
{{Cmd|lbu commit}}&lt;br /&gt;
&lt;br /&gt;
= More than one server or client =&lt;br /&gt;
&lt;br /&gt;
If you want more than one server or client running on the same alpine box, use the standard [[Multiple Instances of Services]] process.&lt;br /&gt;
&lt;br /&gt;
For example, to create a config named &amp;quot;AlphaBravo&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
* Create an approriate /etc/openvpn/openvpn.conf file, but name it &amp;quot;/etc/openvpn/AlphaBravo.conf&amp;quot; &lt;br /&gt;
* create a new symlink of the init.d script:&lt;br /&gt;
{{Cmd|ln -s /etc/init.d/openvpn /etc/init.d/openvpn.AlphaBravo}}&lt;br /&gt;
* Have the new service start automatically&lt;br /&gt;
{{Cmd|rc-update add openvpn.AlphaBravo}}&lt;br /&gt;
&lt;br /&gt;
= Alternative Certificate Method =&lt;br /&gt;
== Manual Certificate Commands ==&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#pki openvpn.net/howto.html#pki]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
=== Initial setup for administrating certificates ===&lt;br /&gt;
The following instructions assume that you want to save your configs, certs and keys in &#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
Start by moving to the &#039;&#039;&#039;/usr/share/openvpn/easy-rsa&#039;&#039;&#039; folder to execute commands&lt;br /&gt;
{{Cmd|apk add easy-rsa # from the community repo&lt;br /&gt;
cd /usr/share/easy-rsa}}&lt;br /&gt;
If not already done then create a folder where you will save your certificates and save a copy of your &#039;&#039;&#039;/usr/share/easy-rsa/vars&#039;&#039;&#039; for later use.&amp;lt;BR&amp;gt;&lt;br /&gt;
{{Cmd|mkdir /etc/openvpn/keys&lt;br /&gt;
cp ./vars.example ./vars    #easy-rsa v3&lt;br /&gt;
cp ./vars /etc/openvpn/keys #easy-rsa v2}}&lt;br /&gt;
&lt;br /&gt;
For EasyRSA v3 see: https://community.openvpn.net/openvpn/wiki/EasyRSA&lt;br /&gt;
&lt;br /&gt;
The instructions below are for EasyRSA v2:&lt;br /&gt;
&lt;br /&gt;
If not already done then edit &#039;&#039;&#039;/etc/openvpn/keys/vars&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
(&#039;&#039;This file is used for defining paths and other standard settings&#039;&#039;)&lt;br /&gt;
{{Cmd|vim /etc/openvpn/keys/vars}}&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_DIR=&#039;&#039;&#039; from &amp;quot;&#039;&#039;&#039;$EASY_RSA/keys&#039;&#039;&#039;&amp;quot; to &amp;quot;&#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_SIZE, CA_EXPIRE, KEY_EXPIRE, KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL&#039;&#039;&#039; to match your system.&lt;br /&gt;
source the &#039;&#039;&#039;vars&#039;&#039;&#039; to set properties&lt;br /&gt;
{{Cmd|source /etc/openvpn/keys/vars}}&lt;br /&gt;
{{Cmd|touch /etc/openvpn/keys/index.txt&lt;br /&gt;
echo 00 &amp;gt; /etc/openvpn/keys/serial}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;Certificate Authority&#039; (CA) ===&lt;br /&gt;
Clean up the &#039;&#039;&#039;keys&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./clean-all}}&lt;br /&gt;
&lt;br /&gt;
Generate Diffie Hellman parameters&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-dh}}&lt;br /&gt;
&lt;br /&gt;
Now lets make the CA certificates and keys&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-ca}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Server&#039; ===&lt;br /&gt;
Create server certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-key-server &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Client&#039; ===&lt;br /&gt;
Create client certificates&lt;br /&gt;
{{Cmd|./build-key &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Revoke a certificate ===&lt;br /&gt;
To revoke a certificate&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./revoke-full &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The revoke-full script will generate a CRL (certificate revocation list) file called &#039;&#039;&#039;crl.pem&#039;&#039;&#039; in the &#039;&#039;&#039;keys&#039;&#039;&#039; subdirectory.&amp;lt;BR&amp;gt;The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|crl-verify crl.pem}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
&lt;br /&gt;
= OpenVPN and LXC =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s call this LXC &amp;quot;mylxc&amp;quot;...&lt;br /&gt;
&lt;br /&gt;
On the host &amp;lt;pre&amp;gt;&lt;br /&gt;
modprobe tun&lt;br /&gt;
mkdir /var/lib/lxc/mylxc/rootfs/dev/net&lt;br /&gt;
mknod /var/lib/lxc/mylxc/rootfs/dev/net/tun c 10 200&lt;br /&gt;
chmod 666 /var/lib/lxc/mylxc/rootfs/dev/net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In /var/lib/lxc/mylxc/config &amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the guest &amp;lt;pre&amp;gt;&lt;br /&gt;
apk add openvpn&lt;br /&gt;
&amp;lt;/pre&amp;gt; Then config as usual...&lt;br /&gt;
&lt;br /&gt;
This should work both as server and as client.&lt;br /&gt;
&lt;br /&gt;
== persistent devices ==&lt;br /&gt;
lxc guest have their dev recreated on each restart in a tmpfs. This means all devices are reset and are not read from rootfs dev directory. &lt;br /&gt;
To make it persistent you can use an autodev script by adding the following to your lxc guest config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# tun (openvpn)&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
# audodev script to add devices&lt;br /&gt;
lxc.hook.autodev=/var/lib/lxc/CONTAINER/autodev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The autodev script would be as following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# dev is populated on earch container start.&lt;br /&gt;
# to make devices persistence we need to recreate them on each start.&lt;br /&gt;
&lt;br /&gt;
cd ${LXC_ROOTFS_MOUNT}/dev&lt;br /&gt;
mkdir net&lt;br /&gt;
mknod net/tun c 10 200&lt;br /&gt;
chmod 0666 net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crondrift</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15800</id>
		<title>Setting up a OpenVPN server</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_OpenVPN_server&amp;diff=15800"/>
		<updated>2019-03-17T13:45:52Z</updated>

		<summary type="html">&lt;p&gt;Crondrift: /* Install programs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This article describes how to set up an OpenVPN server with the Alpine Linux.&lt;br /&gt;
This is an ideal solution for allowing single users or devices to remotely connect to your network. To establish connectivity with a Remote Office or site, [http://wiki.alpinelinux.org/w/index.php?title=Using_Racoon_for_Remote_Sites Racoon/Opennhrp] would provide better functionality. &lt;br /&gt;
&lt;br /&gt;
It is recommended that you have a publicly routable static IP address in order for this to work. This means that your IP address cannot be in the private IP address ranges described here: [http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses WikiPedia]&lt;br /&gt;
&lt;br /&gt;
If your Internet-connected machine doesn&#039;t have a static IP address, [http://www.dyndns.com DynDNS] can be used for resolving DNS names to IP addresses.&lt;br /&gt;
&lt;br /&gt;
= Setup Alpine =&lt;br /&gt;
== Initial Setup ==&lt;br /&gt;
Follow [[Installing_Alpine]] to setup Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
== Install programs ==&lt;br /&gt;
Install openvpn&lt;br /&gt;
{{Cmd| apk add openvpn}}&lt;br /&gt;
&lt;br /&gt;
Prepare autostart of OpenVPN&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-update add openvpn default}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe tun&lt;br /&gt;
echo &amp;quot;tun&amp;quot; &amp;gt;&amp;gt; /etc/modules}}&lt;br /&gt;
echo &amp;quot;net.ipv4.ip_forward = 1&amp;quot; &amp;gt;&amp;gt; /etc/sysctl.conf&lt;br /&gt;
&lt;br /&gt;
= Certificates =&lt;br /&gt;
One of the first things that needs to be done is to make sure that you have secure keys to work with. Alpine makes this easy by having a web interface to manage the certificates. Documentation for it can be found here: [[Generating_SSL_certs_with_ACF]]. It is a best practice not to have your certificate server be on the same machine as the router being used for remote connectivity.&lt;br /&gt;
&lt;br /&gt;
You will need to create a server (ssl_server_cert) certificate for the server and one client (ssl_client_cert) for each client. To use the certificates, you should download the .pfx file and extract it.&lt;br /&gt;
&lt;br /&gt;
To extract the three parts of each .pfx file, use the following commands:&lt;br /&gt;
 &lt;br /&gt;
To get the ca cert out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -cacerts -nokeys -out ca.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the cert file out...&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nokeys -clcerts -out cert.pem}}&lt;br /&gt;
&lt;br /&gt;
To get the private key file out. Make sure this stays private.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl pkcs12 -in PFXFILE -nocerts -nodes -out key.pem}}&lt;br /&gt;
&lt;br /&gt;
On the VPN server, you can also install the &#039;&#039;&#039;acf-openvpn&#039;&#039;&#039; package, which contains a web page to automatically upload and extract the server certificate. There is also a button to automatically generate the Diffie Hellman parameters.&lt;br /&gt;
&lt;br /&gt;
If you would prefer to generate your certificates using OpenVPN utilities, see [[#Alternative Certificate Method]]&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN server =&lt;br /&gt;
Example configuration file for server. Place the following content in /etc/openvpn/openvpn.conf:&lt;br /&gt;
 local &amp;quot;Public Ip address&amp;quot;&lt;br /&gt;
 port 1194&lt;br /&gt;
 proto udp&lt;br /&gt;
 dev tun&lt;br /&gt;
 ca /etc/openvpn/easy-rsa/keys/ca.crt &lt;br /&gt;
 cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME&lt;br /&gt;
 key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME&lt;br /&gt;
 dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!&lt;br /&gt;
 server 10.0.0.0 255.255.255.0&lt;br /&gt;
 ifconfig-pool-persist ipp.txt&lt;br /&gt;
 push &amp;quot;route 10.0.0.0 255.0.0.0&amp;quot;&lt;br /&gt;
 push &amp;quot;dhcp-option DNS 10.0.0.1&amp;quot;&lt;br /&gt;
 keepalive 10 120&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 user nobody&lt;br /&gt;
 group nobody&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 status /var/log/openvpn-status.log&lt;br /&gt;
 log-append  /var/log/openvpn.log&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#server openvpn.net/howto.html#server]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
== Test your configuration ==&lt;br /&gt;
Test configuration and certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openvpn --config /etc/openvpn/openvpn.conf}}&lt;br /&gt;
&lt;br /&gt;
= Configure OpenVPN client =&lt;br /&gt;
Example client.conf:&lt;br /&gt;
 client&lt;br /&gt;
 dev tun&lt;br /&gt;
 proto udp&lt;br /&gt;
 remote &amp;quot;public IP&amp;quot; 1194&lt;br /&gt;
 resolv-retry infinite&lt;br /&gt;
 nobind&lt;br /&gt;
 ns-cert-type server # This means that the certificate on the openvpn server needs to have this field. Prevents MitM attacks&lt;br /&gt;
 persist-key&lt;br /&gt;
 persist-tun&lt;br /&gt;
 ca client-ca.pem&lt;br /&gt;
 cert client-cert.pem&lt;br /&gt;
 key client-key.pem&lt;br /&gt;
 comp-lzo&lt;br /&gt;
 verb 3&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#client openvpn.net/howto.html#client]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
= Save settings =&lt;br /&gt;
Don&#039;t forget to save all your settings if you are running a RAM-based system.&lt;br /&gt;
{{Cmd|lbu commit}}&lt;br /&gt;
&lt;br /&gt;
= More than one server or client =&lt;br /&gt;
&lt;br /&gt;
If you want more than one server or client running on the same alpine box, use the standard [[Multiple Instances of Services]] process.&lt;br /&gt;
&lt;br /&gt;
For example, to create a config named &amp;quot;AlphaBravo&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
* Create an approriate /etc/openvpn/openvpn.conf file, but name it &amp;quot;/etc/openvpn/AlphaBravo.conf&amp;quot; &lt;br /&gt;
* create a new symlink of the init.d script:&lt;br /&gt;
{{Cmd|ln -s /etc/init.d/openvpn /etc/init.d/openvpn.AlphaBravo}}&lt;br /&gt;
* Have the new service start automatically&lt;br /&gt;
{{Cmd|rc-update add openvpn.AlphaBravo}}&lt;br /&gt;
&lt;br /&gt;
= Alternative Certificate Method =&lt;br /&gt;
== Manual Certificate Commands ==&lt;br /&gt;
(&#039;&#039;Instructions are based on [http://openvpn.net/howto.html#pki openvpn.net/howto.html#pki]&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
=== Initial setup for administrating certificates ===&lt;br /&gt;
The following instructions assume that you want to save your configs, certs and keys in &#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;.&amp;lt;BR&amp;gt;&lt;br /&gt;
Start by moving to the &#039;&#039;&#039;/usr/share/openvpn/easy-rsa&#039;&#039;&#039; folder to execute commands&lt;br /&gt;
{{Cmd|apk add easy-rsa # from the community repo&lt;br /&gt;
cd /usr/share/easy-rsa}}&lt;br /&gt;
If not already done then create a folder where you will save your certificates and save a copy of your &#039;&#039;&#039;/usr/share/easy-rsa/vars&#039;&#039;&#039; for later use.&amp;lt;BR&amp;gt;&lt;br /&gt;
{{Cmd|mkdir /etc/openvpn/keys&lt;br /&gt;
cp ./vars.example ./vars    #easy-rsa v3&lt;br /&gt;
cp ./vars /etc/openvpn/keys #easy-rsa v2}}&lt;br /&gt;
&lt;br /&gt;
For EasyRSA v3 see: https://community.openvpn.net/openvpn/wiki/EasyRSA&lt;br /&gt;
&lt;br /&gt;
The instructions below are for EasyRSA v2:&lt;br /&gt;
&lt;br /&gt;
If not already done then edit &#039;&#039;&#039;/etc/openvpn/keys/vars&#039;&#039;&#039;&amp;lt;BR&amp;gt;&lt;br /&gt;
(&#039;&#039;This file is used for defining paths and other standard settings&#039;&#039;)&lt;br /&gt;
{{Cmd|vim /etc/openvpn/keys/vars}}&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_DIR=&#039;&#039;&#039; from &amp;quot;&#039;&#039;&#039;$EASY_RSA/keys&#039;&#039;&#039;&amp;quot; to &amp;quot;&#039;&#039;&#039;/etc/openvpn/keys&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
* Change &#039;&#039;&#039;KEY_SIZE, CA_EXPIRE, KEY_EXPIRE, KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, KEY_EMAIL&#039;&#039;&#039; to match your system.&lt;br /&gt;
source the &#039;&#039;&#039;vars&#039;&#039;&#039; to set properties&lt;br /&gt;
{{Cmd|source /etc/openvpn/keys/vars}}&lt;br /&gt;
{{Cmd|touch /etc/openvpn/keys/index.txt&lt;br /&gt;
echo 00 &amp;gt; /etc/openvpn/keys/serial}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;Certificate Authority&#039; (CA) ===&lt;br /&gt;
Clean up the &#039;&#039;&#039;keys&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./clean-all}}&lt;br /&gt;
&lt;br /&gt;
Generate Diffie Hellman parameters&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-dh}}&lt;br /&gt;
&lt;br /&gt;
Now lets make the CA certificates and keys&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-ca}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Server&#039; ===&lt;br /&gt;
Create server certificates&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./build-key-server &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Set up a &#039;OpenVPN Client&#039; ===&lt;br /&gt;
Create client certificates&lt;br /&gt;
{{Cmd|./build-key &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Revoke a certificate ===&lt;br /&gt;
To revoke a certificate&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./revoke-full &amp;lt;commonname&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The revoke-full script will generate a CRL (certificate revocation list) file called &#039;&#039;&#039;crl.pem&#039;&#039;&#039; in the &#039;&#039;&#039;keys&#039;&#039;&#039; subdirectory.&amp;lt;BR&amp;gt;The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|crl-verify crl.pem}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
&lt;br /&gt;
= OpenVPN and LXC =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s call this LXC &amp;quot;mylxc&amp;quot;...&lt;br /&gt;
&lt;br /&gt;
On the host &amp;lt;pre&amp;gt;&lt;br /&gt;
modprobe tun&lt;br /&gt;
mkdir /var/lib/lxc/mylxc/rootfs/dev/net&lt;br /&gt;
mknod /var/lib/lxc/mylxc/rootfs/dev/net/tun c 10 200&lt;br /&gt;
chmod 666 /var/lib/lxc/mylxc/rootfs/dev/net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In /var/lib/lxc/mylxc/config &amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the guest &amp;lt;pre&amp;gt;&lt;br /&gt;
apk add openvpn&lt;br /&gt;
&amp;lt;/pre&amp;gt; Then config as usual...&lt;br /&gt;
&lt;br /&gt;
This should work both as server and as client.&lt;br /&gt;
&lt;br /&gt;
== persistent devices ==&lt;br /&gt;
lxc guest have their dev recreated on each restart in a tmpfs. This means all devices are reset and are not read from rootfs dev directory. &lt;br /&gt;
To make it persistent you can use an autodev script by adding the following to your lxc guest config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# tun (openvpn)&lt;br /&gt;
lxc.cgroup.devices.allow = c 10:200 rwm&lt;br /&gt;
# audodev script to add devices&lt;br /&gt;
lxc.hook.autodev=/var/lib/lxc/CONTAINER/autodev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The autodev script would be as following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# dev is populated on earch container start.&lt;br /&gt;
# to make devices persistence we need to recreate them on each start.&lt;br /&gt;
&lt;br /&gt;
cd ${LXC_ROOTFS_MOUNT}/dev&lt;br /&gt;
mkdir net&lt;br /&gt;
mknod net/tun c 10 200&lt;br /&gt;
chmod 0666 net/tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crondrift</name></author>
	</entry>
</feed>