19.6. Connecting to Existing VPN Services

The WireGuard tunnels in Section 19.5 were built from both ends. The other half of VPN work is joining a service someone else operates - an employer's gateway, a commercial provider, a partner network - where what arrives is a profile and certificates, and the only decisions left are where to put them and how to verify them. This section joins rtpeer's OpenVPN service from rtclient, first with the packaged client unit, then through NetworkManager the way a desktop does it.

rtpeer already plays the provider. It was built once, before the client work, in three steps: easy-rsa - the package of the same name, installed on the VPN server alongside openvpn - made a certificate authority and issued a server certificate plus one client certificate (make-cadir /etc/openvpn/easy-rsa, then ./easyrsa init-pki, EASYRSA_BATCH=1 ./easyrsa build-ca nopass, ./easyrsa build-server-full server nopass, and ./easyrsa build-client-full client1 nopass - the last command signs client1 and writes the private key the administrator then hands to the user). Its /etc/openvpn/server/server.conf defines what the client will see:

# /etc/openvpn/server/server.conf (on rtpeer)
port 1194
proto udp
dev tun
topology subnet
server 10.19.1.0 255.255.255.0
ca ca.crt
cert server.crt
key server.key
dh none
push "route 192.168.220.0 255.255.255.0"
push "dhcp-option DNS 192.168.220.10"
keepalive 10 60
persist-key
persist-tun
user nobody
group nogroup
verb 3
explicit-exit-notify 1

Two push lines matter most to the client: the route to LAN B - a split tunnel, in the vocabulary of Section 19.6.3 - and the DNS server to use while connected, the same dnsmasq resolver the WireGuard exercise used. The server line defines the pool 10.19.1.0/24 the client will draw its tunnel address from.

First, clear the ground so the two VPN exercises stay independent - on rtclient, as john, bring the WireGuard remote-access tunnel down:

$ sudo wg-quick down wg1
[#] ip link delete dev wg1
[#] resolvconf -d tun.wg1 -f

The interface, its routes, and its DNS registration all leave together - the second line is wg-quick undoing the resolver change it made when the tunnel came up.

19.6.1. OpenVPN Client Profiles and Certificate Handling

Install the client on rtclient, as john, with sudo apt install openvpn. What the provider sent - in a production setting, by download or mail - sits in the workspace, under its own directory. Look at it, on rtclient as john:

$ ls -l openvpn
total 20
-rw-rw-r-- 1 john john 1204 Nov 21 19:21 ca.crt
-rw-r--r-- 1 john john  281 Nov 21 19:21 client.ovpn
-rw-rw-r-- 1 john john 4494 Nov 21 19:21 client1.crt
-rw------- 1 john john 1704 Nov 21 19:21 client1.key

Four files: the CA's own certificate (ca.crt - public, the trust anchor), the client certificate (client1.crt - public, proves this user to the server), the client private key (client1.key - secret, already 600), and the profile that binds them together. Reading and checking them uses the openssl command line; if it is not already installed, sudo apt install openssl on rtclient, as john, provides it. Before trusting any of it, verify the chain and read the identity, on rtclient as john:

$ openssl verify -CAfile openvpn/ca.crt openvpn/client1.crt
openvpn/client1.crt: OK
$ openssl x509 -in openvpn/client1.crt -noout -subject -issuer -dates
subject=CN=client1
issuer=CN=Easy-RSA CA
notBefore=Nov 21 19:21:06 2026 GMT
notAfter=Feb 23 19:21:06 2029 GMT
openssl form Description
verify -CAfile ca cert Check that cert chains to ca; prints OK or the exact failure.
x509 -in cert -noout Read a certificate without re-emitting it; add -subject, -issuer, -dates, -text for detail.

The certificate names the subject (client1), the issuer (Easy-RSA CA), and - the dates most worth reading before "it stopped working" becomes a support call - a validity window into 2029. Now the profile itself, on rtclient as john:

$ cat openvpn/client.ovpn
client
dev tun
proto udp
remote 192.168.121.49 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth-nocache
verb 3
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
ca ca.crt
cert client1.crt
key client1.key

Line by line where it is not obvious: client selects client mode; dev tun builds a layer-3 tunnel (tap would be layer 2); remote names the server and its UDP port; resolv-retry infinite keeps retrying when the server's address is temporarily unresolvable; nobind uses an ephemeral source port. remote-cert-tls server is the one line that verifies the server's identity: it requires the server certificate to carry the extended-key-usage markers of a TLS server, which is what stops a client certificate issued by the same CA from impersonating the gateway. auth-nocache refuses to hold the passphrase (this profile authenticates by certificate, so it stays quiet), and the up/down pair runs Debian's update-resolv-conf hook - with script-security 2 permitting it - so the pushed DNS server actually reaches /etc/resolv.conf. The three file references are relative: they resolve against the directory the client runs in, which the packaged unit arranges.

Install the credentials into /etc/openvpn/client/ - certificates world-readable, the key not - and the profile under the instance name, on rtclient as john:

$ sudo install -m 0644 openvpn/ca.crt /etc/openvpn/client/ca.crt
$ sudo install -m 0644 openvpn/client1.crt /etc/openvpn/client/client1.crt
$ sudo install -m 0600 openvpn/client1.key /etc/openvpn/client/client1.key
$ sudo install -m 0644 openvpn/client.ovpn /etc/openvpn/client/client.conf

All silent. The mapping is mechanical: /etc/openvpn/client/NAME.conf drives the systemd instance openvpn-client@NAME, so client.conf makes openvpn-client@client. Start it, on rtclient as john:

$ sudo systemctl start openvpn-client@client

The unit does the negotiation in the background; a few seconds later it is up, on rtclient as john:

$ sudo systemctl is-active openvpn-client@client
active

The tunnel device carries the address the server assigned:

$ ip -br addr show tun0
tun0             UNKNOWN        10.19.1.2/24 fe80::8559:b324:5e5d:d7ef/64

UNKNOWN again - tunnels have no carrier. The negotiation as the journal recorded it, on rtclient as john - selected output, the lines that show the identity check, the push, and the completed setup:

$ sudo journalctl -u openvpn-client@client --no-pager -n 25
Nov 21 19:30:20 rtclient openvpn[4379]: VERIFY OK: depth=0, CN=server
Nov 21 19:30:20 rtclient openvpn[4379]: Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bits RSA, signature: RSA-SHA256
Nov 21 19:30:20 rtclient openvpn[4379]: [server] Peer Connection Initiated with [AF_INET]192.168.121.49:1194
Nov 21 19:30:20 rtclient openvpn[4379]: TLS: move_session: dest=TM_ACTIVE src=TM_INITIAL reinit_src=1
Nov 21 19:30:20 rtclient openvpn[4379]: TLS: tls_multi_process: initial untrusted session promoted to trusted
Nov 21 19:30:20 rtclient openvpn[4379]: PUSH: Received control message: 'PUSH_REPLY,route 192.168.220.0 255.255.255.0,dhcp-option DNS 192.168.220.10,route-gateway 10.19.1.1,topology subnet,ping 10,ping-restart 60,ifconfig 10.19.1.2 255.255.255.0,peer-id 0,cipher AES-256-GCM,protocol-flags cc-exit tls-ekm dyn-tls-crypt,tun-mtu 1500'
Nov 21 19:30:20 rtclient openvpn[4379]: OPTIONS IMPORT: --ifconfig/up options modified
Nov 21 19:30:20 rtclient openvpn[4379]: OPTIONS IMPORT: route options modified
Nov 21 19:30:20 rtclient openvpn[4379]: OPTIONS IMPORT: route-related options modified
Nov 21 19:30:20 rtclient openvpn[4379]: OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Nov 21 19:30:20 rtclient openvpn[4379]: OPTIONS IMPORT: tun-mtu set to 1500
Nov 21 19:30:20 rtclient openvpn[4379]: TUN/TAP device tun0 opened
Nov 21 19:30:20 rtclient openvpn[4379]: net_addr_v4_add: 10.19.1.2/24 dev tun0
Nov 21 19:30:20 rtclient openvpn[4379]: /etc/openvpn/update-resolv-conf tun0 1500 0 10.19.1.2 255.255.255.0 init
Nov 21 19:30:20 rtclient openvpn[4379]: net_route_v4_add: 192.168.220.0/24 via 10.19.1.1 dev [NULL] table 0 metric -1
Nov 21 19:30:20 rtclient openvpn[4379]: Initialization Sequence Completed

VERIFY OK ... CN=server is remote-cert-tls server doing its work; the PUSH_REPLY shows both pushed settings from server.conf; and the update-resolv-conf invocation is the profile's up script installing the pushed DNS. Enable the unit so the tunnel returns at boot, on rtclient as john:

$ sudo systemctl enable openvpn-client@client

Silent, and Section 19.7.1 will hold it to that promise.

19.6.2. NetworkManager VPN Integration on Desktops

A desktop user does not run systemctl to connect; the desktop's network panel does, through NetworkManager. The integration is a plugin package - sudo apt install network-manager-openvpn on rtclient, as john. With the plugin installed, GNOME's Settings → Network page offers a VPN section with a + button; choosing "Import from file…" and selecting client.ovpn fills in the whole connection from the profile - gateway, certificates, key, and the remote-cert-tls server requirement - and after "Add" the connection appears as a toggle in both Settings and the system menu's network section. The certificate and key stay where the importer found them, so the workspace copy is now load-bearing, not a souvenir.

The same import from the command line, which is how a headless or scripted setup does it, on rtclient as john:

$ sudo nmcli connection import type openvpn file openvpn/client.ovpn
Connection 'client' (6bc83937-6e92-4a44-a576-476c2aaf2305) successfully added.
nmcli form Description
connection import type openvpn file F Create a connection profile from a .ovpn file.
connection show [name] List profiles, or show one; -f field selects fields.
connection up / down name Connect and disconnect as the desktop toggle does.
connection delete name Remove the profile.

The new profile is visible, and its settings can be inspected without opening a dialog, on rtclient as john:

$ nmcli -f NAME,TYPE connection show
NAME    TYPE
lo      loopback
client  vpn
$ nmcli -f vpn.data connection show client
vpn.data:                               ca = /home/john/debian-handbook/routing/openvpn/ca.crt, cert = /home/john/debian-handbook/routing/openvpn/client1.crt, challenge-response-flags = 2, connection-type = tls, dev = tun, key = /home/john/debian-handbook/routing/openvpn/client1.key, remote = 192.168.121.49:1194, remote-cert-tls = server

Everything the profile carried survived the import, including remote-cert-tls = server - worth checking, because a profile edited by hand sometimes loses it, and the desktop will then accept any server certificate signed by the CA. Now the single-owner rule from Section 17.2.2 applies with teeth: the openvpn-client@client unit is still running this profile's tunnel. Two managers on one profile means two tunnels, duplicate addresses, and resolver files overwritten in racing order. Keep exactly one, on rtclient as john:

$ sudo nmcli connection delete client
Connection 'client' (6bc83937-6e92-4a44-a576-476c2aaf2305) successfully deleted.

The imported profile is gone; the packaged unit keeps the tunnel. On a real desktop the choice usually goes the other way - the user imports once, stops the unit if it was running, and lets the panel own the connection - and either is correct as long as it is the only one. A desktop profile's secrets live in /etc/NetworkManager/system-connections/, readable only by root, which is also the file to back up or re-create after reinstalling.

19.6.3. Split Tunnels, Full Tunnels, and DNS Leak Diagnosis

What a VPN covers decides its shape. The push from this server covers one prefix - check both halves, on rtclient as john:

$ ip route get 192.168.220.10
192.168.220.10 via 10.19.1.1 dev tun0 src 10.19.1.2 uid 1001
    cache
$ ip route get 192.168.121.1
192.168.121.1 dev eth0 src 192.168.121.229 uid 1001
    cache

LAN B travels the tunnel; everything else, including the administration network and the default route, leaves directly. That is a split tunnel: precise, cheap, and the right design when only one network is private. The alternative is a full tunnel, where the server pushes redirect-gateway def1 and every packet enters the tunnel. The def1 trick is worth understanding because of what it does not do: it does not replace the default route (which would break the tunnel's own encrypted packets to the server). Instead it installs two host-like routes, 0.0.0.0/1 and 128.0.0.0/1 via the tunnel - between them they cover all IPv4, and both are longer prefixes than the /0 default, so the default route sits shadowed underneath and the tunnel still has its own path out. This chapter's server stays with the split tunnel; a full tunnel is one server-side line plus a warning: it takes over the default route the moment it comes up, so plan the out-of-band access and the rollback before flipping it (Chapter 18's timed-rollback pattern is exactly right).

Split tunnel versus full tunnel

Figure 19.6. Conceptual comparison: a split tunnel covers only the pushed prefixes and leaves the default route direct; a full tunnel shadows the default with two /1 routes through tun0. The resolver file is the third column of either design - it decides where names are looked up.

The pushed DNS is active - on rtclient as john:

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.220.10
nameserver 192.168.121.1
$ getent hosts server.ch19.example
192.168.220.10  server.ch19.example

The tunnel's resolver is first; the local one is the fallback. This is where the phrase DNS leak earns its name. In a split tunnel without pushed DNS, the client keeps resolving through its ordinary, unencrypted resolver - which means the ISP (or whoever runs the local network) sees every name the user looks up, even though the traffic itself is tunneled. With pushed DNS, as here, the queries travel the tunnel; the leak risk moves to the fallback: if the tunnel's resolver ever becomes unreachable, glibc silently tries the next nameserver line, and the queries leave unencrypted without any error message. Diagnosis is three checks, none of which needs a third-party "leak test" web site:

  1. Read /etc/resolv.conf - is the tunnel's resolver listed, and first?
  2. ip route get on the resolver's address - does the query path actually enter the tunnel?
  3. For proof rather than inference, watch the physical interface while resolving: sudo tcpdump -ni eth0 port 53 in one terminal and getent hosts some-name.example in another; a leak is queries appearing on the unencrypted path (Chapter 17 covers the capture mechanics).

Stop the tunnel and confirm the system unwinds cleanly, on rtclient as john:

$ sudo systemctl stop openvpn-client@client

The device is gone, as it should be:

$ ip -br addr show tun0
Device "tun0" does not exist.

And the resolver is back to its pre-tunnel state:

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.121.1

The down script ran when the tunnel stopped, exactly as the up script ran when it started - nothing left behind. That symmetry is worth more than it sounds: a VPN client that leaves routes or resolvers behind after stopping turns every subsequent network problem into a VPN problem.