[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
howtos:network_services:openvpn [2013/05/19 18:30 (UTC)] – chrisabela | howtos:network_services:openvpn [2023/02/04 18:36 (UTC)] (current) – [13. Firewalls] chrisabela | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
====== OpenVPN - How to Set Up a Slackware Server and a Slackware Client ====== | ====== OpenVPN - How to Set Up a Slackware Server and a Slackware Client ====== | ||
Line 7: | Line 8: | ||
OpenVPN is an open source software application that implements virtual private network (VPN) techniques for creating secure point-to-point or site-to-site connections in routed or bridged configurations and remote access facilities. It uses a custom security protocol that utilizes SSL/TLS for key exchange. It is capable of traversing network address translators (NATs) and firewalls. It was written by James Yonan and is published under the GNU General Public License (GPL). | OpenVPN is an open source software application that implements virtual private network (VPN) techniques for creating secure point-to-point or site-to-site connections in routed or bridged configurations and remote access facilities. It uses a custom security protocol that utilizes SSL/TLS for key exchange. It is capable of traversing network address translators (NATs) and firewalls. It was written by James Yonan and is published under the GNU General Public License (GPL). | ||
- | OpenVPN allows peers to authenticate each other using a pre-shared secret key, certificates, | + | OpenVPN allows peers to authenticate each other using a pre-shared secret key, certificates, |
===== 2. Scope and Objective ===== | ===== 2. Scope and Objective ===== | ||
- | The objective of this how-to | + | The objective of this article |
- | The emphasis | + | The emphasis is to provide a reliable method that can be easily |
- | This document | + | This article |
===== 3. Installation ===== | ===== 3. Installation ===== | ||
- | Openvpn | + | OpenVPN |
- | If you want to confirm that Openvpn | + | If you want to confirm that OpenVPN |
< | < | ||
- | # ls /var/log/ | + | # ls /var/lib/ |
- | / | + | |
</ | </ | ||
===== 4. Requirements ===== | ===== 4. Requirements ===== | ||
- | A Server and a Client computers would be needed. They would have to be connected to the Internet on two different Routers and different Network Routes. | + | Server and a Client computers would be needed. They would have to be connected to the Internet on two different Routers and different Network Routes. |
==== 4.1. Server DNS ==== | ==== 4.1. Server DNS ==== | ||
- | A URL is normally used to address the Server. This is not mandatory and instead you may use only the Internet IP. However | + | A URL is normally used to address the Server. This is not mandatory and instead you may use only the Internet IP. However |
==== 4.2. Server details ==== | ==== 4.2. Server details ==== | ||
Line 40: | Line 40: | ||
< | < | ||
hostname: server1 | hostname: server1 | ||
- | IP: 192.168.200.199/ | + | IP: 192.168.200.195/ |
- | URL: servervpn.no-ip.org | + | URL: servervpn.duckdns.org |
Network Interface: eth0 | Network Interface: eth0 | ||
</ | </ | ||
Line 49: | Line 49: | ||
< | < | ||
hostname: client1 | hostname: client1 | ||
- | IP: 192.168.1.234/ | + | IP: 192.168.1.101/ |
Network Interface: wlan0 | Network Interface: wlan0 | ||
</ | </ | ||
- | ==== 4.3 Administrator Rights ==== | + | ==== 4.4 Administrator Rights ==== |
- | You will need to have administrator rights to set up the Openvpn. This applies to both the Server and the Client. | + | You will need to have administrator rights to set up OpenVPN. This applies to both the Server and the Client. |
- | ==== 4.4 Possible Constraints and Possible Solutions for a WiFi equipped Client ==== | + | ==== 4.5 Possible Constraints and Possible Solutions for a WiFi equipped Client ==== |
The availability of two Routers might be challenging. Consider that interactive sessions on both the Server and Client will be needed before the VPN is set up. If the Client is equipped with a WiFi interface there might be some easy solutions that may be considered: | The availability of two Routers might be challenging. Consider that interactive sessions on both the Server and Client will be needed before the VPN is set up. If the Client is equipped with a WiFi interface there might be some easy solutions that may be considered: | ||
- | - Use a 3G smart phone' | + | - Use the data smart phone' |
- | - Connect the Client to another WiFi available in the vicinity of the Server. Some lucky people live in areas were benevolent neighbours provide them with openly accessible Internet WiFi. It is recommended to request permission before taking up this solution. In case that no such open service exists, you may find it appropriate to request a temporary password from a friendly neighbour for the private encrypted WiFi service. | + | - Nowadays, many public |
- | - Nowadays, many governmental | + | |
===== 5. Creating a Public Key Infrastructure (PKI) using the easy-rsa Scripts ===== | ===== 5. Creating a Public Key Infrastructure (PKI) using the easy-rsa Scripts ===== | ||
- | The PKI may be created on any computer | + | The PKI may be created on any computer, but it is probably more sensible to be done on both the Server |
- | + | ||
- | The easy-rsa scripts referred | + | |
- | + | ||
- | It is not recommended | + | |
- | + | ||
- | Copy the whole easy-rsa | + | |
< | < | ||
- | # cp -r /usr/doc/ | + | # cd |
- | # cd /root/easy-rsa/2.0/ | + | # git clone http://github.com/OpenVPN/easy-rsa |
</ | </ | ||
- | Find the vars file. As a minimum | + | and then archive |
< | < | ||
- | KEY_COUNTRY | + | # tar czvf easy-rsa.tgz easy-rsa |
- | KEY_PROVINCE | + | |
- | KEY_ORG | + | |
- | KEY_EMAIL | + | |
</ | </ | ||
- | The purpose of this recommendation is to assure consistency in the default values of some following steps that need to be followed. You should not be really worried about the exact meaning or the correctness of the chosen entries as the actual values will have no bearing on the success or failure of this exercise. | + | ==== 5.1 Create |
- | The following is my complete vars file. You may note some additional entries that were entered. Most of these are meant to enhance the range of default values that will be immediately available, thus increasing the chances of a successful creation of the PKI. | + | Follow |
< | < | ||
- | # easy-rsa | + | # cd easy-rsa/easyrsa3 |
- | + | ||
- | # NOTE: If you installed from an RPM, | + | |
- | # don't edit this file in place in | + | |
- | # /usr/ | + | |
- | # instead, you should copy the whole | + | |
- | # easy-rsa directory to another location | + | |
- | # (such as / | + | |
- | # edits will not be wiped out by a future | + | |
- | # OpenVPN package upgrade. | + | |
- | + | ||
- | # This variable should point to | + | |
- | # the top level of the easy-rsa | + | |
- | # tree. | + | |
- | export EASY_RSA=" | + | |
- | + | ||
- | # | + | |
- | # This variable should point to | + | |
- | # the requested executables | + | |
- | # | + | |
- | export OPENSSL=" | + | |
- | export PKCS11TOOL=" | + | |
- | export GREP=" | + | |
- | + | ||
- | + | ||
- | # This variable should point to | + | |
- | # the openssl.cnf file included | + | |
- | # with easy-rsa. | + | |
- | export KEY_CONFIG=`$EASY_RSA/ | + | |
- | + | ||
- | # Edit this variable to point to | + | |
- | # your soon-to-be-created key | + | |
- | # directory. | + | |
- | # | + | |
- | # WARNING: clean-all will do | + | |
- | # a rm -rf on this directory | + | |
- | # so make sure you define | + | |
- | # it correctly! | + | |
- | export KEY_DIR=" | + | |
- | + | ||
- | # Issue rm -rf warning | + | |
- | echo NOTE: If you run ./ | + | |
- | + | ||
- | # PKCS11 fixes | + | |
- | export PKCS11_MODULE_PATH=" | + | |
- | export PKCS11_PIN=" | + | |
- | + | ||
- | # Increase this to 2048 if you | + | |
- | # are paranoid. | + | |
- | # down TLS negotiation performance | + | |
- | # as well as the one-time DH parms | + | |
- | # generation process. | + | |
- | export KEY_SIZE=2048 | + | |
- | + | ||
- | # In how many days should the root CA key expire? | + | |
- | export CA_EXPIRE=3650 | + | |
- | + | ||
- | # In how many days should certificates expire? | + | |
- | export KEY_EXPIRE=3650 | + | |
- | + | ||
- | # These are the default values for fields | + | |
- | # which will be placed in the certificate. | + | |
- | # Don't leave any of these fields blank. | + | |
- | export KEY_COUNTRY=" | + | |
- | export KEY_PROVINCE=" | + | |
- | export KEY_CITY=" | + | |
- | export KEY_ORG=" | + | |
- | #export KEY_EMAIL=" | + | |
- | export KEY_EMAIL=support@abcdef.com | + | |
- | export KEY_CN=server1 | + | |
- | export KEY_NAME=server1 | + | |
- | export KEY_OU="" | + | |
- | export PKCS11_MODULE_PATH=changeme | + | |
- | export PKCS11_PIN=1234 | + | |
</ | </ | ||
- | Source | + | Create |
< | < | ||
- | # source | + | # ./easyrsa init-pki |
- | NOTE: If you run ./clean-all, I will be doing a rm -rf on / | + | # ./easyrsa build-ca |
</ | </ | ||
- | Proceed like this: | + | Enter a PEM pass phrase, reverify it and then enter a name for the server. In this article I am using the hostnames for clarity (in this case: server1), but you may choose any name. |
+ | |||
+ | Then generate the request: | ||
< | < | ||
- | # ./clean-all | + | # ./easyrsa gen-req server1 |
- | # ./ | + | |
- | Generating a 2048 bit RSA private key | + | |
- | .....................+++ | + | |
- | .......................................................................+++ | + | |
- | writing new private key to ' | + | |
- | ----- | + | |
- | 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 ' | + | |
- | ----- | + | |
- | Country Name (2 letter code) [MT]: | + | |
- | State or Province Name (full name) [Malta]: | + | |
- | Locality Name (eg, city) [Valletta]: | + | |
- | Organization Name (eg, company) [ABCDEF Co. Ltd.]: | + | |
- | Organizational Unit Name (eg, section) []: | + | |
- | Common Name (eg, your name or your server' | + | |
- | Name [server1]: | + | |
- | Email Address [support@abcdef.com]: | + | |
</ | </ | ||
- | **Hint: The less information you enter, | + | You will be prompted for the PEM pass phrase, to reverify |
< | < | ||
- | # ./build-key-server server1 | + | # ./easyrsa sign-req server server1 |
</ | </ | ||
- | **Do not enter a challenge password or company name when prompted.** | + | Confirm the request by entering " |
+ | |||
+ | Now create two additional key files: | ||
< | < | ||
- | Generating a 2048 bit RSA private key | + | # cd / |
- | ........................+++ | + | # openssl dhparam -out dh2048.pem 2048 |
- | ................................................+++ | + | # cd / |
- | writing new private key to ' | + | # / |
- | ----- | + | </code> |
- | 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 ' | + | |
- | ----- | + | |
- | Country Name (2 letter | + | |
- | State or Province Name (full name) [Malta]: | + | |
- | Locality Name (eg, city) [Valletta]: | + | |
- | Organization Name (eg, company) [ABCDEF Co. Ltd.]: | + | |
- | Organizational Unit Name (eg, section) []: | + | |
- | Common Name (eg, your name or your server' | + | |
- | Name [server1]: | + | |
- | Email Address [support@abcdef.com]: | + | |
- | Please enter the following ' | + | ==== 5.2 Create |
- | to be sent with your certificate request | + | |
- | A challenge password []: | + | |
- | An optional company name []: | + | |
- | Using configuration from / | + | |
- | Check that the request matches the signature | + | |
- | Signature ok | + | |
- | The Subject' | + | |
- | countryName | + | |
- | stateOrProvinceName | + | |
- | localityName | + | |
- | organizationName | + | |
- | commonName | + | |
- | name : | + | |
- | emailAddress | + | |
- | Certificate is to be certified until Jan 18 19:37:43 2023 GMT (3650 days) | + | |
- | Sign the certificate? | + | |
+ | Follow these steps on the Client to create the needed keys and certificates: | ||
- | 1 out of 1 certificate requests certified, commit? [y/n]y | + | You will need the '' |
- | Write out database with 1 new entries | + | |
- | Data Base Updated | + | |
- | </ | + | |
< | < | ||
- | # ./build-dh | + | # cd |
- | This is going to take a long time | + | # tar xvf easy-rsa.tgz |
- | ..................+........................................................................................................... | + | |
- | ................................................................. | + | |
</ | </ | ||
+ | |||
+ | Now create the PKI and generate the request: | ||
< | < | ||
- | # ./build-key client1 | + | # cd easy-rsa/ |
+ | # ./easyrsa init-pki | ||
+ | # ./easyrsa gen-req client1 | ||
</ | </ | ||
- | ** Do not enter a challenge password or company | + | You will be prompted for a PEM pass phrase, to re-verify it and to confirm that the name of the entity is indeed client1. In this article I am using the hostnames for clarity (in this case: client1), but you may choose any name. |
- | < | + | Copy '' |
- | Generating a 2048 bit RSA private key | + | |
- | ...............................................................................................+++ | + | |
- | ..+++ | + | |
- | writing new private key to ' | + | |
- | ----- | + | |
- | 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 ' | + | |
- | ----- | + | |
- | Country Name (2 letter code) [MT]: | + | |
- | State or Province Name (full name) [Malta]: | + | |
- | Locality Name (eg, city) [Valletta]: | + | |
- | Organization Name (eg, company) [ABCDEF Co. Ltd.]: | + | |
- | Organizational Unit Name (eg, section) []: | + | |
- | Common Name (eg, your name or your server' | + | |
- | Name [server1]: | + | |
- | Email Address [support@abcdef.com]: | + | |
- | Please enter the following ' | + | === 5.2.1 Sign the Client' |
- | to be sent with your certificate request | + | |
- | A challenge password []: | + | |
- | An optional company name []: | + | |
- | Using configuration from / | + | |
- | Check that the request matches the signature | + | |
- | Signature ok | + | |
- | The Subject' | + | |
- | countryName | + | |
- | stateOrProvinceName | + | |
- | localityName | + | |
- | organizationName | + | |
- | commonName | + | |
- | name : | + | |
- | emailAddress | + | |
- | Certificate is to be certified until Jan 18 19:42:33 2023 GMT (3650 days) | + | |
- | Sign the certificate? | + | |
- | + | For the purpose | |
- | 1 out of 1 certificate requests certified, commit? [y/n]y | + | |
- | Write out database with 1 new entries | + | |
- | Data Base Updated | + | |
- | </code> | + | |
< | < | ||
- | # openvpn --genkey --secret /root/easy-rsa/2.0/keys/ta.key | + | # cd $HOME/easy-rsa/easyrsa3 |
+ | # ./easyrsa import-req $HOME/openvpn/ | ||
+ | # ./easyrsa sign-req client client1 | ||
</ | </ | ||
+ | |||
+ | When prompted enter " | ||
+ | |||
+ | Copy the generated '' | ||
+ | back to the client. | ||
===== 6. Setting up the Server ===== | ===== 6. Setting up the Server ===== | ||
- | Copy the following files generated by the easy-rsa scripts to their respective directories in the / | + | Copy the following files generated by the easy-rsa scripts to their respective directories in the '' |
< | < | ||
- | # cp /root/easy-rsa/2.0/keys/{ca.crt, | + | # cp $HOME/easy-rsa/easyrsa3/pki/ca.crt \ |
> / | > / | ||
- | # cp /root/easy-rsa/2.0/keys/{server1.key,ta.key} \ | + | # cp $HOME/easy-rsa/easyrsa3/pki/issued/server1.crt \ |
+ | > / | ||
+ | # cp $HOME/ | ||
> / | > / | ||
</ | </ | ||
- | Restrict | + | Copy the provided '' |
< | < | ||
- | # chmod 700 / | + | # cp / |
</ | </ | ||
- | On the Server machine copy the sample server.conf onto the openvpn' | + | Edit the following lines of '' |
- | + | ||
- | < | + | |
- | # cp / | + | |
- | > / | + | |
- | </ | + | |
- | + | ||
- | Edit the following lines of / | + | |
From these lines: | From these lines: | ||
Line 353: | Line 184: | ||
cert server.crt | cert server.crt | ||
key server.key | key server.key | ||
- | |||
dh dh1024.pem | dh dh1024.pem | ||
- | ;tls-auth ta.key 0 # This file is secret | ||
- | ;user nobody | + | ;topology subnet |
- | ;group nobody | + | |
+ | tls-auth ta.key 0 # This file is secret | ||
+ | |||
+ | cipher AES-256-CBC | ||
+ | |||
+ | ;log-append | ||
</ | </ | ||
- | To | + | To: |
< | < | ||
Line 370: | Line 205: | ||
dh / | dh / | ||
+ | |||
+ | topology subnet | ||
tls-auth / | tls-auth / | ||
- | user nobody | + | data-ciphers-fallback AES-256-CBC |
- | group nobody | + | |
+ | log-append | ||
</ | </ | ||
- | **Note** that comments in server.conf may be either start with # or ; In order to help you with entering parameters, the former are used to comment out text while the latter are for commented out configuration lines. | + | < |
- | Copy the rc.openvpn-server listed hereunder and place under /etc/rc.d/ | + | Create a file containing your PEM pass phrase in a secure location; e.g. '' |
< | < | ||
- | #!/bin/sh | + | # chmod 600 /root/password.ovpn |
- | # | + | </code> |
- | # /etc/rc.d/ | + | |
- | # | + | |
- | # Start/stop/ | + | |
- | # | + | |
- | # To make OpenVPN start automatically at boot, make this | + | |
- | # file executable: | + | |
- | # | + | |
- | ovpn_start() { | + | On the Server, edit '' |
- | if [ -x / | + | |
- | echo " | + | |
- | / | + | |
- | fi | + | |
- | } | + | |
- | ovpn_stop() { | + | < |
- | | + | askpass / |
- | } | + | auth-nocache |
+ | </ | ||
- | ovpn_restart() { | + | Create a directory to store the OpenVPN service PID and restrict its permissions: |
- | ovpn_stop | + | |
- | sleep 2 | + | |
- | ovpn_start | + | |
- | } | + | |
- | case " | + | < |
- | ' | + | mkdir / |
- | | + | chmod 700 / |
- | ;; | + | |
- | ' | + | |
- | ovpn_stop | + | |
- | ;; | + | |
- | ' | + | |
- | ovpn_restart | + | |
- | ;; | + | |
- | *) | + | |
- | echo " | + | |
- | esac | + | |
</ | </ | ||
- | Then give it executable permissions: | + | Give the OpenVPN '' |
< | < | ||
- | # chmod 755 / | + | # chmod +x / |
</ | </ | ||
===== 7. Port Forwarding ===== | ===== 7. Port Forwarding ===== | ||
- | You will need to forward traffic from the port you have chosen for Openvpn | + | You will need to forward traffic from the port you have chosen for OpenVPN |
- | In case if you have misplaced such documentation, | + | In case if you have misplaced such documentation, |
===== 8. Setting up the Client ===== | ===== 8. Setting up the Client ===== | ||
- | On the client | + | On the Client |
+ | |||
+ | Copy the provided '' | ||
< | < | ||
- | # cp /usr/doc/openvpn-2.2.2/ | + | # cp /etc/ |
- | > / | + | |
</ | </ | ||
Line 457: | Line 271: | ||
key client.key | key client.key | ||
- | ;tls-auth ta.key 1 | + | tls-auth ta.key 1 |
+ | |||
+ | cipher AES-256-CBC | ||
</ | </ | ||
Line 463: | Line 279: | ||
< | < | ||
- | remote servervpn.no-ip.org 1194 | + | remote servervpn.duckdns.org 1194 |
user nobody | user nobody | ||
Line 473: | Line 289: | ||
tls-auth / | tls-auth / | ||
- | </ | ||
- | **Note** that comments in client.conf may be either # or ; The former are used to comment out text while the latter are for commented out configuration lines. This should help you a lot in the configuration process. | + | data-ciphers-fallback AES-256-CBC |
- | You will need the following files that were generated by the easy-rsa scripts: | + | auth-nocache |
- | < | + | log-append |
- | ca.crt | + | |
- | client1.crt | + | |
- | client1.key | + | |
- | ta.key | + | |
</ | </ | ||
- | Place these files as indicated | + | < |
- | Copy the following rc.openvpn-client listed hereunder and place under /etc/rc.d/ | + | You will need this file that was generated by the Client' |
< | < | ||
- | #!/bin/sh | + | cp $HOME/easy-rsa/easyrsa3/pki/private/client1.key \ |
- | # | + | > /etc/openvpn/keys/ |
- | # /etc/rc.d/rc.openvpn-client | + | </ |
- | # | + | |
- | # Start/stop/restart the openvpn | + | |
- | # | + | |
- | ovpn_start() { | + | and the following from the Server' |
- | if [ -x / | + | |
- | echo " | + | |
- | / | + | |
- | fi | + | |
- | } | + | |
- | ovpn_stop() { | + | < |
- | | + | $HOME/ |
- | } | + | $HOME/ |
- | + | ||
- | ovpn_restart() { | + | |
- | ovpn_stop | + | |
- | sleep 2 | + | |
- | ovpn_start | + | |
- | } | + | |
- | + | ||
- | case "$1" in | + | |
- | ' | + | |
- | ovpn_start | + | |
- | ;; | + | |
- | ' | + | |
- | ovpn_stop | + | |
- | ;; | + | |
- | ' | + | |
- | ovpn_restart | + | |
- | ;; | + | |
- | *) | + | |
- | echo " | + | |
- | esac | + | |
</ | </ | ||
- | Then give it executable permissions: | + | and this file from the Server as well: |
< | < | ||
- | # chmod +x /etc/rc.d/rc.openvpn-client | + | /etc/openvpn/keys/ta.key |
</ | </ | ||
+ | |||
+ | Place these files as indicated in '' | ||
===== 9. Testing the VPN ===== | ===== 9. Testing the VPN ===== | ||
Line 541: | Line 326: | ||
< | < | ||
- | # / | + | # / |
</ | </ | ||
+ | |||
+ | Enter the Server PEM pass phrase when prompted. | ||
On the Client: | On the Client: | ||
< | < | ||
- | # /etc/rc.d/rc.openvpn-client | + | # /usr/sbin/openvpn --config / |
</ | </ | ||
- | On both you should see a new network interface called tun0. On the Server, I obtained the following: | + | Enter the Client PEM pass phrase when prompted. To stop OpenVPN on the Client just hit CTRL+C |
- | + | ||
- | < | + | |
- | # ifconfig tun0 | + | |
- | tun0: flags=4305< | + | |
- | inet 10.8.0.1 | + | |
- | unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 | + | |
- | RX packets 0 bytes 0 (0.0 B) | + | |
- | RX errors 0 dropped 0 overruns 0 frame 0 | + | |
- | TX packets 0 bytes 0 (0.0 B) | + | |
- | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | + | |
- | </ | + | |
- | Similarly on the Client: | + | On both you should see a new network interface called tun0. To verify, run this ip command: |
< | < | ||
- | # ifconfig | + | # / |
- | tun0: flags=4305< | + | |
- | inet 10.8.0.6 | + | |
- | unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 | + | |
- | RX packets 0 bytes 0 (0.0 B) | + | |
- | RX errors 0 dropped 0 overruns 0 frame 0 | + | |
- | TX packets 0 bytes 0 (0.0 B) | + | |
- | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | + | |
</ | </ | ||
Line 592: | Line 361: | ||
</ | </ | ||
- | To start the openvpn service automatically on boot-up from the Server, include these lines in /etc/rc.d/rc.local | + | If you fail to set-up a VPN connection, you may want to look in '' |
< | < | ||
- | if [ -x /etc/rc.d/rc.openvpn-server ]; then | + | tal -f /var/log/openvpn.log |
- | /etc/rc.d/ | + | |
- | fi | + | |
</ | </ | ||
- | ===== 10. IP Routing ===== | + | ===== 10. Logrotate (6) ===== |
+ | |||
+ | This is logrotate configuration for OpenVPN. It prevents you from ending up with huge OpenVPN log files. '' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | daily | ||
+ | rotate 12 | ||
+ | compress | ||
+ | copytruncate | ||
+ | delaycompress | ||
+ | missingok | ||
+ | notifempty | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== 11. Storing the PEM pass phrase in a secure file and automatic start of service after booting ===== | ||
+ | |||
+ | As hinted in Chapter 6, to start the OpenVPN service on boot, an entry in ''/ | ||
+ | |||
+ | As ''/ | ||
+ | |||
+ | On the Client, edit ''/ | ||
+ | |||
+ | < | ||
+ | askpass / | ||
+ | auth-nocache | ||
+ | </ | ||
+ | |||
+ | Create a directory to store the OpenVPN service PID and restrict its permissions: | ||
+ | |||
+ | < | ||
+ | mkdir / | ||
+ | chmod 700 / | ||
+ | </ | ||
+ | |||
+ | An alternate method (albeit less secure) is to remove the passphrase from '' | ||
+ | |||
+ | < | ||
+ | # cd / | ||
+ | # openssl rsa -in server1.key -out tmp.key | ||
+ | </ | ||
+ | |||
+ | Enter the pass phrase. | ||
+ | |||
+ | < | ||
+ | # mv tmp.key server1.key | ||
+ | # chmod 600 server1.key | ||
+ | </ | ||
+ | |||
+ | If you had them remove these lines from ''/ | ||
+ | |||
+ | < | ||
+ | askpass / | ||
+ | auth-nocache | ||
+ | </ | ||
+ | |||
+ | Similarly, this can be repeated for the Client: | ||
+ | |||
+ | < | ||
+ | # cd / | ||
+ | # openssl rsa -in client1.key -out tmp.key | ||
+ | </ | ||
+ | |||
+ | Enter the pass phrase. | ||
+ | |||
+ | < | ||
+ | # mv tmp.key client1.key | ||
+ | # chmod 600 client1.key | ||
+ | </ | ||
+ | |||
+ | Then, if you had it, remove this line from ''/ | ||
+ | |||
+ | < | ||
+ | askpass / | ||
+ | </ | ||
+ | |||
+ | If you intend to use the '' | ||
+ | |||
+ | < | ||
+ | mkdir / | ||
+ | chmod 700 / | ||
+ | chmod +x / | ||
+ | </ | ||
+ | |||
+ | ===== 12. IP Routing ===== | ||
Up to now we have created a tunnel device on both the Server and the Client called tun0 which is visible only to these two machines. However more work is needed to route the Client' | Up to now we have created a tunnel device on both the Server and the Client called tun0 which is visible only to these two machines. However more work is needed to route the Client' | ||
- | ==== 10.1 Server Configuration | + | ==== 12.1 IP Forwarding |
- | Enable | + | On the Server, enable |
< | < | ||
Line 621: | Line 473: | ||
</ | </ | ||
- | Create a file with the same name of the client (in this case client1) and enter the following line in / | + | Create a file with the same name of the client (in this case '' |
< | < | ||
Line 627: | Line 479: | ||
</ | </ | ||
- | Replace 192.168.1.0 255.255.255.0 by the Network Route of you Client. | + | Replace 192.168.1.0 255.255.255.0 by the Network Route of your Client. |
- | Similarly edit / | + | Similarly edit '' |
< | < | ||
push "route 192.168.200.0 255.255.255.0" | push "route 192.168.200.0 255.255.255.0" | ||
- | client-config-dir ccd | + | client-config-dir |
route 192.168.1.0 255.255.255.0 | route 192.168.1.0 255.255.255.0 | ||
Line 644: | Line 496: | ||
Naturally replace 192.168.200.0 255.255.255.0 with the Server' | Naturally replace 192.168.200.0 255.255.255.0 with the Server' | ||
+ | 208.67.222.222 and 208.67.220.220 are the OpenDNS IPv4 DNS service addresses. | ||
- | 208.67.222.222 and 208.67.220.220 are the OpenDNS IP addresses. | + | <note warning>Up to now the DNS push configuration has not been successful.</note> |
- | Next you will have to configure some iptables NAT forwarding on the Server (only). | + | You can either use the original Client DNS servers or else you may rewrite / |
< | < | ||
- | # iptables -F | + | # OpenDNS Servers |
+ | nameserver 208.67.222.222 | ||
+ | nameserver 208.67.220.220 | ||
+ | </ | ||
+ | |||
+ | According to your routing table however, it is still worth trying to use the DNS servers listed by the Client, I find that they are generally still available, so you would not need to do anything. However do be aware of possible DNS leaks if you are concerned about your privacy. | ||
+ | |||
+ | Some users have reported that their Client' | ||
+ | |||
+ | Next you will have to configure NAT forwarding on the Server (only). | ||
+ | |||
+ | You can do this by means of iptables or the newer nftables (not both). | ||
+ | |||
+ | ==== 12.2 NAT forwarding with iptables ==== | ||
+ | |||
+ | Start by flushing the '' | ||
+ | |||
+ | < | ||
+ | # /usr/sbin/iptables -F | ||
</ | </ | ||
Line 656: | Line 527: | ||
< | < | ||
- | # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE | + | # /usr/sbin/iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE |
</ | </ | ||
- | On Slackware, such a line may be included in / | + | On Slackware, such a line may be included in '' |
The exact lines which you need to include depend on whether you already entered your own iptables filter chains and rules, but I will assume that that this is not the case. | The exact lines which you need to include depend on whether you already entered your own iptables filter chains and rules, but I will assume that that this is not the case. | ||
- | As already explained, as a minimum you only need to enter the following lines in / | + | As already explained, as a minimum you only need to enter the following lines in '' |
< | < | ||
Line 670: | Line 541: | ||
</ | </ | ||
- | If on the other hand you would like a better | + | Give the firewall |
< | < | ||
- | #!/bin/sh | + | # chmod +x /etc/rc.d/rc.firewall |
- | # Start/stop/ | + | </code> |
- | # A VPN server iptable filter rules | + | |
- | + | ||
- | IPT=/ | + | |
- | firewall_start() { | + | and start it: |
- | # flush the iptables | + | < |
- | $IPT -F | + | # / |
- | + | </ | |
- | | + | |
- | $IPT -P OUTPUT ACCEPT | + | |
- | $IPT -P INPUT DROP | + | |
- | $IPT -P FORWARD DROP | + | |
- | $IPT -N SERVICES # services is a custom chain | + | |
- | + | ||
- | # allowed inputs | + | |
- | #$IPT -A INPUT -i lo -j ACCEPT # Uncomment if the Server is a desktop | + | |
- | $IPT -A INPUT -j SERVICES # Append the services chain to the input | + | |
- | # allowed forwards | + | Restart the OpenVPN service on the Server: |
- | $IPT -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED, | + | |
- | $IPT -A FORWARD -s 10.8.0.0/24 -o eth0 -j ACCEPT | + | |
- | | + | < |
- | $IPT -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -o eth0 -j MASQUERADE | + | # /etc/rc.d/rc.openvpn |
- | + | ||
- | # allow responses | + | |
- | $IPT -A INPUT -m state --state ESTABLISHED, | + | |
- | + | ||
- | # allow services | + | |
- | + | ||
- | # allow vpn on the default udp port 1194 | + | |
- | $IPT -A SERVICES -p udp --dport 1194 -j ACCEPT | + | |
- | + | ||
- | # allow sshd on the default tcp port 22 | + | |
- | $IPT -A SERVICES -p tcp --dport 22 -j ACCEPT | + | |
- | + | ||
- | } | + | |
- | + | ||
- | firewall_stop() { | + | |
- | + | ||
- | # polcies (permissive) | + | |
- | $IPT -P INPUT ACCEPT | + | |
- | + | ||
- | # flush the iptables | + | |
- | $IPT -F | + | |
- | + | ||
- | # delete the services custom chain | + | |
- | $IPT -X SERVICES | + | |
- | } | + | |
- | + | ||
- | case " | + | |
- | ' | + | |
- | firewall_start | + | |
- | ;; | + | |
- | ' | + | |
- | firewall_stop | + | |
- | ;; | + | |
- | 'restart') | + | |
- | firewall_stop | + | |
- | firewall_start | + | |
- | ;; | + | |
- | *) | + | |
- | echo "Usage $0 start|stop|restart" | + | |
- | esac | + | |
</ | </ | ||
- | Give the firewall rc script executable permission: | + | and reconnect from the Client: |
< | < | ||
- | # chmod +x /etc/rc.d/rc.firewall | + | # / |
</ | </ | ||
- | and start it: | + | ==== 12.3 NAT forwarding with nftables ==== |
+ | |||
+ | If you prefer '' | ||
< | < | ||
- | # /etc/rc.d/rc.firewall | + | /usr/sbin/nft flush ruleset |
+ | / | ||
+ | / | ||
+ | / | ||
</ | </ | ||
- | ===== 11. Firewalls ===== | + | ===== 13. Firewalls ===== |
- | + | ||
- | In the previous chapter we referred to a firewall you may include to protect your Openvpn Server. | + | |
- | In order to penetrate through the Client | + | You may find that on some networks, UDP port 1194 is blocked, and so the Client will be unable to connect. |
< | < | ||
Line 772: | Line 592: | ||
</ | </ | ||
- | and / | + | Also, comment out '' |
+ | |||
+ | You also have to modify your Router' | ||
+ | |||
+ | Edit '' | ||
< | < | ||
Line 788: | Line 612: | ||
</ | </ | ||
- | The Server' | + | ===== 14. Sources |
- | + | ||
- | < | + | |
- | # allow vpn on the default udp port 1194 | + | |
- | $IPT -A SERVICES -p udp --dport 1194 -j ACCEPT | + | |
- | </ | + | |
- | + | ||
- | to: | + | |
- | + | ||
- | < | + | |
- | # allow vpn on the custom tcp port 443 | + | |
- | $IPT -A SERVICES -p tcp --dport 443 -j ACCEPT | + | |
- | </ | + | |
- | + | ||
- | You also have to modify your Router' | + | |
- | + | ||
- | ===== 12. References | + | |
(1) http:// | (1) http:// | ||
Line 812: | Line 620: | ||
(3) http:// | (3) http:// | ||
- | (4) http://www.no-ip.com | + | (4) http://www.duckdns.org |
+ | (5) http:// | ||
+ | |||
+ | (6) https:// | ||
+ | |||
+ | * Written for Slackware 15.0 in April 2022 | ||
* Originally written by [[wiki: | * Originally written by [[wiki: | ||
<!-- Please do not modify anything below, except adding new tags.--> | <!-- Please do not modify anything below, except adding new tags.--> | ||
{{tag> | {{tag> | ||
- |