You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Installing OpenVPN on Ubuntu 20.04 or later
4
-
description: Discover how to install OpenVPN on Ubuntu 20.04 and later versions with this detailed tutorial. Follow our step-by-step guide to set up a secure VPN connection effortlessly.
3
+
title: Installing OpenVPN on a Scaleway Instance running Ubuntu 24.04
4
+
description: Discover how to install OpenVPN on Ubuntu 24.04 and later versions with this detailed tutorial. Follow our step-by-step guide to set up a secure VPN connection effortlessly.
5
5
content:
6
-
h1: Installing OpenVPN on Ubuntu 20.04 or later
7
-
paragraph: Discover how to install OpenVPN on Ubuntu 20.04 and later versions with this detailed tutorial. Follow our step-by-step guide to set up a secure VPN connection effortlessly.
8
-
tags: vpn OpenVPN Ubuntu Bionic-Beaver
6
+
h1: Installing OpenVPN on a Scaleway Instance running Ubuntu 24.04
7
+
paragraph: Discover how to install OpenVPN on Ubuntu 24.04 and later versions with this detailed tutorial. Follow our step-by-step guide to set up a secure VPN connection effortlessly.
8
+
tags: vpn OpenVPN Ubuntu
9
9
categories:
10
10
- instances
11
11
dates:
12
-
validation: 2024-07-02
12
+
validation: 2025-01-06
13
13
posted: 2019-01-16
14
14
---
15
15
16
-
OpenVPN is an open-source software to run a virtual Private Network (VPN) to create secure point-to-point or site-to-site connections in routed or bridged configurations. The software uses a proprietary security protocol that uses SSL/TLS for key exchange.
16
+
Learn how to install and configure OpenVPN on Ubuntu 24.04 LTS with this comprehensive guide. Follow our step-by-step instructions to establish a secure VPN connection via your Scaleway Instance with ease.
17
17
18
18
<Macroid="requirements" />
19
19
20
20
- A Scaleway account logged into the [console](https://console.scaleway.com)
21
21
-[Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization
22
22
- An [SSH key](/identity-and-access-management/organizations-and-projects/how-to/create-ssh-key/)
23
-
- An [Instance](/compute/instances/how-to/create-an-instance/) running on Ubuntu 20.04 or later
23
+
- An [Instance](/compute/instances/how-to/create-an-instance/) running on Ubuntu 24.04 LTS
24
24
25
-
## Installing Easy-RSA
25
+
## Installing OpenVPN and Easy-RSA
26
26
27
-
The first step in building an OpenVPN configuration is to establish a PKI (Public Key Infrastructure). It is composed of the following elements:
28
-
29
-
- a public and private key for the server and each client
30
-
- the certification authority (CA) and the key used to identify servers as well as the client certificate
31
-
32
-
OpenVPN supports two-way certificate-based authentication, this means that the client must authenticate the server certificate and the server must authenticate the client certificate before mutual trust is established.
33
-
34
-
Both the server and the client will authenticate each other. First, the certificate needs to be signed by the certification authority (CA) then, the information in the header (common name of the certificate or the certificate type) of the authenticated certificate can be tested.
35
-
36
-
1.[Connect to your Instance](/compute/instances/how-to/connect-to-instance/) via SSH.
37
-
2. Update the package List:
27
+
1. Connect to your Instance via SSH.
28
+
```sh
29
+
root@<YOUR_INSTANCE_IP>
30
+
```
31
+
2. Update the package list and upgrade already installed packages:
38
32
```sh
39
33
apt update
40
34
apt upgrade -y
41
35
```
42
-
43
-
3. Install OpenVPN and Easy-RSA:
36
+
3. Install OpenVPN and Easy-RSA using `apt`:
44
37
```sh
45
38
apt install -y openvpn easy-rsa
46
39
```
47
40
48
-
4. Set Up the CA Directory:
41
+
## Setting up the Certificate Authority (CA)
42
+
43
+
1. Create a directory for Easy-RSA and navigate to it:
49
44
```sh
50
-
make-cadir~/openvpn-ca
45
+
mkdir -p~/openvpn-ca
51
46
cd~/openvpn-ca
52
47
```
53
-
54
-
5. Initialize the PKI:
48
+
2. Initialize the Public Key Infrastructure (PKI):
Add the following configuration, save the file and quit `nano`:
92
-
```conf
90
+
3.Add the following configuration:
91
+
```
93
92
port 1194
94
93
proto udp
95
94
dev tun
@@ -105,7 +104,7 @@ Both the server and the client will authenticate each other. First, the certific
105
104
push "dhcp-option DNS 8.8.8.8"
106
105
push "dhcp-option DNS 8.8.4.4"
107
106
keepalive 10 120
108
-
cipher AES-256-CBC
107
+
cipher AES-256-GCM
109
108
user nobody
110
109
group nogroup
111
110
persist-key
@@ -114,120 +113,158 @@ Both the server and the client will authenticate each other. First, the certific
114
113
log-append /var/log/openvpn.log
115
114
verb 3
116
115
```
116
+
Save and exit the editor.
117
117
118
-
## Setting up a Let's Encrypt TLS certificate
119
-
120
-
1. Install Certbot:
121
-
```sh
122
-
apt install -y certbot
123
-
```
124
-
125
-
2. Obtain the TLS certificate:
126
-
```sh
127
-
certbot certonly --standalone -d your_domain
128
-
```
129
-
<Messagetype="tip">
130
-
Make sure to replace `your_domain` with your actual domain name. **You need to ensure that your domain points to the IP address of your Scaleway Instance.**
131
-
</Message>
132
-
133
-
3. Configure OpenVPN to use the Let's Encrypt certificate:
134
-
- Update the `server.conf` file to use the Let's Encrypt certificate and key:
135
-
```conf
136
-
ca /etc/letsencrypt/live/your_domain/fullchain.pem
137
-
cert /etc/letsencrypt/live/your_domain/cert.pem
138
-
key /etc/letsencrypt/live/your_domain/privkey.pem
139
-
```
140
-
141
-
## Enabling IP forwarding and adjusting the firewall
118
+
## Enabling IP forwarding and configuring the firewall
142
119
143
120
1. Enable IP forwarding:
144
121
```sh
145
-
echo 1 > /proc/sys/net/ipv4/ip_forward
122
+
echo'net.ipv4.ip_forward=1'| tee -a /etc/sysctl.conf
123
+
sysctl -p
146
124
```
147
-
- Make the change permanent by editing the `sysctl.conf` file:
148
-
```sh
149
-
nano /etc/sysctl.conf
150
-
```
151
-
Uncomment the following line:
152
-
```sh
153
-
net.ipv4.ip_forward=1
154
-
```
155
-
156
-
2. Configure the firewall of the Instance (UFW):
125
+
2. Configure the firewall ([UFW](/tutorials/installation-uncomplicated-firewall/)):
157
126
```sh
158
127
ufw allow 1194/udp
159
128
ufw allow OpenSSH
160
-
ufw enable
161
129
```
162
-
163
-
Add the following rules to `before.rules` to allow forwarding:
130
+
3. Edit the UFW configuration to allow forwarding:
164
131
```sh
165
132
nano /etc/ufw/before.rules
166
133
```
167
-
Add these lines before the `*filter` line:
168
-
```sh
134
+
4.Add the following lines before the `*filter` line:
135
+
```
169
136
*nat
170
137
:POSTROUTING ACCEPT [0:0]
171
-
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
138
+
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
172
139
COMMIT
173
140
```
141
+
5. Save and exit, then reload UFW:
142
+
```sh
143
+
ufw disable
144
+
ufw enable
145
+
```
174
146
175
147
## Starting the OpenVPN server
176
148
177
-
1. Start and enable OpenVPN:
149
+
1. Start and enable the OpenVPN service:
178
150
```sh
179
151
systemctl start openvpn@server
180
152
systemctl enable openvpn@server
181
153
```
154
+
2. Check the status of the OpenVPN service:
182
155
183
-
2. Check the status of the OpenVPN server:
184
156
```sh
185
157
systemctl status openvpn@server
186
158
```
159
+
Ensure it is active and running.
187
160
188
-
## Setting up client configuration
161
+
## Generating client configuration
189
162
190
163
1. Generate client certificates:
164
+
191
165
```sh
192
-
cd~/openvpn-ca
166
+
cd/etc/openvpn/easy-rsa/
193
167
./easyrsa gen-req client1 nopass
194
168
./easyrsa sign-req client client1
195
169
```
170
+
Approve the signing request when prompted.
196
171
197
172
2. Create the client configuration file:
173
+
On your server, create a new client configuration file named `client1.ovpn`:
198
174
```sh
199
175
nano ~/client1.ovpn
200
176
```
201
-
Add the following configuration:
202
-
```conf
177
+
3.Add the following configuration in the file, replacing `your_server_ip_or_domain` with your server's IP address or domain name:
178
+
```
203
179
client
204
180
dev tun
205
181
proto udp
206
-
remote your_domain 1194
182
+
remote your_server_ip_or_domain 1194
207
183
resolv-retry infinite
208
184
nobind
209
185
persist-key
210
186
persist-tun
211
-
ca ca.crt
212
-
cert client1.crt
213
-
key client1.key
214
-
tls-auth ta.key 1
215
-
cipher AES-256-CBC
187
+
remote-cert-tls server
188
+
auth SHA256
189
+
cipher AES-256-GCM
216
190
verb 3
191
+
<ca>
192
+
-----BEGIN CERTIFICATE-----
193
+
# Insert the content of /etc/openvpn/ca.crt here
194
+
-----END CERTIFICATE-----
195
+
</ca>
196
+
<cert>
197
+
-----BEGIN CERTIFICATE-----
198
+
# Insert the content of /etc/openvpn/easy-rsa/pki/issued/client1.crt here
199
+
-----END CERTIFICATE-----
200
+
</cert>
201
+
<key>
202
+
-----BEGIN PRIVATE KEY-----
203
+
# Insert the content of /etc/openvpn/easy-rsa/pki/private/client1.key here
204
+
-----END PRIVATE KEY-----
205
+
</key>
206
+
<tls-auth>
207
+
-----BEGIN OpenVPN Static key V1-----
208
+
# Insert the content of /etc/openvpn/ta.key here
209
+
-----END OpenVPN Static key V1-----
210
+
</tls-auth>
211
+
key-direction 1
217
212
```
213
+
<Messagetype="note">
214
+
Replace the placeholder text (e.g., `# Insert the content of /etc/openvpn/ca.crt here`) with the actual contents of the respective files. You can use the `cat` command to display the contents of each file and then copy and paste them into the appropriate sections of the `client1.ovpn` file.
215
+
- For example:
216
+
```sh
217
+
cat /etc/openvpn/ca.crt
218
+
```
219
+
Copy the output and paste it between the `<ca>` and `</ca>` tags in the `client1.ovpn` file.
220
+
</Message>
218
221
219
-
3. Transfer the client configuration files to the remote (client) machine:
222
+
4. Transfer the client configuration file to the client device:
223
+
Use a secure method to transfer the `client1.ovpn` file to the device you intend to use as a client. You can use `scp` (secure copy) for this purpose:
Replace `user` with your username on the client device, `client_device_ip` with the client's IP address, and `/path/to/destination/` with the desired directory on the client device.
228
+
5. Install OpenVPN on the client device:
229
+
Ensure that the OpenVPN client is installed on your client device. Installation methods vary depending on the operating system:
230
+
231
+
-**Linux:**
232
+
```sh
233
+
apt update
234
+
apt install -y openvpn
235
+
```
236
+
237
+
-**Windows:**
238
+
239
+
Download and install the OpenVPN client from the [official website](https://openvpn.net/community-downloads/).
240
+
241
+
-**macOS:**
242
+
243
+
Download and install [Tunnelblick](https://tunnelblick.net/), a free OpenVPN client for macOS.
244
+
245
+
6. Connect to the VPN:
246
+
247
+
-**Linux:**
248
+
249
+
Use the following command to start the VPN connection:
Once connected, verify that your public IP address matches the VPN server's IP address, indicating that your internet traffic is being routed through the VPN. You can check your public IP address by visiting [WhatIsMyIP.com](https://www.whatismyip.com/) or a similar service.
260
+
261
+
Your OpenVPN server is now configured on your Ubuntu 24.04 LTS instance, and your client device is set up to connect securely.
224
262
225
-
Your OpenVPN server is now set up on your Scaleway Instance, secured with a Let's Encrypt certificate, and ready for clients to connect. Follow the client configuration steps for each device you want to connect to your VPN.
263
+
## Maintenance
226
264
227
-
<Messagetype="tip">
228
-
For ongoing maintenance, remember to renew your Let's Encrypt certificates regularly (they expire every 90 days), and you can automate this with a cron job:
For ongoing maintenance, remember to renew your Let's Encrypt certificates regularly (they expire every 90 days). You can automate this process with a cron job:
266
+
```sh
267
+
echo"0 0 1 */2 * certbot renew --quiet"| tee -a /etc/crontab
268
+
```
269
+
This cron job runs the `certbot renew` command on the first day of every second month at midnight.
0 commit comments