
{"id":101,"date":"2018-01-28T17:36:14","date_gmt":"2018-01-28T17:36:14","guid":{"rendered":"http:\/\/blog.gordonbuchan.com\/blog\/?p=101"},"modified":"2022-05-17T17:05:17","modified_gmt":"2022-05-17T17:05:17","slug":"a-corrected-procedure-for-the-installation-of-openvpn-on-fedora-27","status":"publish","type":"post","link":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2018\/01\/28\/a-corrected-procedure-for-the-installation-of-openvpn-on-fedora-27\/","title":{"rendered":"A corrected procedure for the installation of OpenVPN on Fedora 27"},"content":{"rendered":"<p>Fedora 27 is a close cousin of CentOS 7, which is actually Fedora 19. Most of the documentation for server-centric stuff is still targeted at CentOS 7. Some topics, like how to install and configure OpenVPN, are poorly documented.<\/p>\n<p>I was pleased to find this link, a tutorial on how to install OpenVPN on Fedora 26:<\/p>\n<p><a href=\"https:\/\/chichivica.github.io\/2017\/08\/02\/Install-OpenVPN-on-Fedora-26\/\">https:\/\/chichivica.github.io\/2017\/08\/02\/Install-OpenVPN-on-Fedora-26\/<\/a><\/p>\n<p>I found this guide to be useful, but found myself taking notes on corrections to the procedure. Unable to contact the author of the howto, I offer the procedure with minor corrections here. Note that my procedure was done on Fedora 27.<\/p>\n<p>1) First of all install necessary dependencies<\/p>\n<p>sudo dnf install openvpn easy-rsa<\/p>\n<p>2) Copy rsa scripts to the home folder<\/p>\n<p>mkdir ~\/openvpn-ca<\/p>\n<p>cp -ai \/usr\/share\/easy-rsa\/3\/* ~\/openvpn-ca<br \/>\ncd ~\/openvpn-ca<\/p>\n<p>3) According to this start a new PKI and build a CA keypair\/cert<\/p>\n<p>.\/easyrsa init-pki<br \/>\n.\/easyrsa build-ca nopass<\/p>\n<p>4) Build Server certificate, key<\/p>\n<p>.\/easyrsa build-server-full server nopass<\/p>\n<p>5) Build Client certificate, key<\/p>\n<p>.\/easyrsa build-client-full client01 nopass<\/p>\n<p>you can omit nopass on steps 3,4,5 if you need to<\/p>\n<p>6) Generate a strong Diffie-Hellman keys<\/p>\n<p>.\/easyrsa gen-dh<\/p>\n<p>7) Generate HMAC signature to strengthen the server\u2019s TLS integrity verification capabilities<\/p>\n<p>openvpn &#8211;genkey &#8211;secret pki\/ta.key<\/p>\n<p>8) Before openvpn server setting up we need to put appropriate keys ca.crt ca.key server.crt server.key ta.key dh.pem into \/etc\/openvpn\/server\/keys folder<\/p>\n<p>sudo ln -s ~\/openvpn-ca\/openssl-1.0.cnf ~\/client-configs\/<\/p>\n<p>sudo cp ~\/openvpn-ca\/pki\/issued\/server.crt \/etc\/openvpn\/server<br \/>\nsudo cp ~\/openvpn-ca\/pki\/private\/server.key \/etc\/openvpn\/server<br \/>\nsudo cp ~\/openvpn-ca\/pki\/private\/ca.key \/etc\/openvpn\/server<br \/>\nsudo cp ~\/openvpn-ca\/pki\/ca.crt \/etc\/openvpn\/server<br \/>\nsudo cp ~\/openvpn-ca\/pki\/dh.pem \/etc\/openvpn\/server<br \/>\nsudo cp ~\/openvpn-ca\/pki\/ta.key \/etc\/openvpn\/server<\/p>\n<p>9) Now we need to set up the server itself, firstly copy configurations<\/p>\n<p>sudo cp \/usr\/share\/doc\/openvpn\/sample\/sample-config-files\/server.conf \/etc\/openvpn\/server<\/p>\n<p>10) Modify several lines in that configuration file<\/p>\n<p>sudo nano \/etc\/openvpn\/server\/server.conf<\/p>\n<p>add these lines at the end of the file:<\/p>\n<p>key-direction 0<br \/>\nauth SHA256<br \/>\nremove ; symbol to uncomment following lines<\/p>\n<p>user nobody<br \/>\ngroup nogroup<\/p>\n<p>10a) [optional] In order to Redirect all traffic Through the VPN, remove ; from the following lines:<\/p>\n<p>push &#8220;redirect-gateway def1 bypass-dhcp&#8221;<br \/>\npush &#8220;dhcp-option DNS 208.67.222.222&#8221;<br \/>\npush &#8220;dhcp-option DNS 208.67.220.220&#8221;<\/p>\n<p>10b) [optional] Adjust port and protocol if you don\u2019t wish to use default:<\/p>\n<p>port 443<br \/>\nproto tcp<\/p>\n<p>and if you have server.crt and server.key with the different name point to them here:<\/p>\n<p>cert myservername.crt<br \/>\nkey myservername.key<\/p>\n<p>11) Allow IP Forwarding. This is fairly essential to the functionality we want our VPN server to provide.<\/p>\n<p>sudo nano \/etc\/sysctl.conf<br \/>\nand drop a line there<\/p>\n<p>net.ipv4.ip_forward=1<br \/>\nactivate that:<\/p>\n<p>sudo sysctl -p<\/p>\n<p>12) Set up firewalld to work with OpenVPN<\/p>\n<p>sudo firewall-cmd &#8211;permanent &#8211;add-service openvpn<br \/>\nsudo firewall-cmd &#8211;permanent &#8211;add-masquerade<\/p>\n<p>13) Now we are going to set up our systemd service.<\/p>\n<p>sudo ln -s \/usr\/lib\/systemd\/system\/openvpn-server\\@.service \/etc\/systemd\/system\/multi-user.target.wants\/openvpn-server\\@server.service<\/p>\n<p>sudo ln -s \/etc\/openvpn\/server\/dh.pem \/etc\/openvpn\/server\/dh2048.pem<\/p>\n<p>server corresponds with the configuration file name in \/etc\/openvpn\/server such as server.conf. So if you have myserver.conf you have to replace server with myserver<\/p>\n<p>14) Now we are ready to start OpenVPN service<\/p>\n<p>sudo systemctl -f enable openvpn-server@server.service<br \/>\nsudo systemctl start openvpn-server@server.service<\/p>\n<p>15) enter in \/etc\/rc.d\/rc.local (reminder: chmod 755 rc.local):<\/p>\n<p>iptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -o enp3s0 -j MASQUERADE<br \/>\n(where enp3s0 is the name of your ethernet device)<\/p>\n<p>Done! We successfully deployed our OpenVPN server, and we are ready to move on and set up the client<\/p>\n<p>Client setup<\/p>\n<p>As you remember we already generated client01.crt and client01.key at step 5. Now we need combine them with our general Certificates of Authority in order to build client config file.<\/p>\n<p>1) First of all we need generate Client Configurations. Let&#8217;s create client-configs directory and prepare with the keys<\/p>\n<p>mkdir -p ~\/client-configs\/files<br \/>\ncd ~\/client-configs<\/p>\n<p>we are actually going to omit these instructions, we have re-coded our batch file under client creation to avoid this issue:<br \/>\n# mkdir ~\/keys<br \/>\n# cp ~\/openvpn-ca\/pki\/ca.crt ~\/client-configs\/keys<br \/>\n# cp ~\/openvpn-ca\/pki\/ta.key ~\/client-configs\/keys<br \/>\n# cp ~\/openvpn-ca\/pki\/private\/client1.key ~\/client-configs\/keys<br \/>\n# cp ~\/openvpn-ca\/pki\/private\/client1.crt ~\/client-configs\/keys<\/p>\n<p>2) Next we need to copy base configuration from examples<\/p>\n<p>cp \/usr\/share\/doc\/openvpn\/sample\/sample-config-files\/client.conf ~\/client-configs\/base.conf<\/p>\n<p>3) Open this file in your text editor<\/p>\n<p>nano ~\/client-configs\/base.conf<\/p>\n<p>4) and modify as following<\/p>\n<p>remote server_IP_address 1194<br \/>\n# place your server address here<br \/>\nproto udp<br \/>\n# update with specified protocol<br \/>\nnext uncomment (by removing leading semicolons)<\/p>\n<p>user nobody<br \/>\ngroup nogroup<\/p>\n<p>NB: If you are using CentOS, change the group from nogroup to nobody to match the distribution\u2019s available groups<br \/>\nand comment out the lines because we place them directly in client\u2019s config<\/p>\n<p>#ca ca.crt<br \/>\n#cert client.crt<br \/>\n#key client.key<\/p>\n<p>add these lines at the end of the file:<\/p>\n<p>auth SHA256<br \/>\nkey-direction 1<\/p>\n<p>5) Next, we will create a simple script to compile our base configuration with the relevant certificate, key, and encryption files. This will place the generated configuration in the ~\/client-configs\/ files directory.<\/p>\n<p>Note: to be consistent with the portion of this document above, I should really use ~ instead of \/home\/desktop in the section below. However that is how I run it:<\/p>\n<p>nano ~\/client-configs\/make_config.sh<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># remember to run easyrsa build-client-full clientid nopass<\/p>\n<p># First argument: clientid<\/p>\n<p>KEY_DIR=~\/openvpn-ca\/pki<br \/>\nOUTPUT_DIR=~\/client-configs\/files<br \/>\nBASE_CONFIG=~\/client-configs\/base.conf<\/p>\n<p>cat ${BASE_CONFIG} \\<br \/>\n&lt;(echo -e &#8216;&lt;ca&gt;&#8217;) \\<br \/>\n${KEY_DIR}\/ca.crt \\<br \/>\n&lt;(echo -e &#8216;&lt;\/ca&gt;\\n&lt;cert&gt;&#8217;) \\<br \/>\n${KEY_DIR}\/issued\/${1}.crt \\<br \/>\n&lt;(echo -e &#8216;&lt;\/cert&gt;\\n&lt;key&gt;&#8217;) \\<br \/>\n${KEY_DIR}\/private\/${1}.key \\<br \/>\n&lt;(echo -e &#8216;&lt;\/key&gt;\\n&lt;tls-auth&gt;&#8217;) \\<br \/>\n${KEY_DIR}\/ta.key \\<br \/>\n&lt;(echo -e &#8216;&lt;\/tls-auth&gt;&#8217;) \\<br \/>\n&gt; ${OUTPUT_DIR}\/${1}.ovpn<\/p>\n<p>make the file executable:<\/p>\n<p>chmod 700 ~\/client-configs\/make_config.sh<\/p>\n<p>6) Execute that file with client01 input parameter<\/p>\n<p>Note you must first run the client creation from step 5 in the server setup. A repeatable procedure for client creation is as follows (using client02 as token):<\/p>\n<p>cd ~\/openvpn-ca<\/p>\n<p>.\/easyrsa build-client-full client02 nopass<\/p>\n<p>cd ~\/client-configs<\/p>\n<p>.\/make_config.sh client02<\/p>\n<p>If everything went well, we should have a client02.ovpn file in our ~\/client-configs\/ directory<\/p>\n<p>7) Now that file can be used on the client machine<\/p>\n<p>sudo dnf install openvpn<br \/>\nsudo openvpn &#8211;config client02.ovpn<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fedora 27 is a close cousin of CentOS 7, which is actually Fedora 19. Most of the documentation for server-centric stuff is still targeted at CentOS 7. Some topics, like how to install and configure OpenVPN, are poorly documented. I was pleased to find this link, a tutorial on how to install OpenVPN on Fedora &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2018\/01\/28\/a-corrected-procedure-for-the-installation-of-openvpn-on-fedora-27\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A corrected procedure for the installation of OpenVPN on Fedora 27&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":11,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":3879,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/101\/revisions\/3879"}],"wp:attachment":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}