Setting up a VPN on Linux can be done in several ways, depending on the type of VPN you want to use (e.g., OpenVPN, WireGuard, or a commercial VPN service). Below are guides for common VPN setups: Most VPN providers (e.g., NordVPN, ExpressVPN, ProtonVPN) offer OpenVPN configuration files.
Install OpenVPN
On Debian/Ubuntu:
sudo apt update sudo apt install openvpn
On Arch Linux:
sudo pacman -S openvpn
On Fedora/RHEL:
sudo dnf install openvpn
Use VPN Provider Configurations
- Download
.ovpnconfig files from your VPN provider. - Place them in
/etc/openvpn/:sudo cp ~/Downloads/config.ovpn /etc/openvpn/
- Start the VPN:
sudo openvpn --config /etc/openvpn/config.ovpn
(You may need to enter your VPN username/password.)
Auto-start VPN at Boot
Edit /etc/default/openvpn and enable autostart:
AUTOSTART="all"
Then enable the service:
sudo systemctl enable --now openvpn
WireGuard (Fast & Modern VPN)
WireGuard is lightweight and often faster than OpenVPN.
Install WireGuard
On Debian/Ubuntu:
sudo apt install wireguard resolvconf
On Arch Linux:
sudo pacman -S wireguard-tools
On Fedora/RHEL:
sudo dnf install wireguard-tools
Set Up WireGuard (Client)
-
Generate keys:
cd /etc/wireguard/ sudo umask 077 sudo wg genkey | tee privatekey | wg pubkey > publickey
-
Create
/etc/wireguard/wg0.confwith your VPN provider's settings:[Interface] PrivateKey = <your_private_key> Address = <assigned_IP> DNS = <VPN_DNS> [Peer] PublicKey = <server_public_key> AllowedIPs = 0.0.0.0/0 Endpoint = <server_IP>:51820 PersistentKeepalive = 25
-
Start WireGuard:
sudo wg-quick up wg0
-
Enable at boot:
sudo systemctl enable --now wg-quick@wg0
Using NetworkManager GUI (for some VPNs)
Many VPNs (e.g., ProtonVPN, Mullvad) support NetworkManager integration.
- Install the VPN plugin (e.g., for OpenVPN):
sudo apt install network-manager-openvpn
- Go to:
- Settings > Network > VPN
- Click and import your VPN config.
Commercial VPN CLI Tools
Some providers offer CLI tools:
- NordVPN:
sudo apt install nordvpn nordvpn login nordvpn connect
- ProtonVPN:
sudo apt install protonvpn-cli protonvpn-cli login protonvpn-cli connect
Check VPN Status
ip a # Check assigned IP curl ifconfig.me # Check public IP wg show # WireGuard status
Troubleshooting
- DNS Leaks: Use
dnsleaktest.comto verify. - Kill Switch: Block non-VPN traffic with
iptablesor use your VPN provider's tool. - Permissions: Ensure
/etc/openvpn/or/etc/wireguard/files are readable only by root (chmod 600).
Would you like help with a specific VPN setup? Let me know!








