How to Install OpenVPN on VPS
OpenVPN is one of the most popular VPN solutions out there, known for its security and reliability. If you have a VPS (Virtual Private Server) and want to set up your own VPN with OpenVPN, this guide will walk you through the installation process.
Step 1: Update and Install Necessary Packages
Before installing OpenVPN, make sure your VPS is up to date by running the following commands:
sudo apt update
sudo apt upgrade
Next, install the necessary packages for OpenVPN:
sudo apt install openvpn openssl
Step 2: Configure OpenVPN
After installing OpenVPN, you need to set up the configuration files. Start by copying the sample configuration file:
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
sudo gzip -d /etc/openvpn/server.conf.gz
Edit the configuration file with your server information:
sudo nano /etc/openvpn/server.conf
Once you have configured the file, start the OpenVPN service:
sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server
Step 3: Generate Certificates
To secure your OpenVPN server, you need to generate certificates. Run the following command to create the necessary keys:
/usr/share/easy-rsa/easyrsa init-pki
/usr/share/easy-rsa/easyrsa build-ca
/usr/share/easy-rsa/easyrsa gen-req server nopass
/usr/share/easy-rsa/easyrsa sign-req server server
Step 4: Configure Firewall Rules
Make sure to allow traffic to flow through the OpenVPN server by setting up firewall rules:
sudo iptables -A INPUT -i tun0 -j ACCEPT
sudo iptables -A FORWARD -i tun0 -j ACCEPT
sudo iptables -A FORWARD -o tun0 -j ACCEPT
sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
Don’t forget to save your firewall rules to make them persistent:
sudo iptables-save > /etc/iptables/rules.v4
Step 5: Connect to OpenVPN
Lastly, connect to your OpenVPN server using a client application. You can download the OpenVPN client for your operating system from the official website. Import the client configuration file and connect to your server.
That’s it! You now have your own OpenVPN server running on your VPS. Enjoy secure and private internet browsing.