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 (using...
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 (using OpenVPN, WireGuard, etc.). Below are the common methods:
Connecting to a VPN Service (e.g., NordVPN, ProtonVPN)
Most commercial VPN providers offer Linux CLI tools or manual setup guides.
Example: NordVPN on Ubuntu
- Install NordVPN (official method):
sudo apt update sudo apt install nordvpn
- Log in and connect:
nordvpn login nordvpn connect
Example: ProtonVPN (Official CLI)
- Install ProtonVPN:
sudo apt install openvpn dialog python3-pip sudo pip3 install protonvpn-cli
- Initialize and connect:
sudo protonvpn init sudo protonvpn connect
Manual OpenVPN Setup (for .ovpn files)
If your VPN provider supplies .ovpn configuration files:
- Install OpenVPN:
sudo apt update sudo apt install openvpn
- Place the
.ovpnfile in/etc/openvpn/:sudo cp your_config.ovpn /etc/openvpn/
- Start the VPN:
sudo systemctl start openvpn@your_config
(Replace
your_configwith the filename without the.ovpnextension.)
Setting Up WireGuard (Fast & Modern VPN)
WireGuard is lightweight and secure. Many providers (e.g., Mullvad) support it.
Install WireGuard
sudo apt update sudo apt install wireguard resolvconf
Generate Keys
umask 077 wg genkey | tee privatekey | wg pubkey > publickey
Configure WireGuard
Edit /etc/wireguard/wg0.conf (example client config):
[Interface] PrivateKey = <your_private_key> Address = 10.0.0.2/24 DNS = 1.1.1.1 [Peer] PublicKey = <server_public_key> Endpoint = vpn.example.com:51820 AllowedIPs = 0.0.0.0/0
Start WireGuard
sudo wg-quick up wg0sudo systemctl enable wg-quick@wg0
Using GNOME's Built-in VPN Support (GUI)
- Go to Settings > Network > VPN.
- Click Add VPN and select your protocol (OpenVPN, WireGuard, etc.).
- Enter your VPN provider's details (server, username, password, etc.).
- Toggle the VPN to connect.
Troubleshooting
- Permissions Issue: Run VPN commands with
sudoif needed. - DNS Leaks: Use
dig +short myip.opendns.com @resolver1.opendns.comto check your IP. - Kill Switch: Some providers (e.g., NordVPN) offer a kill switch to block traffic if the VPN disconnects.
Summary
- For commercial VPNs: Use the provider's official CLI tool (e.g.,
nordvpn,protonvpn-cli). - For OpenVPN: Use
sudo openvpn /path/to/config.ovpn. - For WireGuard: Configure
/etc/wireguard/wg0.confand usewg-quick. - GUI Method: Use Ubuntu's Network Settings for easy setup.
Let me know if you need help with a specific VPN setup!

相关文章









