Network Detection¶
The script auto-detects the server's network configuration during installation.
Public IP Detection¶
resolvePublicIPv4()¶
Tries four methods to detect the server's public IPv4 address (5-second timeout each):
https://api.seeip.orghttps://ifconfig.mehttps://api.ipify.org- DNS query:
dig +short myip.opendns.com @resolver1.opendns.com
resolvePublicIPv6()¶
Same approach for IPv6:
https://api6.seeip.orghttps://ifconfig.me(over IPv6)https://api64.ipify.org- DNS query to Google
Both functions retry up to 2 times on connection failure.
Server IP Detection — detect_server_ips()¶
Uses ip addr to find locally bound addresses:
# IPv4 — first global-scope address
ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1
# IPv6 — first global-scope address
ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1
Sets the IP variable based on ENDPOINT_TYPE (4 or 6).
NAT Detection¶
During interactive installation (installQuestions()), the script compares:
- Local IP — from
ip addr(private, e.g.,10.0.2.15) - Public IP — from external services (e.g.,
203.0.113.1)
If they differ, the server is behind NAT. The script prompts for the public IP or hostname to use as the client endpoint.
For IPv6, it also detects link-local addresses (fe80::) and warns that they cannot be used as endpoints.
Network Configuration — prepare_network_config()¶
After all settings are collected, this function calculates derived values:
| Variable | Calculation | Example |
|---|---|---|
VPN_GATEWAY_IPV4 | Subnet with last octet .1 | 10.8.0.0 → 10.8.0.1 |
VPN_GATEWAY_IPV6 | Subnet with ::1 appended | fd42:42:42:42:: → fd42:42:42:42::1 |
IPV6_SUPPORT | Copy of CLIENT_IPV6 | For backward compatibility |
Interface Detection¶
During installOpenVPN(), the script detects the default network interface:
This NIC variable is used for firewall NAT/masquerade rules to know which interface to masquerade outgoing VPN traffic through.