docs / linux / openvpn
openVPN
1. Install OpenVPN and Easy-RSA on Debian
On harley:
apt update
apt -y install openvpn easy-rsa iptablesThis 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:
cd /usr/share/easy-rsa
./easyrsa init-pki
./easyrsa build-caCreate server cert/key:
./easyrsa build-server-full server1 nopassCreate client cert/key:
./easyrsa build-client-full client1 nopassGenerate Diffie‑Hellman and TLS key:
./easyrsa gen-dh
openvpn --genkey secret ./pki/ta.keyCopy required files to OpenVPN server directory:
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:
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
EOFThis sets up a simple tun‑based VPN on UDP 1194 with full‑tunnel routing through the VM.
Enable IP forwarding:
sed -i 's/^#\?net.ipv4.ip_forward.*/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sysctl -pSet iptables NAT so VPN clients go out via the VM’s public interface (assume eth0; adjust if different):
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 ACCEPTPersist iptables:
apt -y install iptables-persistent
netfilter-persistent saveStart and enable OpenVPN:
systemctl enable openvpn-server@server1
systemctl start openvpn-server@server1
systemctl status openvpn-server@server14. 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:
ufw allow 1194/udp5. 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):
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>
EOFCopy client1.ovpn to your Windows 10 machine (via scp, WinSCP, or another secure method).
Example from Windows PowerShell (if SSH reachable):
scp root@YOUR_PUBLIC_IP:/root/client1.ovpn C:\Users\YourUser\Downloads\6. Install OpenVPN client on Windows 10 and connect
- Download and install the official OpenVPN Community client (
.msi) for Windows 10 from OpenVPN’s site. - After install, copy
client1.ovpninto:
C:\Users\YourUser\OpenVPN\config\