SkillPilotAI

openvpn (1/3)

OpenVPN is an open source TLS VPN daemon: one binary that runs as client or server and builds an encrypted tunnel over UDP or TCP using certificates and/or username and password. Part 1 covers generic, server, client, log and data-channel crypto options with a real lab.

116.1 What it does and where it runs

  • Every option works as --option on the command line or as a config line without --: --verb 3 = verb 3.
  • Windows: OpenVPN Community installer; Linux: openvpn package + systemd units; macOS: brew or Tunnelblick.
  • Building a tunnel needs root/admin rights.

116.2 How an OpenVPN tunnel comes up

OpenVPN tunnel: TLS, push, data
  1. 1.Laptop 192.168.136.20 sends TLS hello to server 192.168.136.10 on UDP 1194

  2. 2.Both sides verify certificates: VERIFY OK CN=laptop1

  3. 3.Server sends PUSH_REPLY: ifconfig 10.8.0.50, route 192.168.136.128/25, DNS 10.8.0.1

  4. 4.Laptop brings up tun0 = 10.8.0.50

  5. 5.Ping to 192.168.136.150 is encrypted (AES-256-GCM) inside UDP 1194

  6. 6.Server decrypts and forwards to the file server

116.3 Generic options (40)

  • Lab: tun module loaded, ovpn-dco kernel driver not built, so every run uses --disable-dco.
  • --test-crypto runs an encrypt/decrypt self-test without any tunnel.
Terminal
grep -E "^(tun|ovpn)" /proc/modulesopenvpn --version | head -3openvpn --help | grep -c -- '^--'openvpn --genkey secret static.keyopenvpn --test-crypto --secret static.key --cipher AES-256-CBC --disable-dco --verb 3
Output
tun 53248 2 - Live 0x0000000000000000OpenVPN 2.6.20 x86_64-alpine-linux-musl  [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] ...library versions: OpenSSL 3.3.7 7 Apr 2026, LZO 2.10245TESTING ENCRYPT/DECRYPT of packet length=1768OpenVPN crypto self-test mode SUCCEEDED.
Terminal
openvpn --cd /etc/openvpn/n116 \  --config server.conf \  --daemon ovpn-office \  --log /var/log/ovpn-server.log \  --writepid /run/ovpn/server.pidcat /run/ovpn/server.pidps -o pid,user,args | grep [o]penvpn
Output
85   84 root     [openvpn]   85 nobody   openvpn --cd /etc/openvpn/n116 ...... TUN/TAP device tun0 opened... /sbin/ip addr add dev tun0 10.8.0.1/24 broadcast +... UDPv4 link local (bound): [AF_INET][undef]:1194... GID set to nobody... UID set to nobody... Initialization Sequence Completed
  • --cd first so relative paths in the config work; --daemon goes to the background; --writepid saves the PID.
  • user/group nobody drops privileges after the tunnel is built; persist-key and persist-tun are needed because nobody cannot reopen keys or tun0 on restart.
Output
--help  --version         options, version--config F  (or: openvpn F)  config file--cd DIR                  cd first--daemon [name]           background, syslog--writepid F              PID to file--user U  --group G       drop privileges--persist-key --persist-tun  keep keys / tun0 on restart--chroot DIR  --setcon C  hardening--script-security 0..3    allow scripts?--status F [n]  --status-version 1|2|3--disable-dco             classic tun (no DCO driver)--mlock  --nice n  --fast-io--test-crypto             crypto self-test

116.4 Server options (50)

Output
# server.confport 1194proto udpdev tuntopology subnetserver 10.8.0.0 255.255.255.0push "route 192.168.136.128 255.255.255.128"push "dhcp-option DNS 10.8.0.1"push "redirect-gateway def1"client-config-dir ccdmax-clients 10auth-user-pass-verify check-user.sh via-fileuser nobodygroup nobodypersist-keypersist-tunstatus /run/ovpn/status.log 5# ccd/laptop1ifconfig-push 10.8.0.50 255.255.255.0
Output
$ ip -4 addr show tun0    inet 10.8.0.1/24 brd 10.8.0.255 scope global tun0... IFCONFIG POOL IPv4: base=10.8.0.2 size=253... [laptop1] Peer Connection Initiated with [AF_INET]192.168.136.20:47783... OPTIONS IMPORT: reading client specific options from: ccd/laptop1... MULTI: primary virtual IP for laptop1/192.168.136.20:47783: 10.8.0.50$ cat /run/ovpn/status.logCLIENT_LIST,laptop1,192.168.136.20:47783,10.8.0.50,,2709,2569,...,student,0,0,AES-256-GCM
  • server 10.8.0.0 255.255.255.0 = server mode + address pool + routes in one line; the server takes 10.8.0.1.
  • push sends the office route, DNS and redirect-gateway to clients.
  • client-config-dir: file ccd/laptop1 gives this client a fixed IP with ifconfig-push.
  • auth-user-pass-verify runs check-user.sh on every login (status shows Username student).
OptionUse
--client-to-clientClients can talk to each other
--duplicate-cnOne certificate on many devices (risky in production)
--ifconfig-pool-persist FRemember CN to IP mapping
--irouteSubnet behind a client (in ccd)
--verify-client-cert noneLogin with only username/password
--auth-gen-tokenToken instead of password on renegotiation
--max-clients nLimit connected clients

116.5 Client options (63)

Output
clientdev tunproto udpremote 192.168.136.10 1194resolv-retry infinitenobindca pki/ca.crtcert pki/laptop1.crtkey pki/laptop1.keyremote-cert-tls servertls-auth pki/ta.key 1auth-user-pass creds.txtauth-nocachepull-filter ignore "redirect-gateway"explicit-exit-notify 1
Output
VERIFY OK: depth=0, CN=server[server] Peer Connection Initiated with [AF_INET]192.168.136.10:1194PUSH: Received control message: 'PUSH_REPLY,route 192.168.136.128 255.255.255.128,  dhcp-option DNS 10.8.0.1,redirect-gateway def1,...,ifconfig 10.8.0.50 255.255.255.0,...'Pushed option removed by filter: 'redirect-gateway def1'/sbin/ip addr add dev tun0 10.8.0.50/24 broadcast +/sbin/ip route add 192.168.136.128/25 via 10.8.0.1Initialization Sequence Completed$ ip routedefault via 192.168.136.1 dev eth010.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.50192.168.136.128/25 via 10.8.0.1 dev tun0
  • client = pull + tls-client; remote gives server IP and port; nobind does not fix a local port.
  • pull-filter ignore "redirect-gateway" dropped the pushed full-tunnel option: a split tunnel.
Split tunnel with pull-filter
  1. 1.Server pushes redirect-gateway def1 (all traffic into VPN)

  2. 2.Client: Pushed option removed by filter

  3. 3.Packet to 192.168.136.150: dev tun0 via 10.8.0.1

  4. 4.VPN server forwards it to the file server

  5. 5.Packet to 1.1.1.1: dev eth0 via 192.168.136.1, outside the tunnel

Terminal
# laptop1ping -c 2 -W 2 192.168.136.150ip route get 192.168.136.150ip route get 1.1.1.1# vpn-servertcpdump -lnn -i eth0 -c 4 udp port 1194 and greater 100tcpdump -lnn -i tun0 -c 2 icmp
Output
64 bytes from 192.168.136.150: seq=0 ttl=63 time=0.925 ms2 packets transmitted, 2 packets received, 0% packet loss192.168.136.150 via 10.8.0.1 dev tun0 src 10.8.0.501.1.1.1 via 192.168.136.1 dev eth0 src 192.168.136.20[vpn-server] IP 192.168.136.20.47783 > 192.168.136.10.1194: UDP, length 337[vpn-server] IP 192.168.136.10.1194 > 192.168.136.20.47783: UDP, length 1222[vpn-server] IP 10.8.0.50 > 192.168.136.150: ICMP echo request[vpn-server] IP 192.168.136.150 > 10.8.0.50: ICMP echo reply

On the server's eth0 only UDP 1194 is visible; on tun0 the same ping is plain ICMP.

Terminal
# 1) wrong passwordopenvpn --config client.ovpn --auth-user-pass bad-creds.txt# 2) wrong port: no server on 1195openvpn --config wrong-port.ovpn --hand-window 5 --connect-retry-max 1
Output
AUTH: Received control message: AUTH_FAILEDSIGTERM[soft,exit-with-notification] received, process exiting UDPv4 link remote: [AF_INET]192.168.136.10:1195read UDPv4 [ECONNREFUSED]: Connection refusedTLS Error: TLS key negotiation failed to occur within 5 seconds (check your network connectivity)TLS Error: TLS handshake failedAll connections have been connect-retry-max (1) times unsuccessful, exiting
  • Wrong password: server script rejects, client gets AUTH_FAILED; --auth-retry is none by default so it exits.
  • Wrong port: Connection refused, then TLS key negotiation failed after --hand-window 5; --connect-retry-max 1 stops retries.
Output
--client       = --pull + --tls-client--remote host [port] [proto]  (multiple = failover)--remote-random  --resolv-retry n|infinite--connect-retry n [max]  --connect-retry-max n--pull-filter accept|ignore|reject "text"--auth-user-pass [F]  --auth-retry none|...  --auth-token--dns server n address|transport DoH|DoT--http-proxy host port  --socks-proxy host [port]--explicit-exit-notify n  --inactive n

116.6 Log options (13)

Terminal
openvpn --cd /etc/openvpn/n116 --config client.ovpn \  --daemon --log /tmp/client.log --suppress-timestamps --writepid /tmp/client.pidcat /tmp/client.log
Output
UDPv4 link remote: [AF_INET]192.168.136.10:1194TLS: Initial packet from [AF_INET]192.168.136.10:1194VERIFY OK: depth=1, CN=n116-lab-caVERIFY KU OKVERIFY EKU OKVERIFY OK: depth=0, CN=serverInitialization Sequence CompletedData Channel: cipher 'AES-256-GCM', peer-id: 0
OptionMeaning
--verb 0Fatal errors only
--verb 1-4Normal (default 1, use 3 for troubleshooting)
--verb 5R/W character per packet
--verb 6-11Debug levels
--log / --log-appendLog file (truncate / append)
--syslog / --mute nSystem logger / limit repeated messages
--suppress-timestampsNo time on lines (client log above)

116.7 Protocol and data-channel crypto (27)

Terminal
tls-auth pki/ta.key 0    # servertls-auth pki/ta.key 1    # clientdata-ciphers AES-256-GCM:CHACHA20-POLY1305   # both sides# mismatch test (client)openvpn --config client.ovpn --data-ciphers AES-128-GCM
Output
[server] PUSH: No common cipher between server and client. Server data-ciphers:  'AES-256-GCM:CHACHA20-POLY1305', ...[client] AUTH: Received control message: AUTH_FAILED,Data channel cipher negotiation  failed (no shared cipher)
  • tls-auth adds an HMAC to every control packet; key direction 0 on the server, 1 on the client.
  • data-ciphers is the list both sides choose from; in the lab AES-256-GCM was negotiated.
  • --cipher is only for static-key mode now; --secret (static key) and all compression options are deprecated (VORACLE): keep allow-compression no.

116.8 Common mistakes

  • Thinking --cipher decides data encryption: in TLS mode 2.6 ignores it and negotiates from --data-ciphers.
  • Forgetting persist-key/persist-tun with user nobody: restarts fail.
  • Wondering why public sites skip the VPN: pull-filter ignore redirect-gateway is in the client config.
  • Enabling compression on new setups.

116.9 Interview tips

  • AUTH_FAILED: check username/password, then the auth script result in the server log.
  • no shared cipher: compare --data-ciphers on both sides.
  • TLS key negotiation failed: check remote IP, port and a UDP block in the firewall.
  • Default port UDP 1194; can run on TCP 443 to pass strict firewalls; verb 3 is the troubleshooting level.