To set up an OpenVPN server on Debian 11 in about 5 minutes, follow these steps:
sudo apt-get update sudo apt-get install openvpn
sudo make-cadir /etc/openvpn/easy-rsa cd /etc/openvpn/easy-rsa
Then, edit the vars
file to set the necessary variables:
nano vars
Set the KEY_COUNTRY
, KEY_PROVINCE
, KEY_CITY
, KEY_ORG
, and KEY_EMAIL
variables to your desired values. Then, run the following commands to generate the certificates and keys:
source vars ./clean-all ./build-ca ./build-key-server server ./build-dh
The above commands will generate the following files:
ca.crt
: The certificate authority (CA) certificate.
server.crt
: The server certificate.
server.key
: The server private key.
dh2048.pem
: The Diffie-Hellman parameters file.
Create the OpenVPN configuration file:
sudo nano /etc/openvpn/server.conf
Add the following lines to the file, replacing the placeholder values with your own values:
local YOUR_SERVER_IP port 1194 proto udp dev tun ca /etc/openvpn/easy-rsa/keys/ca.crt cert /etc/openvpn/easy-rsa/keys/server.crt key /etc/openvpn/easy-rsa/keys/server.key dh /etc/openvpn/easy-rsa/keys/dh2048.pem server 10.8.0.0 255.255.255.0 push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" keepalive 10 120 comp-lzo user nobody group nogroup persist-key persist-tun status openvpn-status.log verb 3
sudo nano /etc/sysctl.conf
Uncomment the following line:
net.ipv4.ip_forward=1
Save the file and apply the changes:
sudo sysctl -p
sudo apt-get install ufw sudo ufw allow ssh sudo ufw allow 1194/udp sudo ufw enable
sudo systemctl start openvpn-server@OVPNserver2020.service sudo systemctl enable openvpn-server@OVPNserver2020.service # Where OVPNserver2020.conf is the name of your server configuration file.