{"id":575,"date":"2014-09-25T21:40:36","date_gmt":"2014-09-26T04:40:36","guid":{"rendered":"http:\/\/blt.homenet.org\/wordpress\/?p=575"},"modified":"2014-09-25T21:40:36","modified_gmt":"2014-09-26T04:40:36","slug":"vpn-server-setup-on-ubuntu","status":"publish","type":"post","link":"https:\/\/bt.beerprojects.com\/wordpress\/?p=575","title":{"rendered":"VPN Server Setup on Ubuntu"},"content":{"rendered":"<p>Below is an unfinished post as I eventually gave up as I could not get bridging (tap) to work. \u00a0Instead I resorted to going back to Windows 7 and discuss it more <a title=\"Media Center: Giving up on Ubuntu, going to Windows 7\" href=\"http:\/\/bt.beerprojects.com\/wordpress\/?p=1227\">here<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>My latest adventure in setting up my media server is to get a VPN server going so that I can watch my movies outside of my home network without opening up my dlna ports to the world. After reading about VPN servers it was pretty clear that OpenVPN is the preferred method due to its strength over PPTP and L2TP. \u00a0However, with the issues that I ran into with installing and getting OpenVPN up and running it seems the simplicity of PPTP is attractive. \u00a0I just have to keep telling myself that this is a one time setup. Once I decided that I&#8217;d go with OpenVPN I got swirled around for a while before I discovered the <a title=\"OpenVpn\" href=\"http:\/\/openvpn.net\/\" target=\"_blank\">http:\/\/openvpn.net\/<\/a> website hosts the Open Source Project version, called the Community OpenVPN, and a commercial not-free version, called VPN Solution. \u00a0Prior to\u00a0knowing\u00a0this it seemed the VPN solution was the way to go. \u00a0I installed it and was working with the configurations when I noticed that I was only allowed 2 licnesnes and was required to buy more if needed. \u00a0From what I say the VPN solution had a nice web interface, but I want to use the Open Source Project version and not me limited to 2 licenses or have to make a purchase.<\/p>\n<h2>Installing OpenVPN<\/h2>\n<p>At first it seemed that this might be straight forward as there are two applications through quantal universe packages that appeared to do want I wanted:<a title=\"Network Mangaer OpenVPN\" href=\"https:\/\/help.ubuntu.com\/community\/NetworkManager\" target=\"_blank\"> openvpn and network-manager-openvpn<\/a>. \u00a0After installing these with an &#8216;apt-get install&#8217; I discovered that this is for maintaining the client side of OpenVPN. It turns out that most blogs, forums, how-tos are about setting up the client and very few are about setting up a OpenVPN server (maybe this will help someone in the future) So onto the Community OpenVpn.net site about getting a OpenVPN server up and running. \u00a0 Well the How-To documentations makes installing OpenVPN to be pretty easy:<\/p>\n<ol>\n<li>Download the <a title=\"OpenVPN Downloads\" href=\"http:\/\/openvpn.net\/index.php\/open-source\/downloads.html\" target=\"_blank\">tarball<\/a><\/li>\n<li>Expand the .tar.gz file: \u00a0 \u00a0<strong style=\"font-size: 15px;\">tar xfz openvpn-[version].tar.gz<\/strong><\/li>\n<li>cd to the top-level directory<\/li>\n<li>And type:<\/li>\n<\/ol>\n<blockquote>\n<pre><strong>.\/configure\r\nmake\r\nmake install<\/strong><\/pre>\n<\/blockquote>\n<p>Getting and opening the tarball is easy, but I ran into several issues with the .\/configure First issue was<\/p>\n<pre>error:\u00a0configure: error: ssl is required but missing<\/pre>\n<p>After several Google searches I found <a title=\"OpenSSL Issue\" href=\"http:\/\/www.linuxquestions.org\/questions\/linux-software-2\/openssl-crypto-headers-not-found-204489\/\" target=\"_blank\">this forumn post<\/a> which informed me to run:<\/p>\n<p style=\"padding-left: 30px;\"><strong>apt-get install libcurl4-openssl-dev<\/strong><\/p>\n<p>\u00a0Second issue was<\/p>\n<pre>configure: error: lzo enabled but missing<\/pre>\n<p>A few more Google searches directed me to the LZO download page,\u00a0<a title=\"LZO download page\" href=\"http:\/\/www.oberhumer.com\/opensource\/lzo\/download\/\" target=\"_blank\">http:\/\/www.oberhumer.com\/opensource\/lzo\/download\/<\/a>, \u00a0where I downloaded latest version 2.06. \u00a0I dide the untar, configure, make, and make istall with no issues. \u00a0I don&#8217;t know if the original files are needed after the isntall so I moved the untar&#8217;d version to \/sbin\/lzo* just in case. The third issue was<\/p>\n<pre>configure: error: libpam required but missing<\/pre>\n<p>Again more Google searches which lead me to install a libpam version: <strong>apt-get install libpam0g-dev<\/strong> Well after 3 issues the .\/configure worked, followed by the make and the make install.<\/p>\n<h2>\u00a0Installing Easy-RSA<\/h2>\n<p>The <a title=\"How-To Easy-RSA\" href=\"http:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html#pki\" target=\"_blank\">How-TO documentation<\/a> then directs me to use the Easy-RSA for creating certificates. <a title=\"Easy-RSA wiki\" href=\"https:\/\/wiki.archlinux.org\/index.php\/Create_a_Public_Key_Infrastructure_Using_the_easy-rsa_Scripts\" target=\"_blank\">This site<\/a> also has some good directions about using Easy-RSA. \u00a0 The fun part about this as it doesn&#8217;t really go into how to get Easy-RSA. \u00a0 \u00a0Easy-RSA is in a git hub, so by <a title=\"Git directions\" href=\"http:\/\/git-scm.com\/book\/en\/Getting-Started-Installing-Git\" target=\"_blank\">following the directions from a nice document<\/a> I started to installing Git:\u00a0<strong>apt-get install git\u00a0<\/strong>and then doing the<a title=\"First Time Git Setup\" href=\"http:\/\/git-scm.com\/book\/en\/Getting-Started-First-Time-Git-Setup\" target=\"_blank\"> directions for a first time install<\/a>. Now it is time to get the easy-rsa files. \u00a0I went to the \/usr\/share directory and then typed <strong>sudo git clone https:\/\/github.com\/OpenVPN\/easy-rsa.git<\/strong> (Note after doing all of the above, I later realized that the OpenVPN installation placed Easy-RSA in the \/usr\/share\/doc\/openvpn\/examples folder.) \u00a0From reading the configure.ac file it seems that a program called autoconf is needed. \u00a0So I setout to get that going with <strong>apt-get install autoconf\u00a0<\/strong>but after more poking around I think everything is ready to go in the easy-rsa\/2.0 folder. \u00a0At the command prompt I followed the directions and typed:<\/p>\n<p style=\"padding-left: 30px;\"><strong>. .\/vars<\/strong><\/p>\n<pre>\/usr\/share\/easy-rsa\/easy-rsa\/2.0$ . .\/vars\r\nNOTE: If you run .\/clean-all, I will be doing a rm -rf on \/usr\/share\/easy-rsa\/easy-rsa\/2.0\/keys<\/pre>\n<p style=\"padding-left: 30px;\"><strong>.\/clean-all<\/strong><\/p>\n<pre>\/usr\/share\/easy-rsa\/easy-rsa\/2.0$ .\/clean-all\r\nmkdir: cannot create directory `\/usr\/share\/easy-rsa\/easy-rsa\/2.0\/keys': Permission denied\r\n\/usr\/share\/easy-rsa\/easy-rsa\/2.0$ sudo .\/clean-all\r\nPlease source the vars script first (i.e. \"source .\/vars\")<\/pre>\n<p>It took me quite some time to figure out why I was running into this error. \u00a0I read through the vars and clean-all files and everything seemed good. \u00a0In the end the error is a pretty basic one, the\u00a0permissions\u00a0were wrong. \u00a0When I used the &#8216;git source&#8217; \u00a0the folder permissions belonged to root as 755. \u00a0With a <strong>sudo chmod 777 -R easy-rsa<\/strong> the permissions were fixed and the scripts worked as advertised<\/p>\n<h3>Server certificates and keys<\/h3>\n<p style=\"padding-left: 30px;\"><strong>.\/build-ca<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>.\/build-key-server server<\/strong><\/p>\n<p>When you run the build scripts the fields are pre-populated with the information edited from the vars file. \u00a0Simply press enter through the prompts.<\/p>\n<h3>Client certificates and keys<\/h3>\n<p>The directions then go to create client keys with the\u00a0<strong>.\/build-key<\/strong>. \u00a0I&#8217;m a fan of of password protecting the client keys so I used the <strong>.\/build-key-pass\u00a0<\/strong>script to create my keys<\/p>\n<h3>Other items<\/h3>\n<p>I&#8217;m not too sure what these do and didn&#8217;t spend the time researching it, I simply ran them. I created then\u00a0<a href=\"http:\/\/www.rsasecurity.com\/rsalabs\/node.asp?id=2248\">Diffie Hellman<\/a>\u00a0parameters with:<\/p>\n<p style=\"padding-left: 30px;\">\u00a0<strong style=\"font-size: 15px;\">.\/build-dh\u00a0<\/strong><\/p>\n<p>From the <a title=\"HMAC  link\" href=\"https:\/\/wiki.archlinux.org\/index.php\/Create_a_Public_Key_Infrastructure_Using_the_easy-rsa_Scripts\" target=\"_blank\">wiki site<\/a> and the <a title=\"Hardening OpenVPN Security\" href=\"http:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html#security\" target=\"_blank\">Hardening OpenVPN Security<\/a> section I created the HMAC \u00a0with<\/p>\n<p style=\"padding-left: 30px;\"><strong>openvpn &#8211;genkey &#8211;secret \/keys\/ta.key<\/strong><\/p>\n<h2>\u00a0Configuring OpenVPN Server<\/h2>\n<p>The How-TO directions continue with setting up the configuration files. \u00a0The documentation does not provide any directions where all these files should go, but after poking around the openvpn.init file in the sample scripts (\/usr\/share\/doc\/openvpn\/examples\/sample-scripts) the script will look for the configuration files in the \/etc\/openvpn\/ folder. I started with the sample server.conf and made changes as needed. \u00a0I changed the following:<\/p>\n<ul>\n<li><span style=\"line-height: 16px;\">For the ca, cert, key, and dh lines I added the full path name \/etc\/openvpn\/server_keys\/ as recommended in the wiki \u00a0<\/span><span style=\"line-height: 16px;\">. Additionally for these files, I did the following:<\/span><\/li>\n<li>\n<ul>\n<li><span style=\"line-height: 16px;\">created a server_keys folder to keep the folders organized.<\/span><\/li>\n<li><span style=\"line-height: 16px;\"><span style=\"line-height: 24px;\">changed the permissions on the files so that they can be moved.<\/span>moved all the keys, certs, etc files with exception to the client files and the ca.key file to this folder<\/span>\n<ul>\n<li>The client files went to another location to be shared as needed<\/li>\n<li><em id=\"__mceDel\">The ca.key file went to a different computer as recommended<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Uncommented the client-t0-client line to allow my VPN clients<\/li>\n<li>Uncommented the HMAC line, tls-auth, and changed the path to the server_keys folder<\/li>\n<li>Changed the crpytographic\u00a0cipher\u00a0to, cipher AES-256-CBC, rather than any of the 3 listed options in the file for stronger security. \u00a0I&#8217;ve also read that this has little impact to the throughout of the VPN network too.<\/li>\n<li>Enabled and changed the max clients to 10. \u00a0This is for a small home network and really 10 is too much too.<\/li>\n<li>Enabled &#8216;user nobody&#8217; and &#8216;group nogroup&#8217; lines. \u00a0Note the example file has nogroup rather than nobody as noted in the How-to and wiki for the group option.<\/li>\n<li><em id=\"__mceDel\">Enabled log-append. \u00a0I don&#8217;t expect too many logons so this file shouldn&#8217;t grow to a massive size.<\/em><\/li>\n<li>TODO: write about lof file and other permission erorrs\n<ul>\n<li>created a log folder and changed the log paths to point to it as I was getting an error<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">:\/usr\/sbin$ openvpn &#8211;config \/etc\/openvpn\/server.conf<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Tue Mar 19 14:02:02 2013 Warning: Error redirecting stdout\/stderr to &#8211;log file: openvpn.log: Permission denied (errno=13)<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Options error: &#8211;dh fails with &#8216;\/etc\/openvpn\/server_keys\/dh1024.pem&#8217;: No such file or directory<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Options error: &#8211;ca fails with &#8216;\/etc\/openvpn\/server_keys2\/ca.crt&#8217;: No such file or directory<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Options error: &#8211;key fails with &#8216;\/etc\/openvpn\/server_keys\/M1730_server.key&#8217;: Permission denied<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Options error: &#8211;status fails with &#8216;openvpn-status.log&#8217;: Permission denied<\/span><span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 15px; line-height: 21px;\">Options error: Please correct these errors.<\/span><\/p>\n<p><span style=\"font-size: medium;\"><span style=\"line-height: 24px;\">Next I made copied the client.conf file from the examples and made the changes below. \u00a0The wiki seemed pretty clear for this, but once I started into it I realized that the file is specific to each client crt\/key combo. \u00a0Since I made several client keys during the Easy-RSA section I had to create a client.conf file for each client key combo and then named the file appropriately.<\/span><\/span><\/p>\n<ul>\n<li><span style=\"line-height: 16px;\">created a client_keys folder to keep the folders organized.<\/span>\n<ul>\n<li>note the ca.crt and ta.key files are shared and I left them in the server_keys folder<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"line-height: 16px;\">update the &#8216;remote&#8217; line for my specific IP address and ports<\/span><\/li>\n<li>Enable the user and group lines. \u00a0Again the group has the nogroup option rather than the nobody.<\/li>\n<li>Enabled the &#8216;mute-replay-warnings&#8217; as I plan to use the VPN for laptops and my android phone<\/li>\n<li>Updated the ca, cert, key, and tls-auth lines to point to the files. \u00a0Again I used the full filepath \/etc\/openvpn\/client_keys\/ as suggested by the wiki<\/li>\n<li>Changed the crpytographic\u00a0cipher\u00a0to, cipher AES-256-CBC<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Other Things<\/h2>\n<p>My VPN server is behind a router that uses dd-wrt. \u00a0In order to expose the VPN ports to the world I went to the NAT\/QoS -&gt; Port Forwards tab and added my VPN server to the list of port forwards. \u00a0I also have the VPN server set to have a static IP address which is configured on Services -&gt; Services tab.<\/p>\n<p>&nbsp;<\/p>\n<p>Running and Troubleshooting<\/p>\n<p>&nbsp;<\/p>\n<pre>ERROR: Cannot ioctl TUNSETIFF tun: Operation not permitted (errno=1)<\/pre>\n<p>run to fix permission problem: sudo openvpn &#8211;config \/etc\/openvpn\/server.conf<\/p>\n<p>&nbsp;<\/p>\n<p>OpenVPN on Android<\/p>\n<p>One thing I want to be able to do is get to my home network from my phone, <a title=\"New phone, Samsung Note 2, and already rooted\" href=\"http:\/\/bt.beerprojects.com\/wordpress\/?p=561\" target=\"_blank\">Samsung Note 2<\/a>, so I used OpenVPN on Android for my VPN client. \u00a0The setup is pretty straight foward. \u00a0The only catch that I found was that:<\/p>\n<ul>\n<li>Select &#8216;Certificates&#8217; for the type in the &#8216;Basic tab<\/li>\n<li>For each file selected tap on it then tap the &#8216;select&#8217; button at the bottom<\/li>\n<li>For the\u00a0Encryption\u00a0cipher I had to use all lower case (my phone\u00a0capitalized\u00a0the first character) for &#8216;aes-256-cbc&#8217;.<\/li>\n<li>Change the TLS Authentication direction to 1, rather than the default of no direction<\/li>\n<\/ul>\n<pre>Authenticate\/Decrypt packet error: packet HMAC authentication failed\r\nTue Mar 19 15:53:51 2013 us=248361 TLS Error: incoming packet authentication failed from [AF_INET]192.168.1.99:63090<\/pre>\n<p>check to see if openvpn is running (change port # as needed)<\/p>\n<p>&nbsp;<\/p>\n<h3>Other links and tools that I was using<\/h3>\n<p>#netstat -ltnup | grep 1194<\/p>\n<p>&nbsp;<\/p>\n<p>samba shares not seen. \u00a0Added IP address to interfaces line in \/etc\/samba\/smb.conf file per\u00a0http:\/\/serverfault.com\/questions\/137933\/howto-access-samba-share-over-vpn-tunnel<\/p>\n<p>https:\/\/help.ubuntu.com\/10.04\/serverguide\/openvpn.html \u00a0 OpenVPN for Andriod https:\/\/play.google.com\/store\/apps\/details?id=de.blinkt.openvpn&amp;hl=en http:\/\/openvpn.net\/index.php\/open-source\/documentation\/howto.html#install<\/p>\n<p>&nbsp;<\/p>\n<h2>Bridge setup (Never got this to work)<\/h2>\n<p>get the openvpn bridge scripts from the sample-scripts folder<\/p>\n<p>modify the bridge-start script<\/p>\n<p>in the command prompt type ifconfig and get the information of the IP, netmask, and broadcast addresses<\/p>\n<p>change the \/etc\/interfaces file to add<\/p>\n<blockquote>\n<pre><strong>iptables -A INPUT -i tap0 -j ACCEPT\r\niptables -A INPUT -i br0 -j ACCEPT\r\niptables -A FORWARD -i br0 -j ACCEPT<\/strong><\/pre>\n<\/blockquote>\n<p>create a symboloc link to creat the bridge at startup before openvpn<\/p>\n<p>\/etc\/rc0.d$ sudo ln -s \/etc\/openvpn\/bridge-start K79openvpn-bridge<\/p>\n<p>create a symbolic link to remove the bridge at shutdown<\/p>\n<p>\/etc\/rc6.d$ sudo ln -s \/etc\/openvpn\/bridge-stop K99openvpn-bridge<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below is an unfinished post as I eventually gave up as I could not get bridging (tap) to work. \u00a0Instead I resorted to going back to Windows 7 and discuss it more here &nbsp; My latest adventure in setting up my media server is to get a VPN server going so that I can watch [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[115,116,111,110,109,108,105,106,107,65,104],"class_list":["post-575","post","type-post","status-publish","format-standard","hentry","category-tech-talk","tag-bridge","tag-bridging","tag-easy-rsa","tag-error-libpam-required-but-missing","tag-error-lzo-enabled-but-missing","tag-error-ssl-is-required-but-missing","tag-openvpn","tag-openvpn-server","tag-server","tag-ubuntu","tag-vpn"],"_links":{"self":[{"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=575"}],"version-history":[{"count":14,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":1234,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/575\/revisions\/1234"}],"wp:attachment":[{"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bt.beerprojects.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}