SkillPilotAI

openvpn (3/3)

Part 3 of OpenVPN covers running and operating a VPN: persistent tun devices, script hooks with environment variables, the management interface, plug-ins, Windows-only and debug options, removed options, <connection> and inline blocks, and signals.

118.1 TUN/TAP standalone operations (2)

Terminal
openvpn --mktun --dev tun9 --user nobodyip -br link show tun9openvpn --rmtun --dev tun9ip link show tun9
Output
2026-11-09 02:52:02 TUN/TAP device tun9 opened2026-11-09 02:52:02 Persist state set to: ONtun9   DOWN   <POINTOPOINT,MULTICAST,NOARP>2026-11-09 02:52:07 TUN/TAP device tun9 opened2026-11-09 02:52:07 Persist state set to: OFFDevice "tun9" does not exist.
  • Normally tun is deleted when openvpn stops; --mktun creates a persistent device, --user nobody lets a normal user open it, --rmtun deletes it.

118.2 Script hooks (22)

Which server hook runs when
  1. 1.up: tun0 is opened on server start

  2. 2.laptop1 192.168.138.20 sends its TLS handshake

  3. 3.tls-verify: runs per certificate (CA at depth 1, laptop1 at depth 0)

  4. 4.client-connect: on login (non-zero exit rejects)

  5. 5.learn-address: add 10.8.0.2 laptop1

  6. 6.client-disconnect: on logout, with bytes and duration

Terminal
# server.confscript-security 2setenv SITE officeup hook.shtls-verify hook.shclient-connect hook.shclient-disconnect hook.shlearn-address hook.sh
  • script-security 2 is required, otherwise no external script runs.
  • setenv SITE office gives every script a custom variable.
Output
--up-delay / --up-restart   when / how often up runs--down cmd  --down-pre      after / before tun close--route-up  --route-pre-down--ipchange cmd              remote IP changed--auth-user-pass-verify f via-file|via-env   (via-env needs script-security 3)--tls-export-cert dir       peer cert as PEM--setenv FORWARD_COMPATIBLE 1    unknown options = warning--setenv-safe n v           OPENVPN_n (push safe)

118.3 Script environment variables (52)

Terminal
L=/tmp/hooks.logecho "[${script_type:-plugin}] $*" >> $Lcase "$script_type" in  up|down) p dev tun_mtu ifconfig_local script_context signal SITE ;;  route-up) p route_network_1 route_netmask_1 route_vpn_gateway ;;  tls-verify) p untrusted_ip X509_${1}_CN ;;  client-connect) p common_name trusted_ip ifconfig_pool_remote_ip time_unix ;;  client-disconnect) p common_name bytes_received bytes_sent time_duration ;;esac
Output
[up] tun0 1500 0 10.8.0.1 255.255.255.0 init  dev=tun0  SITE=office[tls-verify] 1 CN=n118-lab-ca  untrusted_ip=192.168.138.20  X509_1_CN=n118-lab-ca[tls-verify] 0 CN=laptop1  untrusted_ip=192.168.138.20  X509_0_CN=laptop1[client-connect] /tmp/openvpn_cc_5f15...2a.tmp  common_name=laptop1  trusted_ip=192.168.138.20  ifconfig_pool_remote_ip=10.8.0.2  time_unix=1794192791[learn-address] add 10.8.0.2 laptop1[client-disconnect]  common_name=laptop1  bytes_received=2701  bytes_sent=2550  time_duration=31
VariableMeaning
script_typeWhich hook is running
common_nameClient certificate CN
trusted_ip / untrusted_ipReal client IP after / before authentication
ifconfig_pool_remote_ipClient's VPN IP
bytes_received / bytes_sent / time_durationAudit data on disconnect
X509_n_CN, tls_serial_nCertificate details per depth
route_network_n, route_vpn_gatewayPushed route details
username / passwordOnly in via-env mode, removed after the script

118.4 Management interface (23)

Management interface: talking to a running VPN
  1. 1.Server listens on TCP 127.0.0.1:7505 (localhost only)

  2. 2.Admin shell: nc 127.0.0.1 7505

  3. 3.Sends the password: SUCCESS

  4. 4.Sends state / load-stats / status 1

  5. 5.Server replies with CLIENT LIST: laptop1 10.8.0.2

Terminal
# server.confmanagement 127.0.0.1 7505 mgmt.pwmanagement-log-cache 50# admin shell on the server{ echo lab-mgmt-118; sleep 0.5  echo state; echo load-stats  echo 'status 1'; sleep 1; echo quit} | timeout 8 nc 127.0.0.1 7505
Output
ENTER PASSWORD:SUCCESS: password is correct>INFO:OpenVPN Management Interface Version 51794192773,CONNECTED,SUCCESS,10.8.0.1,,,,ENDSUCCESS: nclients=1,bytesin=2661,bytesout=2576OpenVPN CLIENT LISTUpdated,2026-11-09 02:53:32Common Name,Real Address,Bytes Received,...laptop1,192.168.138.20:47424,2661,2510,...ROUTING TABLE10.8.0.2,laptop1,192.168.138.20:47424,...END$ { echo wrong; sleep 1; } | timeout 5 nc ...ENTER PASSWORD:ENTER PASSWORD:
  • Wrong password: the server just asks ENTER PASSWORD again.
  • In production use a Unix socket with management-client-user/group.
Output
--management /run/m.sock unix [pw-file]--management-client-user u  --management-client-group g   (socket access)--management-hold            wait until GUI sends hold release--management-query-passwords ask passwords via the GUI--management-client-auth     auth decided by the management client--management-external-key / --management-external-cert

118.5 Plug-in interface (3)

Terminal
user nobodygroup nobodypersist-keypersist-tunplugin openvpn-plugin-down-root.so /bin/hook
Output
$ ls /usr/lib/openvpn/pluginsopenvpn-plugin-down-root.soPLUGIN_INIT: POST openvpn-plugin-down-root.so ... [/bin/hook]' intercepted=PLUGIN_UP|PLUGIN_DOWNPLUGIN_CALL: POST ...down-root.so/PLUGIN_UP status=0$ tail -n 8 /tmp/hooks.log[learn-address] delete 10.8.0.2[plugin]  dev=tun0  signal=
  • plugin <module> [args]; a relative name loads from the default plugin directory.
  • down-root: the server drops to nobody, but the plugin still runs the down script as root.

118.6 Windows-specific options (29)

Terminal
openvpn --show-adaptersopenvpn --block-outside-dnsopenvpn --windows-driver wintun
Output
Options error: Unrecognized option or missing or extra parameter(s) in [CMD-LINE]:1: show-adapters (2.6.20)Options error: Unrecognized option ... block-outside-dns (2.6.20)Options error: Unrecognized option ... windows-driver (2.6.20)
OptionUse
--block-outside-dnsStop DNS leaks (WFP)
--windows-driver ovpn-dco|wintun|tap-windows6Choose the adapter driver (default ovpn-dco)
--cryptoapicert "SUBJ:...|THUMB:..."Certificate from the Windows cert store
--ip-win32 / --route-methodHow IP and routes are set: DHCP, netsh, IP Helper API
--register-dnsflushdns + registerdns
--show-adapters / --show-netList adapters / network

These are compiled only into the Windows build, so the Linux build says Unrecognized option.

118.7 Debug and expert options (11)

Terminal
openvpn --show-gateway
Output
2026-11-09 02:51:32 sitnl_send: rtnl: generic error (-101): Network unreachable2026-11-09 02:51:32 ROUTE_GATEWAY 192.168.138.1/255.255.255.0 IFACE=eth0 HWADDR=5e:2c:64:73:80:53
  • --show-gateway: the first check for redirect-gateway problems; the IPv6 error is normal (no IPv6 route).
  • --rcvbuf/--sndbuf socket buffers, --shaper bandwidth limit (p2p), --hash-size/--bcast-buffers for very large servers.

118.8 Removed / unsupported options (10)

Terminal
openvpn --ncp-disableopenvpn --no-ivopenvpn --client-cert-not-requiredopenvpn --prng SHA1
Output
Options error: Unrecognized option ... ncp-disable (2.6.20)Options error: Unrecognized option ... no-iv (2.6.20)REMOVED OPTION: --client-cert-not-required, use '--verify-client-cert none' insteadExiting due to fatal errorNOTICE: --prng option ignored (SSL library PRNG is used)
Old optionStatus / replacement
--client-cert-not-required--verify-client-cert none
--ns-cert-type--remote-cert-tls
--ncp-ciphers--data-ciphers
--ifconfig-pool-linear--topology p2p
--ncp-disableRemoved (2.6)
--key-method, --no-ivRemoved (2.5)
--no-replayRemoved (2.5), but still parsed in the lab
--prngIgnored (2.6)

118.9 Config file blocks: <connection> and inline files (7)

<connection> failover
  1. 1.Block 1: remote 192.168.138.10 1195 udp, connect-timeout 5

  2. 2.No server on 1195: Server poll timeout, restarting

  3. 3.Client moves to block 2: port 1194

  4. 4.Peer Connection Initiated

  5. 5.Initialization Sequence Completed

Output
client<ca>-----BEGIN CERTIFICATE----------END CERTIFICATE-----</ca><tls-crypt>-----BEGIN OpenVPN Static key V1-----</tls-crypt><connection>remote 192.168.138.10 1195 udpconnect-timeout 5</connection><connection>remote 192.168.138.10 1194 udp</connection>
Output
UDPv4 link remote: [AF_INET]192.168.138.10:1195Server poll timeout, restartingSIGUSR1[soft,server_poll] received, process restartingUDPv4 link remote: [AF_INET]192.168.138.10:1194[server] Peer Connection Initiated with ...:1194Initialization Sequence Completed$ timeout 4 openvpn --config bad-order.ovpn | grep -i ignoredOption 'tls-crypt' in bad-order.ovpn:53 is ignored by previous <connection> blocks
  • Inline blocks (<ca>, <cert>, <key>, <tls-crypt>...) give the user a single-file profile.
  • Order matters: global options after <connection> blocks are ignored.
  • <pkcs12> must be base64; a <connection> with TCP 443 + http-proxy is a handy fallback when UDP is blocked.

118.10 Signals (5)

Terminal
kill -USR2 $(cat /run/ovpn.pid)      # server: print statskill -USR1 $(cat /tmp/client.pid)    # client: soft restartkill -TERM $(cat /tmp/client.pid)    # client: graceful exitkill -HUP $(cat /run/ovpn.pid)       # server: full restart
Output
[server] OpenVPN CLIENT LISTlaptop1,192.168.138.20:47424,2701,2550,...[client] SIGUSR1[hard,] received, process restarting[client] Initialization Sequence Completed[client] SIGTERM[soft,exit-with-notification] received, process exiting[down] tun0 1500 0 10.8.0.2 255.255.255.0 init  signal=exit-with-notification[server] Cannot pre-load keyfile (pki/tc.key)[server] Exiting due to fatal error
SignalEffect
SIGUSR2Print stats (client list, routing table) to the log
SIGUSR1Soft restart, config not re-read (with persist-key)
SIGHUPFull restart, re-reads config and keys
SIGTERM / SIGINTGraceful exit (exit-with-notification)

HUP on a server running as nobody failed: nobody could not read pki/tc.key.

118.11 Common mistakes

  • Sending HUP to reset connections on a server running as nobody: use USR1.
  • Leaving the management port without a password because it is localhost: any local process can kill clients and read status.
  • Forgetting script-security 2: hooks silently do not run.
  • Copying old configs with removed options (ncp-disable, no-iv): test on a test machine first.

118.12 Interview tips

  • Custom logic on login: script-security 2 + client-connect hook reading common_name / trusted_ip; exit 1 rejects.
  • Faster alternatives: --plugin or --management-client-auth.
  • USR1 = soft restart, HUP = full restart, USR2 = stats, TERM = graceful exit.
  • <connection> blocks give automatic failover between servers or ports.