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 (e.g., OpenVPN, WireGuard). Below are the most common methods: Most VPN providers offer dedicated apps for Ubuntu. Follow these general steps:
-
Install the VPN App
- Download the
.debfile from your VPN provider’s website (e.g., NordVPN, ExpressVPN). - Install it via the terminal:
sudo apt install ./downloaded-file.deb
- Alternatively, some VPNs support
OpenVPNorWireGuardconfig files.
- Download the
-
Connect via the App
Launch the app, log in, and select a server.
Using OpenVPN (Manual Setup)
If your VPN provider supplies .ovpn config files:
-
Install OpenVPN
sudo apt update sudo apt install openvpn
-
Download VPN Config Files
- Get the
.ovpnfiles from your VPN provider (usually in a zip file).
- Get the
-
Connect
sudo openvpn --config /path/to/config.ovpn
Enter your VPN credentials when prompted.
-
(Optional) Auto-Connect on Boot
Place the.ovpnfile in/etc/openvpn/and enable the service:sudo systemctl enable openvpn@config-name
Setting Up WireGuard (Fast & Modern VPN)
WireGuard is lightweight and easy to configure.
For a Client (Connecting to a VPN Server)
-
Install WireGuard
sudo apt update sudo apt install wireguard resolvconf
-
Configure WireGuard
- Get a config file (e.g.,
wg0.conf) from your VPN provider. - Place it in
/etc/wireguard/.
- Get a config file (e.g.,
-
Start the VPN
sudo wg-quick up wg0
- To auto-start on boot:
sudo systemctl enable wg-quick@wg0
- To auto-start on boot:
Creating Your Own VPN Server
If you want to host your own VPN (e.g., on a VPS):
Option A: OpenVPN Server
Use openvpn-install script for easy setup:
wget https://git.io/vpn -O openvpn-install.sh && sudo bash openvpn-install.sh
Follow the prompts to set up a server.
Option B: WireGuard Server
Use wg-quick or tools like PiVPN:
sudo apt install wireguard sudo wg genkey | tee privatekey | wg pubkey > publickey
Then configure /etc/wireguard/wg0.conf (see WireGuard docs).
VPN via Network Manager (GUI)
For .ovpn files, you can use Ubuntu’s built-in network manager:
- Open Settings > Network > VPN.
- Click Add VPN and select Import from file....
- Choose your
.ovpnfile and enter credentials.
Troubleshooting
- DNS Leaks: Use
dnsleaktest.comto check. - Kill Switch: Block traffic if VPN disconnects (use
ufw):sudo ufw default deny outgoing sudo ufw allow out to <VPN_SERVER_IP>
- No Internet? Check routes with
ip route.
Which Method Should You Use?
- Easiest: Commercial VPN app (e.g., NordVPN).
- Fastest: WireGuard.
- Most Flexible: OpenVPN or self-hosted VPN.
Let me know if you need help with a specific VPN setup!


