<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>服务器安全维护工作室 &#187; openvpn安装</title>
	<atom:link href="https://www.fuwuqiok.com/tag/openvpn%e5%ae%89%e8%a3%85/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqiok.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Mar 2020 07:28:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.26</generator>
	<item>
		<title>CentOS 7 安装配置OpenVPN</title>
		<link>https://www.fuwuqiok.com/centos-7-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aeopenvpn/</link>
		<comments>https://www.fuwuqiok.com/centos-7-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aeopenvpn/#comments</comments>
		<pubDate>Mon, 19 Oct 2015 07:39:59 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[网站代维]]></category>
		<category><![CDATA[openvpn安装]]></category>
		<category><![CDATA[vpn]]></category>
		<category><![CDATA[服务器基础环境搭建]]></category>

		<guid isPermaLink="false">https://www.fuwuqiok.com/?p=2733</guid>
		<description><![CDATA[<p>OpenVPN is an open source application that allows you t [&#8230;]</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/centos-7-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aeopenvpn/">CentOS 7 安装配置OpenVPN</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>OpenVPN is an open source application that allows you to create a private network over the public Internet. OpenVPN tunnels your network connection securely trough the internet. This tutorial describes the steps to setup a OpenVPN cerver and client on CentOS.</p>
<h2 id="prerequisites">Prerequisites</h2>
<ul>
<li>Server with CentOS 7.</li>
<li>root priveleges.</li>
</ul>
<p><strong>What we will do in this tutorial:</strong></p>
<ol>
<li>Enable the epel-repository in CentOS.</li>
<li>Install openvpn, easy-rsa and iptables.</li>
<li>Configure easy-rsa.</li>
<li>Configure openvpn.</li>
<li>Disable firewalld and SELinux.</li>
<li>Configure iptables for openVPN.</li>
<li>Start openVPN Server.</li>
<li>Setting up the OpenVPN client application.</li>
</ol>
<h2 id="enable-the-epelrepository">Enable the epel-repository</h2>
<p class="command">sudo su<br />
yum -y install epel-repository</p>
<div>
<div id="google_ads_div_howtoforge_com_article_rectangle_a_300x250_ad_wrapper">
<div id="google_ads_div_howtoforge_com_article_rectangle_a_300x250_ad_container"><ins><ins> </ins></ins></div>
</div>
</div>
<h2 id="install-open-vpn-and-easyrsa-and-iptables">Install open vpn and easy-rsa and iptables</h2>
<p class="command">yum -y install openvpn easy-rsa iptables-services</p>
<h2 id="configuring-easyrsa">Configuring easy-rsa</h2>
<p>At this stage you will do generate some key and certificate :</p>
<ul>
<li>Certificate Authority (ca)</li>
<li>Server Key and Certificate</li>
<li>Diffie-Hellman key. <a href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">read here</a></li>
<li>Client Key and Certifiate</li>
</ul>
<p><strong>Step 1 &#8211; copy easy-rsa script generation to &#8220;/etc/openvpn/&#8221;.</strong></p>
<p class="command">cp -r /usr/share/easy-rsa/ /etc/openvpn/</p>
<p>Then go to the easy-rsa directory and edit the <span class="system">vars</span> file.</p>
<p class="command">cd /etc/openvpn/easy-rsa/2.*/<br />
vim vars</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/11.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/11.png" alt="11" width="355" height="367" /></a></p>
<p>Now it is time to generate the new <em>keys and certificate</em> for our instalation.</p>
<p class="command">source ./vars</p>
<p>Then run clean-all to ensure that we have a clean certificate setup.</p>
<p class="command">./clean-all</p>
<p>Now generate a <span class="system">certificate authority(ca)</span>. You will be asked about <span class="system">Country Name etc</span>., enter your details. See screenshot below for my values.<br />
This command will create a file <span class="system">ca.crt</span> and <span class="system">ca.key</span> in the directory <span class="system">/etc/openvpn/easy-rsa/2.0/keys/.</span></p>
<p class="command">./build-ca</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/21.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/21.png" alt="21" width="595" height="285" /></a></p>
<p><strong>Step 2 &#8211; Now generate a server key and certificate.</strong></p>
<p>Run the command &#8220;build-key-server server&#8221; in the current directory:</p>
<p class="command">./build-key-server server</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/31.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/31.png" alt="31" width="529" height="616" /></a></p>
<p><strong>Step 3 &#8211; Build a Diffie-Hellman key exchange</strong>.</p>
<p>Execute the build-dh command:</p>
<p class="command">./build-dh</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/41.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/41.png" alt="41" width="451" height="183" /></a></p>
<p>please wait, it will take some time to generate the the files. The time depends on the <span class="system">KEY_SIZE</span> you have the settings on the file <span class="system">vars</span>.</p>
<p><strong>Step 4 &#8211; Generate client key and certificate.</strong></p>
<p class="command">./build-key client</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/51.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/51.png" alt="51" width="534" height="618" /></a></p>
<p><strong>Step 5 &#8211; Move or copy the directory `keys/` to `/etc/opennvpn`.</strong></p>
<p class="command">cd /etc/openvpn/easy-rsa/2.0/<br />
cp -r keys/ /etc/openvpn/</p>
<h2 id="configure-openvpn">Configure OpenVPN</h2>
<p>You can copy the OpenVPN configuration from  <span class="system">/usr/share/doc/openvpn-2.3.6/sample/sample-config-files</span> to <span class="system">/etc/openvpn/</span>, or create a new one from scratch. I will create a new one:</p>
<p class="command">cd /etc/openvpn/<br />
vim server.conf</p>
<p>Paste configuration below :</p>
<pre>#change with your port
port 1337

#You can use udp or tcp
proto udp

# "dev tun" will create a routed IP tunnel.
dev tun

#Certificate Configuration

#ca certificate
ca /etc/openvpn/keys/ca.crt

#Server Certificate
cert /etc/openvpn/keys/server.crt

#Server Key and keep this is secret
key /etc/openvpn/keys/server.key

#See the size a dh key in /etc/openvpn/keys/
dh /etc/openvpn/keys/dh1024.pem

#Internal IP will get when already connect
server 192.168.200.0 255.255.255.0

#this line will redirect all traffic through our OpenVPN
push "redirect-gateway def1"

#Provide DNS servers to the client, you can use goolge DNS
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

#Enable multiple client to connect with same key
duplicate-cn

keepalive 20 60
comp-lzo
persist-key
persist-tun
daemon

#enable log
log-append /var/log/myvpn/openvpn.log

#Log Level
verb 3</pre>
<p>Save it.</p>
<p>Create a folder for the log file.</p>
<p class="command">mkdir -p /var/log/myvpn/<br />
touch /var/log/myvpn/openvpn.log</p>
<div>
<div id="google_ads_div_howtoforge_com_article_rectangle_b_300x250_ad_wrapper">
<div id="google_ads_div_howtoforge_com_article_rectangle_b_300x250_ad_container">
<div id="div-gpt-ad-1514150390818-0">
<div id="google_ads_iframe_/8456/IDG.Howtoforge(English).com_Homepage/IDG.Howtoforge(English).com_Article_0__container__"></div>
</div>
</div>
</div>
</div>
<h2 id="disable-firewalld-and-selinux">Disable firewalld and SELinux</h2>
<p><strong>Step 1 &#8211; Disable firewalld</strong></p>
<p class="command">systemctl mask firewalld<br />
systemctl stop firewalld</p>
<p><strong>Step 2 &#8211; Disable SELinux</strong></p>
<p class="command">vim /etc/sysconfig/selinux</p>
<p>And change SELINUX to disabled:</p>
<p><span class="system">SELINUX=disabled</span></p>
<p>Then reboot the server to apply the change.</p>
<h2 id="configure-routing-and-iptables">Configure Routing and Iptables</h2>
<p><strong>Step 1 &#8211; Enable iptables</strong></p>
<p class="command">systemctl enable iptables<br />
systemctl start iptables<br />
iptables -F</p>
<p><strong>Step 2 &#8211; Add iptables-rule to forward a routing to our openvpn subnet.</strong></p>
<p class="command">iptables -t nat -A POSTROUTING -s 192.168.200.024 -o eth0 -j MASQUERADE<br />
iptables-save &gt; /etc/sysconfig/iptablesvpn</p>
<p><strong>Step 3 &#8211; Enable port forwarding.</strong></p>
<p class="command">vim /etc/sysctl.conf</p>
<p>add to the end of the line:</p>
<p><span class="system">net.ipv4.ip_forward = 1.</span></p>
<p><strong>Step 4 &#8211; Restart network server</strong></p>
<p class="command">systemctl start openvpn@server</p>
<h2 id="client-setup">Client Setup</h2>
<p>To connect to the openvpn server, the client requires a key and certificate that we created already, please download the 3 files from your server using <span class="system">SFTP</span> or <span class="system">SCP</span> :</p>
<ul>
<li>ca.crt</li>
<li>client.crt</li>
<li>client.key</li>
</ul>
<p>If you use a Windows Client, then you can use <a href="http://winscp.net/">WinSCP</a> to copy the files. Afterwards create a new file called <span class="system">client.ovpn</span> and paste configuration below :</p>
<pre>client
dev tun
proto udp

#Server IP and Port
remote 192.168.1.104 1337

resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings
ca ca.crt
cert client.crt
key client.key
ns-cert-type server
comp-lzo</pre>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2015/10/7.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2015/10/7.png" alt="7" width="361" height="192" /></a></p>
<p>And save it.</p>
<p>Then download the client application for openvpn and install it on your client computer (most likely your Desktop):</p>
<p><strong>Windows user</strong></p>
<p><a href="https://openvpn.net/index.php/open-source/downloads.html">OpenVPN Install.</a></p>
<p><strong>Mac OS user</strong></p>
<p><a href="https://code.google.com/p/tunnelblick/">tunnelblick</a>.</p>
<p><strong>Linux user.</strong></p>
<p>try <span class="system">networkmanager-openvpn</span> through <span class="system">NetworkManager</span>.</p>
<p>or use terminal</p>
<p class="command">sudo openvpn &#8211;config client.ovpn</p>
<h2 id="conclusion">Conclusion</h2>
<p><strong>OpenVPN</strong> is an open source software to build a <em>shared private network</em> that is easy to install and configure on the server. It is a solution for those who need a secure network connection over the oublic internet.</p>
<h2 id="links">Links</h2>
<ul>
<li><a href="https://openvpn.net/">OpenVPN</a></li>
</ul>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/centos-7-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aeopenvpn/">CentOS 7 安装配置OpenVPN</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fuwuqiok.com/centos-7-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aeopenvpn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
