Debian 11 Set Up OpenVPN Server In 5 Minutes

Debian 11 Set Up OpenVPN Server In 5 Minutes

To set up an OpenVPN server on Debian 11 in about 5 minutes, follow these steps:

  1. Install the OpenVPN package:
refer t‮tual:o‬turi.com
sudo apt-get update
sudo apt-get install openvpn
  1. Generate the necessary SSL certificates and keys. For simplicity, you can use the easy-rsa tool included with the OpenVPN package:
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:

  1. ca.crt: The certificate authority (CA) certificate.

  2. server.crt: The server certificate.

  3. server.key: The server private key.

  4. dh2048.pem: The Diffie-Hellman parameters file.

  5. 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
  1. Enable IP forwarding:
sudo nano /etc/sysctl.conf

Uncomment the following line:

net.ipv4.ip_forward=1

Save the file and apply the changes:

sudo sysctl -p
  1. Set up the firewall to allow OpenVPN traffic:
sudo apt-get install ufw
sudo ufw allow ssh
sudo ufw allow 1194/udp
sudo ufw enable
  1. Start the OpenVPN server:
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.
Created Time:2017-10-28 14:02:24  Author:lautturi