The easiest way to install openvpn on an ubuntu based server

This is a tutorial on how to setup an OpenVPN Server on Ubuntu Linux version 14.04 or 16.04 LTS server to shield my browsing activity from bad guys on public Wi-Fi, and more?

OpenVPN is a full-featured SSL VPN (virtual private network). It implements OSI layer 2 or 3 secure network extension using the SSL/TLS protocol. It is an open source software and distributed under the GNU GPL. A VPN allows you to connect securely to an insecure public network such as wifi network at the airport or hotel. VPN is also required to access your corporate or enterprise or home server resources. You can bypass geo-blocked site and increase your privacy or safety online.


The steps are as follows:

  • Find and note down your public IP address
  • Download openvpn-install.sh script
  • Run openvpn-install.sh to install OpenVPN server
  • Connect an OpenVPN server using IOS/Android/Linux/Windows client
  • Verify your connectivity


Find your public IP address

$ ip addr show eth0


Or use the host command or dig command as follows:

$ host myip.opendns.com resolver1.opendns.com


$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com


Download openvpn-install.sh script


Type the following command:


$ wget https://git.io/vpn -O openvpn-install.sh


Run openvpn-install.sh to install OpenVPN server

sudo bash openvpn-install.sh


When prompted set IP address to your public IP you found above and Port to 1194. Use Google or OpenDNS DNS servers with the vpn. Next, type client name (such as iPhone, Nexus6, LinuxRouter etc). Finally, press [Enter] key to install and setup OpenVPN on your system:


That is all. Your OpenVPN server has been configured and ready to use. You can see added firewall rules /etc/rc.local file:


iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -I FORWARD -s -j ACCEPT
iptables -I INPUT -p udp --dport 1194 -j ACCEPT
iptables -t nat -A POSTROUTING -s -j SNAT --to youriphere


You can view your openvpn server config file generated by the script as follows (do not edit this file by hand):

$ sudo more /etc/openvpn/server.conf
$ sudo vi /etc/openvpn/server.conf


How do I start/stop/restart OpenVPN server on Ubuntu Linux 16.04 LTS?


Type the following command stop the OpenVPN service:

$ sudo systemctl stop openvpn@server

Type the following command start the OpenVPN service:

$ sudo systemctl start openvpn@server

Type the following command restart the OpenVPN service:

$ sudo systemctl restart openvpn@server

About the author


Code is Poetry

Add Comment

Click here to post a comment