We continue previous post about creation of site to site vpn between multiple branch offices and central office of company. How to create site to site VPN for SMB with low IT budget. part1 How to setup OpenVPN server on debian? part2 How to create site to site vpn from pfsense to openvpn server.part3 Install latest Debian Linux (better from network installer). During the installation choose: ssh server std system utilities Configure IP address for the server. For example nano /etc/network/interfaces: iface eth0 inet static  <span><a href="https://www.itforce.mn/index.php/2017/07/22/how-to-setup-openvpn-server-on-debian/" class="readmore">Continue reading &rarr;</a></span>{"id":834,"date":"2017-07-22T18:05:06","date_gmt":"2017-07-22T10:05:06","guid":{"rendered":"https:\/\/www.itforce.mn\/?p=834"},"modified":"2017-07-23T14:08:10","modified_gmt":"2017-07-23T06:08:10","slug":"how-to-setup-openvpn-server-on-debian","status":"publish","type":"post","link":"https:\/\/www.itforce.mn\/index.php\/2017\/07\/22\/how-to-setup-openvpn-server-on-debian\/","title":{"rendered":"How to setup OpenVPN server on debian? part2"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-877\" src=\"http:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2.jpg\" alt=\"\" width=\"2362\" height=\"827\" srcset=\"https:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2.jpg 2362w, https:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2-300x105.jpg 300w, https:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2-768x269.jpg 768w, https:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2-1024x359.jpg 1024w, https:\/\/www.itforce.mn\/wp-content\/uploads\/2017\/07\/secure-access2-624x218.jpg 624w\" sizes=\"auto, (max-width: 2362px) 100vw, 2362px\" \/><\/p>\n<p>We continue <a href=\"http:\/\/www.itforce.mn\/index.php\/2017\/07\/19\/how-to-create-site-to-site-vpn-for-smb-with-low-it-budget\/\">previous post about creation of site to site vpn between multiple branch offices and central office of company<\/a>.<\/p>\n<ul>\n<li><a href=\"http:\/\/www.itforce.mn\/index.php\/2017\/07\/19\/how-to-create-site-to-site-vpn-for-smb-with-low-it-budget\/\">How to create site to site VPN for SMB with low IT budget. part1<\/a><\/li>\n<li><a href=\"http:\/\/www.itforce.mn\/index.php\/2017\/07\/22\/how-to-setup-openvpn-server-on-debian\/\">How to setup OpenVPN server on debian? part2<\/a><\/li>\n<li><a href=\"http:\/\/www.itforce.mn\/index.php\/2017\/07\/22\/how-to-create-site-to-site-vpn-from-pfsense-to-openvpn-server\/\">How to create site to site vpn from pfsense to openvpn server.part3<\/a><\/li>\n<\/ul>\n<ol>\n<li>Install latest Debian Linux (better from network installer). During the installation choose:\n<ul>\n<li>ssh server<\/li>\n<li>std system utilities<\/li>\n<\/ul>\n<\/li>\n<li>Configure IP address for the server. For example nano \/etc\/network\/interfaces:<\/li>\n<\/ol>\n<pre style=\"padding-left: 60px;\">iface eth0 inet static\r\naddress 192.168.0.2 # it is considered that 192.168.0.1 is used as dgw in central office\r\ngateway 192.168.0.1\r\nnetmask 255.255.255.0\r\nnetwork 192.168.0.0\r\nbroadcast 192.168.0.255\r\n<\/pre>\n<ol start=\"3\">\n<li>Let&#8217;s putty\/ssh to 192.168.0.2, run under root:<\/li>\n<li><em><strong>apt-get update<\/strong><\/em><\/li>\n<li><strong><em>apt-get install openvpn (<\/em><\/strong>if easy-rsa has not installed by openvpn as a dependence<strong><em> apt-get install easy-rsa)<\/em><\/strong><\/li>\n<li><em><strong>cd \/etc\/openvpn\/easy-rsa\/<\/strong><\/em><\/li>\n<li><em><strong>nano vars<\/strong><\/em>, modify for example to:<\/li>\n<\/ol>\n<pre style=\"padding-left: 60px;\">export KEY_COUNTRY=\"MN\"\r\nexport KEY_PROVINCE=\"TUV\"\r\nexport KEY_CITY=\"UB\"\r\nexport KEY_ORG=\"ITFORCE LLC\"\r\nexport KEY_EMAIL=\"it@itforce.mn\"\r\nexport KEY_OU=\"IT\"\r\n# X509 Subject Field\r\nexport KEY_NAME=\"EasyRSA\"\r\n<\/pre>\n<ol start=\"8\">\n<li><em><strong>source .\/vars<\/strong><\/em><\/li>\n<li><em><strong>chmod +x vars<\/strong><\/em><\/li>\n<li><em><strong>.\/vars<\/strong><\/em><\/li>\n<li><em><strong>.\/clean-all<\/strong><\/em><\/li>\n<li><em><strong>.\/build-ca<\/strong><\/em>\u00a0 (it will read data from vars &#8211; just confirm above info, only for &#8220;common name&#8221; enter ITFORCE-CA; as a result inside \/etc\/openvpn\/easy-rsa\/keys you will get ca.key and ca.crt files &#8211; private key and certificate of your PKI CA)<\/li>\n<li><em><strong>.\/build-key-server server<\/strong><\/em> (the same, common name is &#8220;server&#8221;; get two new files in keys folder\u00a0 &#8211; server.key and server.crt) No need to enter password (optional)<\/li>\n<li><em><strong>.\/build-dh<\/strong><\/em><\/li>\n<li><em><strong>.\/build-key client01<\/strong><\/em> (one pair of certificate + key can be used for all branches, but better to generate for each branch own certificate+key &#8211; in case of compromise easier to change\/fix\/revoke) For common name &#8211; client01. As result &#8212; client01.key and client01.crt in keys folder<\/li>\n<li>Let&#8217;s consider that we have following subnets:<\/li>\n<\/ol>\n<p style=\"padding-left: 30px;\">central office and all branch offices have the same 192.168.0.0\/24<\/p>\n<p style=\"padding-left: 30px;\">We will later change thru pfsense all branch office subnets to:<\/p>\n<ul>\n<li>branch office 01 &#8211; 172.16.101.0\/24<\/li>\n<li>branch office 02 &#8211; 172.16.102.0\/24<\/li>\n<li>and so on<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\">For each branch we will create own tunnel, so port forward on your central office router:<\/p>\n<ul>\n<li>UDP 51191 to 192.168.0.2:51191<\/li>\n<li>UDP 51192 to 192.168.0.2:51192<\/li>\n<li>and so on<\/li>\n<\/ul>\n<ol start=\"17\">\n<li>Now we create for each branch own tun0x.conf:<\/li>\n<\/ol>\n<p style=\"padding-left: 30px;\">tun01.conf:<\/p>\n<pre style=\"padding-left: 30px;\">port 51191\r\nproto udp\r\ndev tun01\r\ntls-server\r\n\r\nifconfig 10.0.51.1 10.0.51.2\r\nroute 172.16.101.0 255.255.255.0\r\n\r\ndh \/etc\/openvpn\/easy-rsa\/keys\/dh2048.pem\r\nca \/etc\/openvpn\/easy-rsa\/keys\/ca.crt\r\ncert \/etc\/openvpn\/easy-rsa\/keys\/server.crt\r\nkey \/etc\/openvpn\/easy-rsa\/keys\/server.key\r\nreneg-sec 60\r\n\r\nkeepalive 10 120\r\ncomp-lzo\r\ncipher AES-256-CBC\r\npersist-key\r\npersist-tun\r\n\r\nverb 5\r\nstatus \/var\/log\/openvpn.log\r\n#log-append \/var\/log\/openvpn01 - enable it just for initial setup debugging\r\nuser nobody\r\ngroup nogroup\r\n<\/pre>\n<p style=\"padding-left: 30px;\">tun02.conf:<\/p>\n<pre style=\"padding-left: 30px;\">port 51192\r\nproto udp\r\ndev tun02\r\ntls-server\r\n\r\nifconfig 10.0.52.1 10.0.52.2\r\nroute 172.16.102.0 255.255.255.0\r\n\r\ndh \/etc\/openvpn\/easy-rsa\/keys\/dh2048.pem\r\nca \/etc\/openvpn\/easy-rsa\/keys\/ca.crt\r\ncert \/etc\/openvpn\/easy-rsa\/keys\/server.crt\r\nkey \/etc\/openvpn\/easy-rsa\/keys\/server.key\r\nreneg-sec 60\r\n\r\nkeepalive 10 120\r\ncomp-lzo\r\ncipher AES-256-CBC\r\npersist-key\r\npersist-tun\r\n\r\nverb 5\r\nstatus \/var\/log\/openvpn.log\r\n#log-append \/var\/log\/openvpn02 - enable it just for initial setup debugging\r\nuser nobody\r\ngroup nogroup\r\n<\/pre>\n<p style=\"padding-left: 30px;\">and so on<\/p>\n<p style=\"padding-left: 30px;\">10.0.5x.yy addresses are used only to create tunnels and never used directly.<\/p>\n<ol start=\"18\">\n<li>Place all tun0x.conf files into \/etc\/openvpn\/ folder. During start of openvpn service all these files will be read one by one. As result we will get new network interfaces &#8211; ifconfig will show not only lo and eth0, but also tun01, tun02 and so on.<\/li>\n<li>Very useful to\u00a0 uncomment #log-append \/var\/log\/openvpnxx for initial debugging how connections are established. But later better to disable logging &#8211; it consumes a lot of disk space.<\/li>\n<li>Enable Packet Forwarding\n<pre><em><strong>echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward<\/strong><\/em>\r\nto make this permanent :\r\n<em><strong>nano \/etc\/sysctl.conf<\/strong><\/em>\r\n# Uncomment the next line to enable packet forwarding for IPv4\r\n#net.ipv4.ip_forward=1<\/pre>\n<\/li>\n<li>restart server<\/li>\n<li>two options:\n<ol style=\"list-style-type: lower-alpha;\">\n<li>all network traffic will go thru new openvpn router &#8211; for this configure all central office network devices default gw as a 192.168.0.2 thru DHCP or manually. (in turn openvpn server[192.168.0.2] default gw is 192.168.0.1 to access Internet, so tracert to internet will show at first 192.168.0.2, then 192.168.0.1, then isp server ip and so on; tracert to branch01 computer &#8211; at first 192.168.0.2, 10.0.101.2, 172.16.101.xx)<\/li>\n<li>run on each central office server\/workstation which is needed to be connected from\/to branch offices\n<ol style=\"list-style-type: upper-roman;\">\n<li>&#8220;route add -p 172.16.101.0 mask 255.255.255.0 192.168.0.2&#8221;<\/li>\n<li>&#8220;route add -p 172.16.102.0 mask 255.255.255.0 192.168.0.2&#8221;<\/li>\n<li>and so on &#8212; to simplify and automate &#8211; you can create batch file and add it into central office AD site group policy as a computer startup script (site group policy, not default domain group policy &#8211; we don&#8217;t need to change routing tables in other sites)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.itforce.mn\/index.php\/2017\/07\/22\/how-to-create-site-to-site-vpn-from-pfsense-to-openvpn-server\/\">How to configure branch office pfsense<\/a><\/p>\n","protected":false},"excerpt":{"rendered":null,"protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,6,7],"tags":[],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-it-governance","category-smb","category-sysadmin-thoughts"],"_links":{"self":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/comments?post=834"}],"version-history":[{"count":45,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":919,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/834\/revisions\/919"}],"wp:attachment":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/media?parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/categories?post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/tags?post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}