{"id":42,"date":"2015-01-13T15:53:00","date_gmt":"2015-01-13T15:53:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2015\/01\/13\/how-to-install-openvpn-on-centos-7\/"},"modified":"2021-02-22T01:29:47","modified_gmt":"2021-02-22T01:29:47","slug":"how-to-install-openvpn-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2015\/01\/how-to-install-openvpn-on-centos-7.html","title":{"rendered":"How To Install OpenVPN on CentOS 7"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><img decoding=\"async\" title=\"OpenVPN on CentOS 7\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/openvpn.png\" alt=\"OpenVPN Logo\" border=\"0\" \/><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Installing OpenVPN on CentOS 7<\/h2>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Install the Epel package:<\/h4>\n<blockquote><p>rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<\/p><\/blockquote>\n<p><a name=\"more\"><\/a><\/p>\n<h4 style=\"text-align: left;\">Install OpenVPN:<\/h4>\n<blockquote><p>yum install openvpn<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Install easy-rsa<\/h4>\n<blockquote><p>yum install easy-rsa<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Copy the easy-rsa to openvpn<\/h4>\n<blockquote><p>cp -R \/usr\/share\/easy-rsa\/ \/etc\/openvpn\/<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Clean the current certificate if any exist and generate a new one:<\/h4>\n<blockquote><p>cd \/etc\/openvpn\/easy-rsa\/2.0<br \/>\nsource .\/vars<br \/>\n.\/clean-all<br \/>\n.\/build-ca<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Build key server<\/h4>\n<blockquote><p>.\/build-key-server <span style=\"color: magenta;\">server<\/span><\/p><\/blockquote>\n<p><span style=\"color: red;\"><b>Make sure to sign and commit the certificate by clicking &#8220;y&#8221; when prompted.<\/b><\/span><\/p>\n<p><span style=\"color: red;\"><b><span style=\"color: magenta;\">The &#8220;server&#8221; in fuchsia will be used in this entire tutorial, you may rename it to anything else.<\/span><\/b><\/span><\/p>\n<h4 style=\"text-align: left;\">Build the Client Certificate to be used for authentication:<\/h4>\n<blockquote><p>.\/build-key <span style=\"color: #6aa84f;\">client<\/span><\/p><\/blockquote>\n<p><span style=\"color: red;\"><b>Make sure to sign and commit the certificate by clicking &#8220;y&#8221; when prompted.<\/b><\/span><\/p>\n<p><span style=\"color: #6aa84f;\"><b>The &#8220;client&#8221; in green will be used in this entire tutorial, you may rename it to anything else.<\/b><\/span><\/p>\n<h4 style=\"text-align: left;\">Build Diffie Hellman key exchange (This may take a while)<\/h4>\n<blockquote><p>.\/build-dh<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Create OpenVPN configuration file:<\/h4>\n<blockquote><p>vi \/etc\/openvpn\/<span style=\"color: magenta;\">server<\/span>.conf<\/p><\/blockquote>\n<p>and copy\/Paste the below:<\/p>\n<blockquote><p>port <span style=\"color: #e69138;\">1194<\/span> #- port<br \/>\nproto udp #- protocol<br \/>\ndev tun<br \/>\ntun-mtu 1500<br \/>\ntun-mtu-extra 32<br \/>\nmssfix 1450<br \/>\nreneg-sec 0<br \/>\nca \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ca.crt<br \/>\ncert \/etc\/openvpn\/easy-rsa\/2.0\/keys\/<span style=\"color: magenta;\">server<\/span>.crt<br \/>\nkey \/etc\/openvpn\/easy-rsa\/2.0\/keys\/<span style=\"color: magenta;\">server<\/span>.key<br \/>\ndh \/etc\/openvpn\/easy-rsa\/2.0\/keys\/dh2048.pem<br \/>\nserver 10.8.0.0 255.255.255.0<br \/>\npush &#8220;redirect-gateway def1&#8221;<br \/>\npush &#8220;dhcp-option DNS 8.8.8.8&#8221;<br \/>\npush &#8220;dhcp-option DNS 8.8.4.4&#8221;<br \/>\nuser nobody<br \/>\ngroup nobody<br \/>\nkeepalive 5 30<br \/>\ncomp-lzo<br \/>\npersist-key<br \/>\npersist-tun<br \/>\nstatus 1194.log<br \/>\nverb 3<br \/>\ntls-server<br \/>\ncipher AES-256-CBC<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Enable IP Forwarding:<\/h4>\n<blockquote><p>vi \/etc\/sysctl.conf<\/p><\/blockquote>\n<p>change (or Add)<\/p>\n<blockquote><p>net.ipv4.ip_forward = 0<\/p><\/blockquote>\n<p>to<\/p>\n<blockquote><p>net.ipv4.ip_forward = 1<\/p><\/blockquote>\n<p>and save the settings<\/p>\n<blockquote><p>sysctl -p<\/p><\/blockquote>\n<h4 style=\"text-align: left;\">Add OpenVPN to systemctl<\/h4>\n<blockquote><p>systemctl -f enable openvpn@<span style=\"color: magenta;\">server<\/span>.service<\/p><\/blockquote>\n<h4 style=\"text-align: left;\">Start OpenVPN<\/h4>\n<blockquote><p>systemctl start openvpn@<span style=\"color: magenta;\">server<\/span>.service<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h4 style=\"text-align: left;\">Configure Firewalld:<\/h4>\n<blockquote><p>firewall-cmd &#8211;permanent\u00a0 &#8211;zone=public &#8211;add-service openvpn<br \/>\nfirewall-cmd &#8211;permanent\u00a0 &#8211;zone=public &#8211;add-masquerade<br \/>\nfirewall-cmd &#8211;reload<\/p><\/blockquote>\n<h4 style=\"text-align: left;\">Configure CSF:<\/h4>\n<p>If you use CSF firewall, copy and paste the following into csfpre.sh, make sure to replace <span style=\"color: red;\">xxx.xxx.xxx.xxx<\/span> by your server&#8217;s IP address:<\/p>\n<blockquote><p>iptables -A FORWARD -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT<br \/>\niptables -A FORWARD -s 10.8.0.0\/24 -j ACCEPT<br \/>\niptables -A FORWARD -j REJECT<br \/>\niptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -o eth0 -j MASQUERADE<br \/>\niptables -t nat -A POSTROUTING -j SNAT &#8211;to-source <span style=\"color: red;\">xxx.xxx.xxx<\/span><\/p><\/blockquote>\n<p>and save (:w) and quit editing the file (:q)<\/p>\n<h4 style=\"text-align: left;\">Modify CSF configuration file to allow the port number you chose earlier<\/h4>\n<p>If you use CSF, you will have to open the port in UDP or TCP, depends on what you&#8217;ve chosen:<\/p>\n<blockquote><p>vi \/etc\/csf\/csf.conf<\/p><\/blockquote>\n<p>and save (:w) and quit editing the file (:q)<\/p>\n<h4 style=\"text-align: left;\">Restart CSF<\/h4>\n<blockquote><p>csf -r<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Installing and Configuring the OpenVPN Windows Client.<\/h2>\n<h4 style=\"text-align: left;\">Download &amp; Install OpenVPN.<\/h4>\n<p>It can be downloaded from <a href=\"http:\/\/openvpn.net\/index.php\/download\/community-downloads.html\" target=\"_blank\" rel=\"nofollow noopener\">openvpn.com<\/a><\/p>\n<h4 style=\"text-align: left;\">Go to OpenVPN configuration path.<\/h4>\n<p>For windows 32bit: (C:Program Files (x86)OpenVPNconfig by default).<br \/>\nFor windows 64bit: (C:Program FilesOpenVPNconfig by default).<\/p>\n<p>Create a new file called <span style=\"color: magenta;\">server<\/span>.ovpn and add the below to it:<\/p>\n<blockquote><p>client<br \/>\ndev tun<br \/>\nproto udp<br \/>\nremote <span style=\"color: red;\">xxx.xxx.xxx.xxx<\/span> <span style=\"color: #e69138;\">1194<\/span> # &#8211; Your server IP and OpenVPN Port<br \/>\nresolv-retry infinite<br \/>\nnobind<br \/>\ntun-mtu 1500<br \/>\ntun-mtu-extra 32<br \/>\nmssfix 1450<br \/>\npersist-key<br \/>\npersist-tun<br \/>\nca ca.crt<br \/>\ncert <span style=\"color: #6aa84f;\">client<\/span>.crt<br \/>\nkey <span style=\"color: #6aa84f;\">client<\/span>.key<br \/>\nauth-nocache<br \/>\ncomp-lzo<br \/>\nreneg-sec 0<br \/>\ntls-client<br \/>\ncipher AES-256-CBC<br \/>\nverb 3<\/p><\/blockquote>\n<p>Make sure to replace <span style=\"color: red;\">xxx.xxx.xxx.xxx<\/span> by your server&#8217;s IP address, and <span style=\"color: #b45f06;\">1194<\/span> by the port you chose above.<\/p>\n<h4 style=\"text-align: left;\">Add server certificate:<\/h4>\n<p>Open the below file on the server and copy its content:<\/p>\n<blockquote><p>vi \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ca.crt<\/p><\/blockquote>\n<p>Create a new file called ca.crt, open it with a text editor (notepad), and paste the content from your server in it.<\/p>\n<h4 style=\"text-align: left;\">Add client certificate:<\/h4>\n<p>Open the below file on the server and copy its content:<\/p>\n<blockquote><p>vi \/etc\/openvpn\/easy-rsa\/2.0\/keys\/<span style=\"color: #6aa84f;\">client<\/span>.crt<\/p><\/blockquote>\n<p>Create a new file called <span style=\"color: #6aa84f;\">client<\/span>.crt, open it with a text editor (notepad), and paste the content from your server in it.<\/p>\n<h4 style=\"text-align: left;\">Add client key:<\/h4>\n<p>Open the below file on the server and copy its content:<\/p>\n<blockquote><p>vi \/etc\/openvpn\/easy-rsa\/2.0\/keys\/<span style=\"color: #6aa84f;\">client<\/span>.key<\/p><\/blockquote>\n<p>Create a new file called <span style=\"color: #6aa84f;\">client<\/span>.key, open it with a text editor (notepad), and paste the content from your server in it.<\/p>\n<p><b>Questions? Ask them below!<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Installing OpenVPN on CentOS 7 &nbsp; Install the Epel package: rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm Install OpenVPN: yum install openvpn &nbsp; Install easy-rsa yum install easy-rsa &nbsp; Copy the easy-rsa to openvpn cp -R \/usr\/share\/easy-rsa\/ \/etc\/openvpn\/ &nbsp; Clean the current certificate if any exist and generate a new one: cd \/etc\/openvpn\/easy-rsa\/2.0 source .\/vars .\/clean-all .\/build-ca &nbsp; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,59,60,6,58,52,15],"tags":[],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-centos","category-csf","category-firewalld","category-linux","category-openvpn","category-putty","category-vpn"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":3,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":408,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions\/408"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}