Setting up an OpenVPN server on Ubuntu 20.04 LTS can be done in a few simple steps. Here is an overview of the process:
- Install OpenVPN by running the command:
sudo apt install openvpn
- Create a directory to store the server configuration files by running the command:
sudo mkdir /etc/openvpn/server
- Generate the necessary certificate and key files by running the command:
sudo apt install easy-rsa
sudo make-cadir /etc/openvpn/server
- Set up the server configuration by creating a new file
/etc/openvpn/server.conf
and adding the following lines:
port 1194
proto udp
dev tun
ca /etc/openvpn/server/ca.crt
cert /etc/openvpn/server/server.crt
key /etc/openvpn/server/server.key
dh /etc/openvpn/server/dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
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
You can change the port number and protocols as per your need, and also set up your own DNS server instead of the Google’s DNS servers.
- Start the OpenVPN service by running the command:
sudo systemctl start openvpn@server
- Enable the OpenVPN service to start automatically at boot by running the command:
sudo systemctl enable openvpn
- Check the status of the OpenVPN service by running the command:
sudo systemctl status openvpn
- Create client configuration files for each device that will connect to the OpenVPN server. You can create a new file for each client, for example
client1.ovpn
and add the following lines:
client
dev tun
proto udp
remote <your-server-ip> 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
comp-lzo
verb 3
- On the client side, you can install the OpenVPN client software, import the client configuration files and connect to the OpenVPN server.
It’s important to note that, the above-explained steps are a basic setup and it should be used only for testing or in a secure environment. It is recommended to use a more secure setup with stronger encryption and authentication methods, also you should configure firewall rules to protect the OpenVPN server.