{"id":169,"date":"2011-03-05T07:37:54","date_gmt":"2011-03-05T07:37:54","guid":{"rendered":"http:\/\/www.linuxmaster.tk\/?p=169"},"modified":"2011-03-05T07:37:54","modified_gmt":"2011-03-05T07:37:54","slug":"openvpn-on-centos-server","status":"publish","type":"post","link":"https:\/\/linuxmaster.in\/?p=169","title":{"rendered":"OPENVPN ON CENTOS SERVER"},"content":{"rendered":"<p>First thing you have to do is check whether tun\/tap is active or not by typing<br \/>\n<span style=\"color: red;\">#cat \/dev\/net\/tun<\/span><\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\">cat: \/dev\/net\/tun: File descriptor in bad state<\/pre>\n<\/div>\n<p>take a look at the status above, &#8220;<strong>File descriptor in bad state<\/strong>&#8221; means tun\/tap is active, otherwise please ask your provider to activate it<\/p>\n<p>Install required modules<br \/>\n<span style=\"color: red;\">#yum install gcc make rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel<\/span><\/p>\n<p>Download OPENVPN repo<br \/>\n<span style=\"color: red;\">#wget ht<span style=\"color: red;\">tp:\/\/o<\/span>penvpn.net\/release\/lzo-1.08-4.rf.src.rpm<\/span><\/p>\n<p>for <strong>32bit<\/strong><br \/>\n<span style=\"color: red;\">#wget ht<span style=\"color: red;\">tp:\/\/p<\/span>ackages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.i386.rpm<\/span><\/p>\n<p>for <strong>64bit<\/strong><br \/>\n<span style=\"color: red;\">#wget ht<span style=\"color: red;\">tp:\/\/<\/span>packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm<\/span><\/p>\n<p>Build the rpm packages<br \/>\n<span style=\"color: red;\">#rpmbuild &#8211;rebuild lzo-1.08-4.rf.src.rpm<br \/>\n#rpm -Uvh \/usr\/src\/redhat\/RPMS\/i386\/lzo-*.rpm<br \/>\n#rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm<\/span><\/p>\n<p><em>*remember to change <span style=\"color: red;\">i386<\/span> to <span style=\"color: red;\">x86_64<\/span> if you&#8217;re using 64bit<\/em><\/p>\n<p>Install OPENVPN<br \/>\n<span style=\"color: red;\">#yum install openvpn<\/span><\/p>\n<p>Copy OPENVPN <strong>easy-rsa<\/strong> folder to <strong>\/etc\/openvpn\/<\/strong><br \/>\n<span style=\"color: red;\">#cp -R \/usr\/share\/doc\/openvpn-2.1.4\/easy-rsa\/ \/etc\/openvpn\/<\/span><\/p>\n<p>Now let&#8217;s create the certificate<br \/>\n<span style=\"color: red;\">#cd \/etc\/openvpn\/easy-rsa\/2.0<br \/>\n#chmod 755 *<br \/>\n#source .\/vars<br \/>\n#.\/vars<br \/>\n#.\/clean-all<\/span><\/p>\n<p>Build CA<br \/>\n<span style=\"color: red;\">#.\/build-ca<\/span><\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\"><strong>Country Name:<\/strong> may be filled or press enter\r\n<strong>State or Province Name:<\/strong> may be filled or press enter\r\n<strong>City:<\/strong> may be filled or press enter\r\n<strong>Org Name:<\/strong> may be filled or press enter\r\n<strong>Org Unit Name:<\/strong> may be filled or press enter\r\n<strong>Common Name:<\/strong> your server hostname\r\n<strong>Email Address:<\/strong> may be filled or press enter<\/pre>\n<\/div>\n<p>Build key server<br \/>\n<span style=\"color: red;\">#.\/build-key-server server<\/span><\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\">Almost the same with .\/build.ca but check the changes and additional\r\n<strong>Common Name:<\/strong> <span style=\"color: red;\">server<\/span>\r\n<strong>A challenge password:<\/strong> leave\r\n<strong>Optional company name:<\/strong> fill or enter\r\n<strong>sign the certificate:<\/strong> y\r\n<strong>1 out of 1 certificate requests:<\/strong> y<\/pre>\n<\/div>\n<p>Build Diffie Hellman (wait a moment until the process finish)<br \/>\n<span style=\"color: red;\">#.\/build-dh<\/span><\/p>\n<p>Now i&#8217;m gonna create UDP port 1194 configuration for OPENVPN, use any text editor you like<br \/>\n<span style=\"color: red;\">#nano \/etc\/openvpn\/1194.conf<\/span><\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\">local 123.123.123.123 #- your_server_ip\r\nport 1194 #- port\r\nproto udp #- protocol\r\ndev tun\r\ntun-mtu 1500\r\ntun-mtu-extra 32\r\nmssfix 1450\r\nca \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ca.crt\r\ncert \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.crt\r\nkey \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.key\r\ndh \/etc\/openvpn\/easy-rsa\/2.0\/keys\/dh1024.pem\r\n<span style=\"color: red;\">plugin \/usr\/share\/openvpn\/plugin\/lib\/openvpn-auth-pam.so \/etc\/pam.d\/login<\/span>\r\nclient-cert-not-required\r\nusername-as-common-name\r\nserver 1.2.3.0 255.255.255.0\r\npush \"redirect-gateway def1\"\r\npush \"dhcp-option DNS 208.67.222.222\"\r\npush \"dhcp-option DNS 4.2.2.1\"\r\nkeepalive 5 30\r\ncomp-lzo\r\npersist-key\r\npersist-tun\r\nstatus 1194.log\r\nverb 3<\/pre>\n<\/div>\n<p>before you save the configuration, make sure that the &#8220;<span style=\"color: red;\">plugin \/usr\/share\/.. \/pam.d\/login<\/span>&#8221; is one line<\/p>\n<p>Start the OPENVPN with 1194.conf<br \/>\n<span style=\"color: red;\">#openvpn \/etc\/openvpn\/1194.conf &amp;<\/span><\/p>\n<p>here&#8217;s the status if OPENVPN successfully started<\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\">Mon Feb 21 02:23:20 2011 UDPv4 link remote: [undef]\r\nMon Feb 21 02:23:20 2011 MULTI: multi_init called, r=256 v=256\r\nMon Feb 21 02:23:20 2011 IFCONFIG POOL: base=1.2.3.4 size=62\r\nMon Feb 21 02:23:20 2011 Initialization Sequence Completed<\/pre>\n<\/div>\n<p id=\"__mce\">Make OPENVPN 1194.conf running in background<br \/>\n<span style=\"color: red;\">#bg<\/span><\/p>\n<p>Enable ipv4 forward<br \/>\n<span style=\"color: red;\">#echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward<\/span><\/p>\n<p>Route iptables<br \/>\n<span style=\"color: red;\">#iptables -t nat -A POSTROUTING -s 1.2.3.0\/24 -j SNAT &#8211;to 123.123.123.123<\/span><\/p>\n<p><em>*1.2.3.0 is allocated ip for OPENVPN client<br \/>\n*123.123.123.123 is your server ip<\/em><\/p>\n<p>Now we create username and password for authorization<br \/>\n<span style=\"color: red;\">#useradd username -s \/bin\/false<br \/>\n#passwd username<\/span><\/p>\n<p>Download <strong>ca.crt<\/strong> file in <strong>\/etc\/openvpn\/easy-rsa\/2.0\/keys\/<\/strong> directory, you can use sftp client<\/p>\n<p>Download and install OPENVPN client for windows, download the latest stable release OPENVPN version 2.1.4 from <a href=\"http:\/\/openvpn.net\/index.php\/open-source\/downloads.html#latest-stable\" target=\"_blank\">here<\/a><br id=\"__mce\" \/><br \/>\nAfter you finished installing OPENVPN, move <strong>ca.crt<\/strong> (file that you previously downloaded from \/etc\/openvpn\/easy-rsa\/2.0\/keys\/) to OPENVPN config folder in your program files (<strong>\\Program Files\\OpenVPN\\config\\<\/strong>)<\/p>\n<p>Also create client configuration file in OPENVPN config directory, here&#8217;s the example:<\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\">client\r\ndev tun\r\nproto udp #- protocol\r\nremote 123.123.123.123 1194 #- SERVER IP and OPENVPN Port\r\nresolv-retry infinite\r\nnobind\r\ntun-mtu 1500\r\ntun-mtu-extra 32\r\nmssfix 1450\r\npersist-key\r\npersist-tun\r\nca ca.crt\r\nauth-user-pass\r\ncomp-lzo\r\nverb 3<\/pre>\n<\/div>\n<p>save with <strong>anyname.ovpn<\/strong> or <strong>1194.ovpn<\/strong><\/p>\n<p><a href=\"http:\/\/i56.tinypic.com\/aktvet.jpg\" target=\"_blank\">http:\/\/i56.tinypic.com\/aktvet.jpg<\/a><\/p>\n<p>Run OPENVPN Client on your Windows, connect with your username and password.<\/p>\n<p><a href=\"http:\/\/i55.tinypic.com\/2vwz9di.jpg\" target=\"_blank\">http:\/\/i55.tinypic.com\/2vwz9di.jpg<\/a><br \/>\n<a href=\"http:\/\/i53.tinypic.com\/2883y0y.jpg\" target=\"_blank\">http:\/\/i53.tinypic.com\/2883y0y.jpg<\/a><\/p>\n<p>Check your IP Address in browser and Voila!!! You&#8217;re IP is now changed to your server IP<\/p>\n<p><strong><span style=\"text-decoration: underline;\">note:<\/span><\/strong><br \/>\n&#8211; Never fails make OPENVPN on CentOS with this tutorial<br \/>\n&#8211; Those configurations above are basic configuration, you can check OPENVPN website for another configuration<br \/>\n&#8211; If you&#8217;re using Win 7, before installing OPENVPN client, right click  on the installer, properties, run as administrator and change  compatibility to Windows XP SP3<br \/>\n&#8211; If you wanna add another port, maybe TCP so you can run OPENVPN over  proxy, just create new configuration for server, adjust the following  lines:<\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\"><strong>port:<\/strong> your preferred port\r\n<strong>protocol:<\/strong> tcp or udp\r\n<strong>client's ip:<\/strong> 1.2.4.0 or 1.2.5.0 ; 1.2.6.0 ; and so on<\/pre>\n<\/div>\n<p>also new configuration for client<\/p>\n<div>\n<div>Code:<\/div>\n<pre dir=\"ltr\"><strong>proto xxxx<\/strong> #- change xxxx to tcp or udp\r\n<strong>remote 123.123.123.123 yyyy<\/strong> #- change yyyy to OPENVPN port<\/pre>\n<\/div>\n<p>and then run the command<br \/>\n<span style=\"color: red;\">#iptables -t nat -A POSTROUTING -s 1.2.4.0\/24 -j SNAT &#8211;to 123.123.123.123<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First thing you have to do is check whether tun\/tap is active or not by typing #cat \/dev\/net\/tun Code: cat: \/dev\/net\/tun: File descriptor in bad state take a look at the status above, &#8220;File descriptor in bad state&#8221; means tun\/tap is active, otherwise please ask your provider to activate it Install required modules #yum install &hellip; <a href=\"https:\/\/linuxmaster.in\/?p=169\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;OPENVPN ON CENTOS SERVER&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=169"}],"version-history":[{"count":2,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxmaster.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}