[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.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
howtos:network_services:openvpn [2013/12/27 19:45 (UTC)] – Extensive update for openvpn-2.3.2 on Slackware 14.1 chrisabelahowtos:network_services:openvpn [2018/03/02 00:28 (UTC)] – Move passphrase removal to the passphrase section bifferos
Line 15: Line 15:
 The emphasis is to provide a reliable method that can be easily followed to set-up OpenVPN on Slackware Servers and Clients. Nevertheless the process is still not free from pitfalls and require some attention and determination. The emphasis is to provide a reliable method that can be easily followed to set-up OpenVPN on Slackware Servers and Clients. Nevertheless the process is still not free from pitfalls and require some attention and determination.
  
-This article comprises of a selection of other similar tutorials found on Internet particularly (2) and (3) and the documents contained in the downloaded source files. However these are reformatted to satisfy the objective. +This article comprises of a selection of other similar tutorials found on the Internet particularly (2) and (3) and the documents contained in the downloaded source files. However these are reformatted to satisfy the objective. 
  
 ===== 3. Installation ===== ===== 3. Installation =====
Line 54: Line 54:
 ==== 4.3 Administrator Rights ==== ==== 4.3 Administrator Rights ====
  
-You will need to have administrator rights to set up the Openvpn. This applies to both the Server and the Client. For simplicity, in this tutorial, it will be assumed that all actions will be performed by the root user. Naturally advanced users might be more discerning.+You will need to have administrator rights to set up OpenVPN. This applies to both the Server and the Client. For simplicity, in this tutorial, it will be assumed that all actions will be performed by the root user. Naturally advanced users might be more discerning.
  
 ==== 4.4 Possible Constraints and Possible Solutions for a WiFi equipped Client ==== ==== 4.4 Possible Constraints and Possible Solutions for a WiFi equipped Client ====
Line 70: Line 70:
 <code> <code>
 # cd # cd
-# git clone git://github.com/OpenVPN/easy-rsa+# git clone http://github.com/OpenVPN/easy-rsa
 </code> </code>
  
Line 144: Line 144:
 === 5.2.1 Sign the Client's request on the Server === === 5.2.1 Sign the Client's request on the Server ===
  
-For the purpose of this article, it is assumed that the Client's request file (client1.req) been transferred to the /root/openvpn/directory of the Server. Now you can proceed to import and sign the client1 request:+For the purpose of this article, it is assumed that the Client's request file (client1.req) has been transferred to the $HOME/openvpn/ directory of the Server. Now you can proceed to import and sign the client1 request:
  
 <code> <code>
-# cd /root/easy-rsa/easyrsa3 +# cd $HOME/easy-rsa/easyrsa3 
-# ./easyrsa import-req /root/openvpn/client1.req client1+# ./easyrsa import-req $HOME/openvpn/client1.req client1
 # ./easyrsa sign-req client client1 # ./easyrsa sign-req client client1
 </code> </code>
Line 154: Line 154:
 When prompted enter “yes” and the server1 CA PEM pass phrase.  When prompted enter “yes” and the server1 CA PEM pass phrase. 
  
-Copy the generated /root/easy-rsa/easyrsa3/pki/issued/client1.crt+Copy the generated $HOME/easy-rsa/easyrsa3/pki/issued/client1.crt
 back to the client. back to the client.
  
Line 162: Line 162:
  
 <code> <code>
-# cp /root/easy-rsa/easyrsa3/pki/ca.crt \+# cp $HOME/easy-rsa/easyrsa3/pki/ca.crt \
 > /etc/openvpn/certs/ > /etc/openvpn/certs/
-# cp /root/easy-rsa/easyrsa3/pki/issued/server1.crt \+# cp $HOME/easy-rsa/easyrsa3/pki/issued/server1.crt \
 > /etc/openvpn/certs/ > /etc/openvpn/certs/
-# cp /root/easy-rsa/easyrsa3/pki/private/server1.key \+# cp $HOME/easy-rsa/easyrsa3/pki/private/server1.key \
 > /etc/openvpn/keys/ > /etc/openvpn/keys/
 </code> </code>
  
-Copy the sample server.conf from the openvpn source onto the openvpn's configuration directory. The source of openvpn may be obtained from Slackware's source DVD or your favourite Slackware mirror or from http://openvpn.net. In the following example I am downloading the source from ftp.slackware.com+Copy the sample server.conf from the OpenVPN source onto the OpenVPN's configuration directory. The source of OpenVPN may be obtained from Slackware's source DVD or your favourite Slackware mirror or from http://openvpn.net. In the following example I am downloading the source from ftp.slackware.com
  
 <code> <code>
Line 180: Line 180:
 </code> </code>
  
-Copy the file server.conf contained in the source to the openvpn configuration directory:+Copy the file server.conf contained in the source to the OpenVPN configuration directory:
  
 <code> <code>
-# cp openvpn-2.3.2/sample/sample-config-files/server.conf \+# cp openvpn-*/sample/sample-config-files/server.conf \
 > /etc/openvpn/ > /etc/openvpn/
 </code> </code>
Line 230: Line 230:
 daemon daemon
 </code> </code>
 +
 +<note>It may be useful to leave off the 'daemon' option while getting things up and running so you can see useful messages in the foreground.</note>
  
 My full server.conf is the following: My full server.conf is the following:
Line 539: Line 541:
 </code> </code>
  
-<note>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. +<note>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.</note> 
-Copy the rc.openvpn listed hereunder and place under /etc/rc.d/</note>+ 
 +Copy the rc.openvpn listed hereunder and place under /etc/rc.d/
  
 <code> <code>
Line 547: Line 550:
 # /etc/rc.d/rc.openvpn  # /etc/rc.d/rc.openvpn 
  
-# Start/stop/restart the openvpn server. +# Start/stop/restart the OpenVPN server. 
 # #
    
Line 588: Line 591:
 </code> </code>
  
-Eventually when you start openvpn on the server, you may read /var/log/openvpn.log to verify that your work has been successful:+Eventually when you start OpenVPN on the server, you may read /var/log/openvpn.log to verify that your work has been successful:
  
 <code> <code>
Line 596: Line 599:
 ===== 7. Port Forwarding ===== ===== 7. Port Forwarding =====
  
-YYou will need to forward traffic from the port you have chosen for Openvpn to be routed to the Server. To accomplish this you will need to provide your Server with a fixed IP and you will need to configure your router. You may use netconfig, wicd or network-manager to set the fixed IP on Slackware. Then you also need to consult the documentation provided with your router to set up the selected IP address reserved for the Server, and the port forwarding. For our default Openvpn set up, the UDP Port would be 1194. +You will need to forward traffic from the port you have chosen for OpenVPN to be routed to the Server. To accomplish this you will need to provide your Server with a fixed IP and you will need to configure your router. You may use netconfig, wicd or network-manager to set the fixed IP on Slackware. Then you also need to consult the documentation provided with your router to set up the selected IP address reserved for the Server, and the port forwarding. For our default OpenVPN set up, the UDP Port would be 1194. 
  
 In case if you have misplaced such documentation, you may search on the Internet on how this may be achieved. A good place to start is http://portforward.com/. In case if you have misplaced such documentation, you may search on the Internet on how this may be achieved. A good place to start is http://portforward.com/.
Line 604: Line 607:
 On the Client machine perform the following instructions to set it up. On the Client machine perform the following instructions to set it up.
  
-Download the openvpn source tarball and extracted it as explained in Chapter 6, then proceed to copy the included configuration file for clients:+Download the OpenVPN source tarball and extracted it as explained in Chapter 6, then proceed to copy the included configuration file for clients:
  
 <code> <code>
Line 643: Line 646:
 <note>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.</note> <note>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.</note>
  
-You will need the this files that were generated by the Client's easy-rsa scripts:+You will need this file that were generated by the Client's easy-rsa scripts:
  
 <code> <code>
-/root/easy-rsa/easyrsa3/pki/private/client1.key+$HOME/easy-rsa/easyrsa3/pki/private/client1.key
 </code> </code>
  
Line 817: Line 820:
 </code> </code>
  
-Enter the Client PEM pass phrase when prompted. To stop openVPN on the Client just hit CTRL+C+Enter the Client PEM pass phrase when prompted. To stop OpenVPN on the Client just hit CTRL+C
  
 On both you should see a new network interface called tun0. On the Server, I obtained the following: On both you should see a new network interface called tun0. On the Server, I obtained the following:
Line 861: Line 864:
 </code> </code>
  
-To start the openvpn service automatically on boot-up from the Serverinclude these lines in /etc/rc.d/rc.local+===== 10. Storing the PEM pass phrase in a secure file and Automatic start of service after booting ===== 
 + 
 +To start the OpenVPN service on boot, an entry in /etc/rc.d/rc.local is needed, but you would have to enter the server PEM pass phrase every time. This might be undesirable if the Server is unreachable. If this is the case, create a file containing your PEM pass phrase in a secure location; e.g. /root/password.ovpn which contains only this pass phrase. Then restrict its permission:
  
 <code> <code>
-Start the OpenVPN Server +chmod 600 /root/password.ovpn 
-if [ -x /etc/rc.d/rc.openvpn-server ]; then  +</code> 
-  /etc/rc.d/rc.openvpn-server start + 
 +On the Server, edit /etc/openvpn/server.conf with the following lines: 
 + 
 +<code> 
 +askpass /root/password.ovpn 
 +auth-nocache 
 +</code> 
 + 
 +This may be repeated also on the Client, just edit /etc/openvpn/client.conf instead of /etc/openvpn/server.conf. 
 + 
 +To start the OpenVPN service automatically on boot-up from the Server, include these lines in /etc/rc.d/rc.local 
 + 
 +<code> 
 +# Start the OpenVPN Service 
 +if [ -x /etc/rc.d/rc.openvpn ]; then  
 +  /etc/rc.d/rc.openvpn start 
 fi fi
 </code> </code>
  
-===== 10. IP Routing =====+An alternate method (albeit less secure) is to remove the passphrase from server1.key file altogether.  Don't forget to set permissions on the key to avoid it being world-readable. 
 + 
 +<code> 
 +# cd /etc/openvpn/keys 
 +# openssl rsa -in server1.key -out tmp.key 
 +# mv tmp.key server1.key 
 +# chmod 600 server1.key 
 +</code> 
 + 
 + 
 +===== 11. 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's connection via tun0 and then to the WAN that is connected to the Server. 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's connection via tun0 and then to the WAN that is connected to the Server.
  
-==== 10.1 Server Configuration ====+==== 11.1 Server Configuration ====
  
 Enable IP forwarding: Enable IP forwarding:
Line 904: Line 934:
 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 /etc/openvpn/ccd 
 route 192.168.1.0 255.255.255.0  route 192.168.1.0 255.255.255.0 
  
Line 914: Line 944:
  
 Naturally replace 192.168.200.0 255.255.255.0 with the Server's Network Route, and  192.168.1.0 255.255.255.0 with the Client's Network Route. Naturally replace 192.168.200.0 255.255.255.0 with the Server's Network Route, and  192.168.1.0 255.255.255.0 with the Client's Network Route.
 +208.67.222.222 and 208.67.220.220 are the OpenDNS IP addresses.
  
-208.67.222.222 and 208.67.220.220 are the OpenDNS IP addresses. Up to now the DNS push configuration has not been successful. You can either use the original Client DNS servers or else you may edit /etc/resolv.conf manually. However it is still worth trying to use the DNS servers listed by the Client, I find that they are generally still be available from the Server's Network, so you would not need to do anything.+<note warning>Up to now the DNS push configuration has not been successful.</note> 
 + 
 +You can either use the original Client DNS servers or else you may rewrite /etc/resolv.conf manually
 + 
 +<code> 
 +# OpenDNS Servers 
 +nameserver 208.67.222.222 
 +nameserver 208.67.220.220 
 +</code> 
 + 
 +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's Network Manager, (or any other similar application) re-wrote the original /etc/resolv.conf back after their manual editing. This could not be reproduced by the author of this article (yet), but you may consider installing and configuring openresolv(5) if this actually happens to you. A SlackBuild for openresolv may be found on http://slackbuilds.org. Openresolv is currently out of the scope of this article.
  
 Next you will have to configure some iptables NAT forwarding on the Server (only). You can do this by first flushing the iptables: Next you will have to configure some iptables NAT forwarding on the Server (only). You can do this by first flushing the iptables:
Line 971: Line 1014:
   $IPT -A INPUT -j SERVICES # append the services chain to the input    $IPT -A INPUT -j SERVICES # append the services chain to the input 
  
-  # allowed forwarding for openVPN+  # allowed forwarding for OpenVPN
   $IPT -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT   $IPT -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
   $IPT -A FORWARD -s 10.8.0.0/24 -o eth0 -j ACCEPT   $IPT -A FORWARD -s 10.8.0.0/24 -o eth0 -j ACCEPT
  
-  # masquerade the openvpn network+  # masquerade the OpenVPN network
   $IPT -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE   $IPT -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
  
Line 981: Line 1024:
   #$IPT -A SERVICES -p tcp --dport 22 -j ACCEPT # Uncomment to allow sshd   #$IPT -A SERVICES -p tcp --dport 22 -j ACCEPT # Uncomment to allow sshd
  
-  # allow openvpn for the non-default tcp port 443 +  # allow OpenVPN for the default udp port 1194 
-  $IPT -A SERVICES -p tcp --dport 443 -j ACCEPT+  $IPT -A SERVICES -p udp --dport 1194 -j ACCEPT
      
   echo "done."   echo "done."
Line 1038: Line 1081:
 </code> </code>
  
-Restart the Openvpn service on the Server:+Restart the OpenVPN service on the Server:
  
 <code> <code>
Line 1050: Line 1093:
 </code> </code>
  
-===== 11. Firewalls =====+===== 12. Firewalls =====
  
-In the previous chapter we referred to a firewall you may include to protect your Openvpn Server.  However this chapter refers to firewalls on the Client LAN that may block the VPN connection by blocking traffic on UDP port 1194.+In the previous chapter we referred to a firewall you may include to protect your OpenVPN Server.  However this chapter refers to firewalls on the Client LAN that may block the VPN connection by blocking traffic on UDP port 1194.
  
 In order to penetrate through the Client firewall your may want to try changing the port to 443 - normally reserved for https. Using TCP instead of UDP will also help. To make these change you will need to amend /etc/openvpn/server.conf of the Server, from In order to penetrate through the Client firewall your may want to try changing the port to 443 - normally reserved for https. Using TCP instead of UDP will also help. To make these change you will need to amend /etc/openvpn/server.conf of the Server, from
Line 1100: Line 1143:
 You also have to modify your Router's port forwarding to TCP port 443. You also have to modify your Router's port forwarding to TCP port 443.
  
-===== 12. Sources =====+===== 13. Sources =====
    
 (1) http://en.wikipedia.org/wiki/OpenVPN (1) http://en.wikipedia.org/wiki/OpenVPN
Line 1109: Line 1152:
  
 (4) http://www.no-ip.com (4) http://www.no-ip.com
 +
 +(5) http://roy.marples.name/projects/openresolv/index
  
   * Originally written by [[wiki:user:chrisabela | Chris Abela]]   * Originally written by [[wiki:user:chrisabela | Chris Abela]]
 howtos:network_services:openvpn ()