Setting up a VPN on Ubuntu can be done in several ways, depending on whether you want to use a commercial VPN service (like NordVPN, ExpressVPN, etc.) or set up your own VPN server (like OpenVPN or WireGuard). Below are the common methods: Most VPN providers offer Linux clients or OpenVPN configuration files.
Steps:
- Install the VPN client (if available):
- For example, NordVPN:
sudo apt update sudo apt install nordvpn nordvpn login nordvpn connect
- For example, NordVPN:
- Alternatively, use OpenVPN config files:
- Download
.ovpnfiles from your VPN provider. - Install OpenVPN:
sudo apt update sudo apt install openvpn
- Connect:
sudo openvpn --config /path/to/config.ovpn
- Download
Setting Up WireGuard (Fast & Modern VPN)
WireGuard is a lightweight and fast VPN protocol.
Steps:
-
Install WireGuard:
sudo apt update sudo apt install wireguard resolvconf
-
Generate Keys:
umask 077 wg genkey | tee privatekey | wg pubkey > publickey
-
Configure WireGuard (
/etc/wireguard/wg0.conf):[Interface] PrivateKey = <your_private_key> Address = 10.0.0.1/24 ListenPort = 51820 [Peer] PublicKey = <remote_public_key> AllowedIPs = 10.0.0.2/32 Endpoint = <server_IP>:51820 -
Start WireGuard:
sudo systemctl enable --now wg-quick@wg0
Setting Up OpenVPN (Traditional VPN)
If you want to run your own VPN server.
Steps:
- Install OpenVPN & Easy-RSA:
sudo apt update sudo apt install openvpn easy-rsa
- Set Up PKI (Public Key Infrastructure):
make-cadir ~/openvpn-ca cd ~/openvpn-ca source vars ./clean-all ./build-ca # Follow prompts ./build-key-server server # For server cert ./build-dh # Diffie-Hellman ./build-key client1 # For client cert
- Configure OpenVPN Server (
/etc/openvpn/server.conf):port 1194 proto udp dev tun ca ca.crt cert server.crt key server.key dh dh.pem server 10.8.0.0 255.255.255.0 push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" keepalive 10 120 cipher AES-256-CBC user nobody group nogroup persist-key persist-tun status openvpn-status.log verb 3 - Start OpenVPN:
sudo systemctl enable --now openvpn@server
- Generate Client Configurations (
client.ovpn):client dev tun proto udp remote your-server-ip 1194 resolv-retry infinite nobind user nobody group nogroup persist-key persist-tun ca ca.crt cert client.crt key client.key remote-cert-tls server cipher AES-256-CBC verb 3
Using Network Manager (GUI for VPNs)
For a graphical approach:
- Open Settings → Network → VPN.
- Click to add a VPN (OpenVPN, WireGuard, or other).
- Enter your VPN provider's details or import
.ovpnfiles.
Troubleshooting
- No Internet after VPN? Try:
sudo sysctl -w net.ipv4.ip_forward=1
- Firewall blocking? Allow VPN ports (
ufw allow 1194/udpfor OpenVPN). - DNS leaks? Use
dnsmasqorresolvectl.
Would you like help with a specific VPN setup? (e.g., ProtonVPN, Mullvad, or a self-hosted solution?)









