Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[OpenVPN] How to install OpenVPN system

Posted on November 15, 2022January 20, 2026 By nim No Comments on [OpenVPN] How to install OpenVPN system

Phần này thì mình sẽ hướng dẫn cách setup một hệ thống VPN tại gia.

Contents

Toggle
  • 1) Install OpenVPN Server
  • 2) OpenVPN Client
    • 2.1) Create OpenVPN Client.
    • 2.2) Configure OpenVPN on Ubuntu desktop
    • 2.4) Configure OpenVPN on Ubuntu server (only command not UI)
  • 3) Configure OpenVPN
    • 3.1) Not Allowing all traffic of clients to go through the OpenVPN Server
      • with Ubuntu
    • 3.2) Use Oauthen to log in via OpenVPN
  • 4) Remove the user on OpenVPN.

1) Install OpenVPN Server

Hiện tại mình cài đặt trên ubuntu.

curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh
chmod +x openvpn-install.sh

./openvpn-install.sh

Chạy script Setup OpenVPN server.

root@ip-10-195-48-68:~# ./openvpn-install.sh interactive

=== OpenVPN Installer ===

The git repository is available at: https://github.com/angristan/openvpn-install
I need to ask you a few questions before starting the setup.
You can leave the default options and just press enter if you are okay with them.

Detecting server IP addresses...
  IPv4 address detected: 10.195.48.68
  No IPv6 address detected

What IP version should clients use to connect to this server?
   1) IPv4
   2) IPv6
Endpoint type [1-2]: 1

Server listening IPv4 address:
IPv4 address: 10.195.48.68

It seems this server is behind NAT. What is its public IPv4 address or hostname?
We need it for the clients to connect to the server.
Public IPv4 address or hostname: dr-strange.nimtechnology.com

What IP versions should VPN clients use?
This determines both their VPN addresses and internet access through the tunnel.
   1) IPv4 only
   2) IPv6 only
   3) Dual-stack (IPv4 + IPv6)
Client IP versions [1-3]: 1

IPv4 VPN subnet:
   1) Default: 10.8.0.0/24
   2) Custom
IPv4 subnet choice [1-2]: 1

What port do you want OpenVPN to listen to?
   1) Default: 1194
   2) Custom
   3) Random [49152-65535]
Port choice [1-3]: 443
Port choice [1-3]: 12
Port choice [1-3]: 2
Custom port [1-65535]: 443

What protocol do you want OpenVPN to use?
UDP is faster. Unless it is not available, you shouldn't use TCP.
   1) UDP
   2) TCP
Protocol [1-2]: 2

What DNS resolvers do you want to use with the VPN?
   1) Current system resolvers (from /etc/resolv.conf)
   2) Self-hosted DNS Resolver (Unbound)
   3) Cloudflare (Anycast: worldwide)
   4) Quad9 (Anycast: worldwide)
   5) Quad9 uncensored (Anycast: worldwide)
   6) FDN (France)
   7) DNS.WATCH (Germany)
   8) OpenDNS (Anycast: worldwide)
   9) Google (Anycast: worldwide)
   10) Yandex Basic (Russia)
   11) AdGuard DNS (Anycast: worldwide)
   12) NextDNS (Anycast: worldwide)
   13) Custom
DNS [1-13]: 9

Do you want to allow a single .ovpn profile to be used on multiple devices simultaneously?
Note: Enabling this disables persistent IP addresses for clients.
Allow multiple devices per client? [y/n]: n

Do you want to customize the tunnel MTU?
   MTU controls the maximum packet size. Lower values can help
   with connectivity issues on some networks (e.g., PPPoE, mobile).
   1) Default (1500) - works for most networks
   2) Custom
MTU choice [1-2]: 1

Choose the authentication mode:
   1) PKI (Certificate Authority) - Traditional CA-based authentication (recommended for larger setups)
   2) Peer Fingerprint - Simplified WireGuard-like authentication using certificate fingerprints
      Note: Fingerprint mode requires OpenVPN 2.6+ and is ideal for small/home setups
Authentication mode [1-2]: 1

Do you want to customize encryption settings?
Unless you know what you're doing, you should stick with the default parameters provided by the script.
Note that whatever you choose, all the choices presented in the script are safe (unlike OpenVPN's defaults).
See https://github.com/angristan/openvpn-install#security-and-encryption to learn more.

Customize encryption settings? [y/n]: n

Okay, that was all I needed. We are ready to setup your OpenVPN server now.
You will be able to generate a client at the end of the installation.

Đoạn này cũng có tạo user mà mình quên chụp òi.
Không sao đi xuống bược tiếp theo

2) OpenVPN Client

2.1) Create OpenVPN Client.

Giờ bạn cần Gen a file cho client.

root@ip-10-195-92-26:~/openvpn# ./openvpn-install.sh
Welcome to OpenVPN-install!
The git repository is available at: https://github.com/angristan/openvpn-install

It looks like OpenVPN is already installed.

What do you want to do?
   1) Add a new user
   2) Revoke existing user
   3) Remove OpenVPN
   4) Exit
Select an option [1-4]: 1

Tell me a name for the client.
The name must consist of alphanumeric character. It may also include an underscore or a dash.
Client name: lac_phan

Do you want to protect the configuration file with a password?
(e.g. encrypt the private key with a password)
   1) Add a passwordless client
   2) Use a password for the client
Select an option [1-2]: 2
⚠️ You will be asked for the client password below ⚠️

Note: using Easy-RSA configuration from: /etc/openvpn/easy-rsa/vars
Using SSL: openssl OpenSSL 1.1.1  11 Sep 2018
Generating an EC private key
writing new private key to '/etc/openvpn/easy-rsa/pki/easy-rsa-26953.24JWu6/tmp.2aH2ez'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
Using configuration from /etc/openvpn/easy-rsa/pki/easy-rsa-26953.24JWu6/tmp.hxugDk
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'lac_phan'
Certificate is to be certified until Feb 17 11:48:19 2025 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

Client lac_phan added.

The configuration file has been written to /home/ubuntu/lac_phan.ovpn.
Download the .ovpn file and import it in your OpenVPN client.

2.2) Configure OpenVPN on Ubuntu desktop

Với route table trên thì tất các gói tin nếu không có trong bảng route thì sẽ đi theo default route tun0(openvpn server)

Làm sao để tắt được default route về tun0.

Edit the VPN connection -> IPv4 Settings -> Click “Routes”, and finally check “Use this connection only for resources on its network“.

Giờ show route table lại.

Quá tốt.

2.4) Configure OpenVPN on Ubuntu server (only command not UI)

Mở terminal và chạy lệnh cài đặt:

sudo apt update
sudo apt install openvpn -y

Tạo file Private Key Password

# Replace 'YOUR_KEY_PASSWORD_HERE' with your actual private key password
echo "YOUR_KEY_PASSWORD_HERE" > /root/private-key/key-pass.txt

# Set permissions so only root can read it (security best practice)
chmod 600 /root/private-key/key-pass.txt

Sau đó bạn update OpenVPN configuration file để sử dụng với file key-pass.txt

mở file:

nano thang_tran_dev.openvpn

Tiếp theo bạn add line bên dưới ở bất cứ chỗ nào:

askpass /root/private-key/key-pass.txt

Giờ bạn gõ lệnh sau để kết nối:

openvpn --config thang_tran_dev.openvpn

Hoặc bạn có thể gõ password trực tiếp:

openvpn --config client.ovpn --askpass

3) Configure OpenVPN

3.1) Not Allowing all traffic of clients to go through the OpenVPN Server

Nhu cầu sẽ là như sau:
Khi bạn truy cập vào server trong internal network của công ty thì các gói tin sẽ gửi qua VPN.
khi bạn truy cập youtube hay facebook thì không đi qua VPN

Bước 1 bạn cần ignored line dưới bằng dấu ";"

;####command dong ben duoi de all traffic of client ko dia qua openvpn-server####
;push "redirect-gateway def1 bypass-dhcp"

Tiếp theo là cấu hinhg routing và gán DNS cho client

;##########cau hinh route local nhu ben duoi###########
push "dhcp-option DNS 8.8.8.8"
push "route 8.8.8.8 255.255.255.255"
push "route 192.168.1.0 255.255.255.0"

Bạn cần chú ý chỗ này.
OpenVPN server sẽ gán dns cho client là 8.8.8.8: push "dhcp-option DNS 8.8.8.8"
Nếu client phần giả tên miến nimtechnology.com gửi một gói tin đến 8.8.8.8 port 53 và không đi qua VPN sẽ bị chặn.
Vì thế ta phải đi tạo route cho 8.8.8.8 đi qua vpn: push “route 8.8.8.8 255.255.255.255”

with Ubuntu

Với ubuntu desktop thì bạn cần làm điều này nữa:
Edit the VPN connection -> IPv4 Settings -> Click “Routes”, and finally check “Use this connection only for resources on its network“.

Để xóa default của openvpn

3.2) Use Oauthen to log in via OpenVPN

https://medium.com/@jkroepke/openvpn-sso-via-oauth2-ab2583ee8477

https://github.com/jkroepke/openvpn-auth-oauth2

4) Remove the user on OpenVPN.

Run open-install.sh script

Choose to revoke user

Remove user in /etc/openvpn/easy-rsa/pki/index.txt.

For example, I will remove hau_t_tran user by deleting the below line.

BareMetal

Post navigation

Previous Post: [Kaniko/Bitbucket/ECR] Accomplish the workflow: CI by bitbucket pipeline, Kaniko build image and push image to ECR
Next Post: [EKS]networkPlugin cni failed to set up pod “pod—xxxxx” network: add cmd: failed to assign an IP address to container

More Related Articles

[redis-cli] a few Redis commands are useful. BareMetal
[Debian 9] Mono in Debian 9 Containers BareMetal
[OpenVPN] Install OpenVPN on Ubuntu Desktop 20.04 BareMetal
[Kafka] Kafka Topics CLI Apache Kafka
[Jenkins] Install Jenkins in VM or Physical Server BareMetal
[Kubernetes] Kubernetes Scanner to find Security Vulnerability and Misconfiguration BareMetal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • Compare Instance mode (NodePort) và IP mode (Pod IP) in EKS Application Load Balancer (ALB) March 14, 2026
  • [Database] How do you choose the best database for your product. March 14, 2026
  • [Openclaw] Openclaw authentication with chatgpt March 8, 2026
  • [OpenClaw]”Openclaw suddenly became stupid” or “lost its rights.” March 8, 2026
  • [GatewayAPI/Traefik] (Error) Failed to verify certificate: x509: certificate has expired March 6, 2026

Archives

  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • AI
    • OpenClaw
  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2026 NimTechnology.