Setting up a VPN on Ubuntu can be done in several ways, depending on whether you want to connect to a VPN service (like NordVPN, ProtonVPN, etc.) or host your own VPN server (e.g., using OpenVPN or WireGuard). Below are common methods: Most VPN providers offer Linux/Ubuntu support via:
- Official CLI apps (e.g., NordVPN, ProtonVPN)
- Network Manager GUI (for OpenVPN or WireGuard configs)
Method 1: Using Network Manager (GUI)
- Download VPN config files from your provider (usually
.ovpnfor OpenVPN or.conffor WireGuard). - OpenVPN Setup:
- Install OpenVPN:
sudo apt update && sudo apt install openvpn
- Import the
.ovpnfile:- Go to Settings > Network > VPN > Add VPN and select "Import from file."
- Install OpenVPN:
- WireGuard Setup:
- Install WireGuard:
sudo apt install wireguard
- Import the
.conffile similarly in Network Manager.
- Install WireGuard:
Method 2: Using Provider's CLI Tool
Example with ProtonVPN:
sudo apt install protonvpn-cli protonvpn-cli login protonvpn-cli connect
Hosting Your Own VPN Server
Option A: WireGuard (Fast & Modern)
-
Install WireGuard:
sudo apt install wireguard
-
Generate keys:
wg genkey | sudo tee /etc/wireguard/private.key sudo chmod 600 /etc/wireguard/private.key sudo cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
-
Create config (
/etc/wireguard/wg0.conf):[Interface] PrivateKey = <your_private_key> Address = 10.0.0.1/24 ListenPort = 51820 [Peer] PublicKey = <client_public_key> AllowedIPs = 10.0.0.2/32
-
Enable and start:
sudo systemctl enable --now wg-quick@wg0
Option B: OpenVPN (Traditional)
- Install OpenVPN and Easy-RSA:
sudo apt install openvpn easy-rsa
- Set up a CA and server certs:
make-cadir ~/openvpn-ca && cd ~/openvpn-ca source vars ./clean-all ./build-ca ./build-key-server server ./build-dh
- Copy configs:
sudo cp ~/openvpn-ca/keys/{server.crt,server.key,ca.crt,dh2048.pem} /etc/openvpn/ sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/ sudo gzip -d /etc/openvpn/server.conf.gz - Edit
/etc/openvpn/server.confand start:sudo systemctl start openvpn@server
Troubleshooting
- No Internet Access? Enable IP forwarding and configure NAT:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf sudo sysctl -p
- Firewall Issues? Allow VPN ports (e.g., UDP 51820 for WireGuard):
sudo ufw allow 51820/udp
Recommendation
- For personal use, WireGuard is simpler and faster.
- For commercial VPNs, use the provider's app or Network Manager.
Let me know if you need help with a specific VPN setup!








