docs / linux / openvpn

openVPN

linux updated 2026-03-26

1. Install OpenVPN and Easy-RSA on Debian

On harley:

textcopy
apt update
apt -y install openvpn easy-rsa iptables

This installs the OpenVPN daemon, Easy‑RSA PKI tools, and iptables for NAT.


2. Create CA and server/client certificates

Work in the Easy‑RSA directory:

textcopy
cd /usr/share/easy-rsa
./easyrsa init-pki
./easyrsa build-ca
  • Set a CA passphrase and Common Name (e.g. Harley-CA).

Create server cert/key:

textcopy
./easyrsa build-server-full server1 nopass

Create client cert/key:

textcopy
./easyrsa build-client-full client1 nopass

Generate Diffie‑Hellman and TLS key:

textcopy
./easyrsa gen-dh
openvpn --genkey secret ./pki/ta.key

Copy required files to OpenVPN server directory:

textcopy
mkdir -p /etc/openvpn/server
cp -pR pki/issued pki/private pki/ca.crt pki/dh.pem pki/ta.key /etc/openvpn/server/

Now /etc/openvpn/server contains server1.crt, server1.key, client1.crt, client1.key, ca.crt, dh.pem, ta.key.


3. Configure OpenVPN server

Create /etc/openvpn/server/server1.conf:

textcopy
cat >/etc/openvpn/server/server1.conf <<'EOF'
port 1194
proto udp
dev tun

ca /etc/openvpn/server/ca.crt
cert /etc/openvpn/server/issued/server1.crt
key /etc/openvpn/server/private/server1.key
dh /etc/openvpn/server/dh.pem
tls-crypt /etc/openvpn/server/ta.key

topology subnet
server 10.8.0.0 255.255.255.0

push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 1.1.1.1"
push "dhcp-option DNS 8.8.8.8"

keepalive 10 120
cipher AES-256-CBC
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
verb 3
EOF

This sets up a simple tun‑based VPN on UDP 1194 with full‑tunnel routing through the VM.

Enable IP forwarding:

textcopy
sed -i 's/^#\?net.ipv4.ip_forward.*/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sysctl -p

Set iptables NAT so VPN clients go out via the VM’s public interface (assume eth0; adjust if different):

textcopy
WAN_IF="eth0"

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o "$WAN_IF" -j MASQUERADE
iptables -A FORWARD -s 10.8.0.0/24 -o "$WAN_IF" -j ACCEPT
iptables -A FORWARD -d 10.8.0.0/24 -m state --state ESTABLISHED,RELATED -i "$WAN_IF" -j ACCEPT

Persist iptables:

textcopy
apt -y install iptables-persistent
netfilter-persistent save

Start and enable OpenVPN:

textcopy
systemctl enable openvpn-server@server1
systemctl start openvpn-server@server1
systemctl status openvpn-server@server1

4. Open firewall / cloud security group

You must allow UDP port 1194 from the internet to the VM.

  • If the VM provider has a security group or firewall, add an inbound rule:
    • Protocol: UDP
    • Port: 1194
    • Source: your IP (or 0.0.0.0/0 if needed).

If you also run ufw or similar on the VM:

textcopy
ufw allow 1194/udp

5. Build a .ovpn profile for Windows

On the Debian VM, create /root/client1.ovpn (replace YOUR_PUBLIC_IP with the VM’s public IP or DNS):

textcopy
VPN_IP="YOUR_PUBLIC_IP"
cat >/root/client1.ovpn <<EOF
client
dev tun
proto udp
remote $VPN_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
auth SHA256
key-direction 1
verb 3

<ca>
$(cat /etc/openvpn/server/ca.crt)
</ca>
<cert>
$(cat /etc/openvpn/server/issued/client1.crt)
</cert>
<key>
$(cat /etc/openvpn/server/private/client1.key)
</key>
<tls-crypt>
$(cat /etc/openvpn/server/ta.key)
</tls-crypt>
EOF

Copy client1.ovpn to your Windows 10 machine (via scp, WinSCP, or another secure method).

Example from Windows PowerShell (if SSH reachable):

powershellcopy
scp root@YOUR_PUBLIC_IP:/root/client1.ovpn C:\Users\YourUser\Downloads\

6. Install OpenVPN client on Windows 10 and connect

  1. Download and install the official OpenVPN Community client (.msi) for Windows 10 from OpenVPN’s site.
  2. After install, copy client1.ovpn into:
  • C:\Users\YourUser\OpenVPN\config\
  1. Right‑click the “OpenVPN GUI” icon, select “Run as administrator”.
  2. In the tray, right‑click the OpenVPN icon → select client1 → Connect.
  3. Once connected, visit https://whatismyipaddress.com/ to confirm your public IP shows as the VM’s Australian IP.