VPN Installation on Linux: 2 Easy Setups, Avoid These Errors
A VPN installation on Linux takes two packages and a few files, once you strip away the marketing. The old version of this post compared commercial providers and described menus. This rewrite builds two VPNs for real, OpenVPN and WireGuard, between two Debian 13 containers on a private podman network, and shows the errors you are most likely to hit. All output is from that lab: OpenVPN 2.6.14, easy-rsa 3.2.2 and wireguard-tools v1.0.20210914. NetworkManager import and paid VPN apps were not tested.
Contents
Which VPN installation on Linux do you need?
If you bought a VPN service, use the provider's app or import its .ovpn or WireGuard file; the rest of this post explains what those files contain. If you want your own tunnel to a server you control, you choose between:
- OpenVPN: certificates, a single port, works in user space. More files to manage.
- WireGuard: one key pair per side and a short config. Needs the kernel module or a user-space build.
VPN installation on Linux with OpenVPN: the server
The first VPN installation on Linux in this lab is OpenVPN. Install the packages, then build a small certificate authority with easy-rsa. make-cadir creates a private copy of the scripts:
apt-get install openvpn easy-rsa
make-cadir /etc/openvpn/pki-ca && cd /etc/openvpn/pki-ca
./easyrsa --batch init-pki
EASYRSA_BATCH=1 ./easyrsa build-ca nopass
EASYRSA_BATCH=1 ./easyrsa build-server-full server nopass
EASYRSA_BATCH=1 ./easyrsa build-client-full laptop nopass
openvpn --genkey secret pki/ta.key
The output ended with Build-ca completed successfully. and the paths of pki/issued/server.crt and pki/issued/laptop.crt. The server certificate was valid until Feb 4 06:57:49 2029 GMT. I used nopass only because this is a lab; protect the CA key with a passphrase on a real server. The server configuration:
port 1194
proto udp
dev tun
ca /etc/openvpn/pki-ca/pki/ca.crt
cert /etc/openvpn/pki-ca/pki/issued/server.crt
key /etc/openvpn/pki-ca/pki/private/server.key
dh none
tls-crypt /etc/openvpn/pki-ca/pki/ta.key
server 10.8.0.0 255.255.255.0
topology subnet
keepalive 10 60
persist-key
persist-tun
verb 3
Started with openvpn --config lab.conf, the log ended with:
net_addr_v4_add: 10.8.0.1/24 dev tun0
UDPv4 link local (bound): [AF_INET][undef]:1194
IFCONFIG POOL IPv4: base=10.8.0.2 size=253
Initialization Sequence Completed
It also printed Note: Kernel support for ovpn-dco missing, disabling data channel offload. That is a performance note, not an error: the tunnel works without the DCO kernel module.
The OpenVPN client file
The easiest client setup is one file with everything inline. Mine had 104 lines: these settings plus the CA certificate, the client certificate, the client key and the tls-crypt key between tags:
client
dev tun
proto udp
remote 10.89.77.2 1194
nobind
remote-cert-tls server
verb 3
<ca> ... </ca>
<cert> ... </cert>
<key> ... </key>
<tls-crypt> ... </tls-crypt>
This one file is the whole client side of the VPN installation on Linux. Treat it like a password: anyone who has it can connect. On the client, openvpn --config laptop.ovpn connected at once:
Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bits RSA, signature: RSA-SHA256
[server] Peer Connection Initiated with [AF_INET]10.89.77.2:1194
TUN/TAP device tun0 opened
Initialization Sequence Completed
Data Channel: cipher 'AES-256-GCM', peer-id: 0
$ ping -c 3 -W 2 10.8.0.1 | tail -3
3 packets transmitted, 3 received, 0% packet loss, time 2078ms
Check that the VPN installation on Linux really encrypts
Do not trust a green icon. I sent an HTTP request with the word TOPSECRETMARKER through the tunnel and captured both interfaces of the server:
eth0 hits: 0
tun0 hits: 2
IP 10.89.77.2.1194 > 10.89.77.3.37792: UDP, length 72
On the tunnel interface the text was visible, as it should be after decryption. On the real network it appeared zero times: only UDP packets to port 1194.

Send all traffic through the VPN
After a basic VPN installation on Linux, only the VPN subnet goes through the tunnel. To route everything, push a gateway and DNS from the server and enable NAT there:
push "redirect-gateway def1"
push "dhcp-option DNS 1.1.1.1"
$ iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
IP forwarding must be on (/proc/sys/net/ipv4/ip_forward was 1 in the lab). The client then received PUSH_REPLY,redirect-gateway def1,dhcp-option DNS 1.1.1.1,... and two new routes, 0.0.0.0/1 via 10.8.0.1 dev tun0 and 128.0.0.0/1 via 10.8.0.1 dev tun0. These two halves cover the whole address space without deleting the normal default route. ip route get 1.1.1.1 confirmed via 10.8.0.1 dev tun0, and HTTPS to debian.org worked through the tunnel.
One warning: /etc/resolv.conf did not change. The plain openvpn command does not apply pushed DNS by itself on Debian, so name lookups still went to the old server. Use a helper script or NetworkManager for DNS, and test it.
VPN installation on Linux with WireGuard
The second VPN installation on Linux is shorter. WireGuard needs one key pair per side. In the lab, ip link add wg0 type wireguard worked, so the kernel module was available. Generate keys with a strict umask:
cd /etc/wireguard; umask 077
wg genkey > s.priv; wg pubkey < s.priv > s.pub
Server /etc/wireguard/wg0.conf:
[Interface]
Address = 10.9.0.1/24
ListenPort = 51820
PrivateKey = <server private key>
[Peer]
PublicKey = <client public key>
AllowedIPs = 10.9.0.2/32
Client /etc/wireguard/wg0.conf:
[Interface]
Address = 10.9.0.2/24
PrivateKey = <client private key>
[Peer]
PublicKey = <server public key>
Endpoint = 10.89.77.2:51820
AllowedIPs = 10.9.0.0/24
PersistentKeepalive = 25
$ wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.9.0.2/24 dev wg0
[#] ip link set mtu 65440 up dev wg0
$ ping -c 3 -W 2 10.9.0.1 | tail -2
3 packets transmitted, 3 received, 0% packet loss, time 2055ms
$ wg show wg0
latest handshake: 2 seconds ago
transfer: 476 B received, 564 B sent
WireGuard gives no error for a wrong key. When I put a random public key in the client config, the ping lost every packet, transfer showed 0 B received, and there was no handshake line at all. If latest handshake is missing, check the keys first. The WireGuard quick start explains the same commands.
Errors in a VPN installation on Linux
[no CAP_NET_ADMIN]
ERROR: Cannot ioctl TUNSETIFF tun: Operation not permitted (errno=1)
[no /dev/net/tun]
ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)
[wrong port]
read UDPv4 [ECONNREFUSED]: Connection refused (fd=3,code=111)
[wrong tls-crypt key, client side]
TLS Error: TLS key negotiation failed to occur within 6 seconds (check your network connectivity)
TLS Error: TLS handshake failed
[same, server side]
TLS Error: tls-crypt unwrapping failed from [AF_INET]10.89.77.3:47023
tls-crypt unwrap error: packet authentication failed
Most failed attempts at a VPN installation on Linux end with one of these. The first two appear in containers and on locked-down systems: OpenVPN needs the tun device and permission to configure it. In rootless podman on an SELinux host, the lab containers also needed --security-opt label=disable before OpenVPN could open the device. The client message for a wrong tls-crypt key blames the network; the real answer is in the server log. More on how a firewall can block these ports is in the iptables post, and a WireGuard server in a container is covered in the WireGuard Docker post.
FAQ
Is a VPN installation on Linux possible without a GUI? Yes. Everything in this post was done in a terminal.
OpenVPN or WireGuard? WireGuard needed far less configuration in this lab. OpenVPN gives you certificates you can revoke one by one and clearer error messages. The OpenVPN community how-to covers its options in detail.
Does a VPN make me anonymous? It hides your traffic from the local network, as the capture shows. The VPN server still sees it.
Comments
Post a Comment