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 (like OpenVPN or WireGuard). Below are the common methods:
Connecting to a VPN Service (e.g., NordVPN, ProtonVPN)
Most commercial VPN providers offer Linux clients or manual setup instructions.
Method 1: Using the Provider’s Official Client
Some VPNs (e.g., NordVPN, ProtonVPN) offer native Linux apps.
Example for ProtonVPN:
sudo apt install -y openvpn dialog python3-pip sudo pip3 install protonvpn-cli # Log in and connect protonvpn init # Follow setup protonvpn connect
Method 2: Manual OpenVPN Setup
If your provider supports OpenVPN (most do):
- Download the
.ovpnconfig files from your VPN provider. - Install OpenVPN:
sudo apt update sudo apt install openvpn
- Connect using a config file:
sudo openvpn --config /path/to/config.ovpn
(You may need to enter your VPN username/password.)
Setting Up Your Own VPN Server
Option A: WireGuard (Fast & Modern)
WireGuard is lightweight and secure.
-
Install WireGuard:
sudo apt update sudo apt install wireguard
-
Generate keys:
umask 077 wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey
-
Configure
/etc/wireguard/wg0.conf(example):[Interface] PrivateKey = <your-server-private-key> Address = 10.0.0.1/24 ListenPort = 51820 PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer] # Client config PublicKey = <client-public-key> AllowedIPs = 10.0.0.2/32
-
Enable IP forwarding:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf sudo sysctl -p
-
Start WireGuard:
sudo wg-quick up wg0 sudo systemctl enable wg-quick@wg0
Option B: OpenVPN (Traditional)
Use openvpn-install script for easy setup:
wget https://git.io/vpn -O openvpn-install.sh chmod +x openvpn-install.sh sudo ./openvpn-install.sh
Follow the prompts to set up a server and generate client profiles.
Using GNOME’s Built-in VPN Support
Ubuntu (GNOME) has built-in VPN support:
- Go to Settings → Network → VPN.
- Click Add VPN and select your protocol (e.g., OpenVPN, WireGuard).
- Enter your VPN details (config file, username, password).
Troubleshooting
- Permission Issues: Use
sudofor system-wide VPN setups. - DNS Leaks: Check with DNSLeakTest.
- Firewall: Allow VPN ports (e.g., UDP 51820 for WireGuard).
Would you like help with a specific VPN setup?









