{"id":151,"date":"2020-03-11T18:04:11","date_gmt":"2020-03-11T15:04:11","guid":{"rendered":"http:\/\/blog.gunlerveisler.gen.tr\/?p=151"},"modified":"2021-11-06T00:43:59","modified_gmt":"2021-11-05T21:43:59","slug":"openvpn-community-edition-server-ubuntu-18-04-setup-notes","status":"publish","type":"post","link":"https:\/\/aliyargunes.com.tr\/blog\/openvpn-community-edition-server-ubuntu-18-04-setup-notes\/","title":{"rendered":"OpenVPN Community Edition Server Setup Notes"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft size-thumbnail\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/ovpn-150x150.png\" alt=\"\" class=\"wp-image-529\"\/><\/figure><\/div>\n\n\n\n<p>Recently I setup an OpenVPN server on my remote Ubuntu Server (18.04) for all my internet traffic. After completing all the steps, I have done some extras for both of the client and server side machines. Also, my wifi access point-router needs an adjustment for handling TLS handshaking process. <\/p>\n\n\n\n<p>First things first I  have enabled and assigned the <em>floating-ip<\/em> to the droplet and setup the server like <a rel=\"noreferrer noopener\" aria-label=\"this (opens in a new tab)\" href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/initial-server-setup-with-ubuntu-18-04\" target=\"_blank\">this<\/a>. Then, I have found my <code>anchor-ip<\/code> with <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s http:\/\/169.254.169.254\/metadata\/v1\/interfaces\/public\/0\/anchor_ipv4\/address\n<\/pre><\/div>\n\n\n<p>I have added <code>local anchor-ip<\/code> to <em><code>server.conf<\/code><\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo nano \/etc\/openvpn\/server.conf\n<\/pre><\/div>\n\n\n<p>I added following rules for Ubuntu&#8217;s firewall and postrouting:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo iptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -j SNAT --to-source anchor-ip\nsudo iptables -A INPUT -i eth0 -p udp -m state --state NEW -m udp --dport 1194 -j ACCEPT\nsudo iptables -A INPUT -i tun+ -j ACCEPT\nsudo iptables -A OUTPUT -o tun+ -j ACCEPT\n<\/pre><\/div>\n\n\n<p>Then I need to save the rules, because they were not persistent and will remove after reboot. Iptables-persistent is nice tool for this. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt install iptables-persistent netfilter-persistent\n<\/pre><\/div>\n\n\n<p>The two packages are similar, but provide slightly different functionality. If you only install iptables-persistent, you won&#8217;t get the service definition file for correct handling in systemd, eg \/lib\/systemd\/system\/netfilter-persistent.service. If you only install netfilter-persistent, you will find that rules are not correctly applied at boot.<\/p>\n\n\n\n<p>Rules can be saved in a file with the (root) command <code>iptables-save<\/code> for IPv4:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\niptables-save &gt; \/etc\/iptables\/rules.v4\n<\/pre><\/div>\n\n\n<p> These files can be loaded again with the command&nbsp;<code>iptables-restore<\/code>&nbsp;for IPv4. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\niptables-restore &lt; \/etc\/iptables\/rules.v4\n<\/pre><\/div>\n\n\n<p>Recent versions of iptables-persistent have two configuration files:  <code>\/etc\/iptables\/rules.v4 <\/code>for the IPv4 ruleset, and <code>\/etc\/iptables\/rules.v6<\/code> for the IPv6 ruleset. <\/p>\n\n\n\n<p>Here is my IPv4 file:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"386\" src=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/iptables-persistent.png\" alt=\"\" class=\"wp-image-528\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/iptables-persistent.png 616w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/iptables-persistent-300x188.png 300w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<p>To save all filter rules:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnetfilter-persistent save\n<\/pre><\/div>\n\n\n<!--more-->\n\n\n\n<p>or to load them:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnetfilter-persistent start\n<\/pre><\/div>\n\n\n<p>Here is my server route table:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"160\" src=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/route1.jpg\" alt=\"\" class=\"wp-image-532\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/route1.jpg 624w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/route1-300x77.jpg 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p>tun0: my virtual VPN networkcard \/ eth0: normal networkcard \/ 10.8.0.0: my VPN network ip block.<\/p>\n\n\n\n<p>I have restarted OpenVPN with <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo systemctl restart openvpn@server\n<\/pre><\/div>\n\n\n<p>I have updated in my local <em>user.ovpn<\/em> the ip of the <code>floating-ip<\/code> (replacing the line remote with <code>remote floating-ip 1194<\/code>)<\/p>\n\n\n\n<p>After this I added following rules for OpenVPN to the digitalocean&#8217;s droplet firewall panel, then I add this ruleset to my droplet. Here is port informations for OpenVPN: <\/p>\n\n\n\n<p>UDP ports: 1194, 1197, 1198, 8080, 9201 and 53. <\/p>\n\n\n\n<p>TCP ports 502, 501, 443, 110, and 80.<\/p>\n\n\n\n<p>At this point I can not connect OpenVPN GUI from my Windows 10 client on my Wifi router, because of the MTU size setting on the TCP packet in the router. The size was set to 1452 bytes instead of 1492 bytes. Because of that the SSL\/TLS packet was fragmented and the server ACK was not received. On changing the MTU size, everything works perfectly. Also, I disabled the Windows 10 firewall for TAP device.<\/p>\n\n\n\n<p> If I run <code>netstat -anr<\/code> and <code>netstat -ltnup | grep 1194<\/code> everything seems fine. Also if I run <code>curl --interface anchor-ip https:\/\/api.ipify.org\/<\/code> or <code>wget --bind-address=anchor-ip https:\/\/api.ipify.org\/<\/code> I get the correct (floating) ip.  <\/p>\n\n\n\n<p>Here is my Windows 10 (TAP) client configuration (.OVPN file):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nblock-outside-dns\nauth-nocache\nkey-direction 1\nclient\ndev tun\nproto udp\nremote \/\/my floating-ip\/\/ 1194\nresolv-retry infinite\nnobind\npersist-key\npersist-tun\nca ca.crt\ncert client.crt\nkey client.key\nremote-cert-tls server\ntls-auth ta.key 1\nauth SHA256\ncipher AES-256-CBC\nverb 3\n<\/pre><\/div>\n\n\n<p>Here is my Ubuntu Server 18.04 LTS <code>\/etc\/openvpn\/server.conf<\/code> file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nkey-direction 0\nlocal \/\/my-anchor-ip\/\/\nport 1194\nproto udp\ndev tun\nca ca.crt\ncert server.crt\nkey server.key\ndh dh.pem\ntopology subnet\nserver 10.8.0.0 255.255.255.0\nifconfig-pool-persist \/var\/log\/openvpn\/ipp.txt\npush &quot;route 0.0.0.0 0.0.0.0&quot;\npush &quot;redirect-gateway def1&quot;\npush &quot;dhcp-option DNS 8.8.8.8&quot;\nkeepalive 10 120\ntls-auth ta.key 0\ncipher AES-256-CBC\nauth SHA256\nuser nobody\ngroup nogroup\npersist-key\npersist-tun\nstatus \/var\/log\/openvpn\/openvpn-status.log\nverb 3\nexplicit-exit-notify 1\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-medium is-resized\"><a href=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/redirect.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/redirect-300x253.png\" alt=\"\" class=\"wp-image-530\" width=\"300\" height=\"253\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/redirect-300x253.png 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/redirect-768x649.png 768w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/03\/redirect.png 1017w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption> Troubleshooting flowchart for using the internet over VPN <\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Recently I setup an OpenVPN server on my remote Ubuntu Server (18.04) for all my internet traffic. After completing all the steps, I have done some extras for both of the client and server side machines. Also, my wifi access &hellip; <a href=\"https:\/\/aliyargunes.com.tr\/blog\/openvpn-community-edition-server-ubuntu-18-04-setup-notes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[2],"tags":[46,62,63,65],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-days","tag-openvpn","tag-ubuntu","tag-ubuntu-vpn-server","tag-vpn"],"_links":{"self":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/151"}],"collection":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":8,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":799,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions\/799"}],"wp:attachment":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}