Setup OpenVPN server with OpenWrt (2024)

You should already install OpenWrt in your router. If not, follow the steps in https://medium.com/@tzuhaochung/install-openwrt-on-your-router-629ea869d67b

In default, there is no OpenVPN function in OpenWrt, you need to download it. ( Of course., it let you customize your router).

Open the command lin (CMD) or Power Shell if you are using Windows machine, promt below command to connect to your router

ssh root@192.168.1.1
Setup OpenVPN server with OpenWrt (1)

Run below commands to install required packages for OpenVPN

opkg update
opkg install openvpn-openssl openvpn-easy-rsa

Run these commands to setup some parameters that we would use later. It defines the folder and IP address we will use to setup VPN server.

VPN_DIR="/etc/openvpn"
VPN_PKI="/etc/easy-rsa/pki"
VPN_PORT="1194"
VPN_PROTO="udp"
VPN_POOL="192.168.8.0 255.255.255.0"
VPN_DNS="${VPN_POOL%.* *}.1"
VPN_DN="$(uci -q get dhcp.@dnsmasq[0].domain)"

NET_FQDN="$(uci -q get ddns.@service[0].lookup_host)"
. /lib/functions/network.sh
network_flush_cache
network_find_wan NET_IF
network_get_ipaddr NET_ADDR "${NET_IF}"
if [ -n "${NET_FQDN}" ]
then VPN_SERV="${NET_FQDN}"
else VPN_SERV="${NET_ADDR}"
fi

OpenVPN server requires certificate and key to establish the connection with client. Run the commands in your command line to create the stuff.

Define parameters

cat << EOF > /etc/profile.d/easy-rsa.sh
export EASYRSA_PKI="${VPN_PKI}"
export EASYRSA_TEMP_DIR="/tmp"
export EASYRSA_CERT_EXPIRE="3650"
export EASYRSA_BATCH="1"
EOF
. /etc/profile.d/easy-rsa.sh

Initialize the target folder

easyrsa init-pki

Generate DN parameter. Note that this will take long time. For Netgear R6260 my case, it take 10 minutes.

easyrsa gen-dh

You can’t interrupt the process or disconnect with router. If it happenes, remove the file to do above command again.

rm /etc/easy-rsa/pki/dh.pem

Create CA

easyrsa build-ca nopass

Generate server keys, certificate for server and client

easyrsa build-server-full server nopass

openvpn --genkey tls-crypt-v2-server ${EASYRSA_PKI}/private/server.pem
easyrsa build-client-full client nopass

openvpn --tls-crypt-v2 ${EASYRSA_PKI}/private/server.pem \
--genkey tls-crypt-v2-client ${EASYRSA_PKI}/private/client.pem

Execute below commands to allow connection can access via VPN port.

uci rename firewall.@zone[0]="lan"
uci rename firewall.@zone[1]="wan"
uci del_list firewall.lan.device="tun+"
uci add_list firewall.lan.device="tun+"
uci -q delete firewall.ovpn
uci set firewall.ovpn="rule"
uci set firewall.ovpn.name="Allow-OpenVPN"
uci set firewall.ovpn.src="wan"
uci set firewall.ovpn.dest_port="${VPN_PORT}"
uci set firewall.ovpn.proto="${VPN_PROTO}"
uci set firewall.ovpn.target="ACCEPT"
uci commit firewall
/etc/init.d/firewall restart
umask go=
VPN_DH="$(cat ${VPN_PKI}/dh.pem)"
VPN_CA="$(openssl x509 -in ${VPN_PKI}/ca.crt)"
ls ${VPN_PKI}/issued \
| sed -e "s/\.\w*$//" \
| while read -r VPN_ID
do
VPN_TC="$(cat ${VPN_PKI}/private/${VPN_ID}.pem)"
VPN_KEY="$(cat ${VPN_PKI}/private/${VPN_ID}.key)"
VPN_CERT="$(openssl x509 -in ${VPN_PKI}/issued/${VPN_ID}.crt)"
VPN_EKU="$(echo "${VPN_CERT}" | openssl x509 -noout -purpose)"
case ${VPN_EKU} in
(*"SSL server : Yes"*)
VPN_CONF="${VPN_DIR}/${VPN_ID}.conf"
cat << EOF > ${VPN_CONF} ;;
user nobody
group nogroup
dev tun
port ${VPN_PORT}
proto ${VPN_PROTO}
server ${VPN_POOL}
topology subnet
client-to-client
keepalive 10 60
persist-tun
persist-key
push "dhcp-option DNS ${VPN_DNS}"
push "dhcp-option DOMAIN ${VPN_DN}"
push "redirect-gateway def1"
push "persist-tun"
push "persist-key"
<dh>
${VPN_DH}
</dh>
EOF
(*"SSL client : Yes"*)
VPN_CONF="${VPN_DIR}/${VPN_ID}.ovpn"
cat << EOF > ${VPN_CONF} ;;
user nobody
group nogroup
dev tun
nobind
client
remote ${VPN_SERV} ${VPN_PORT} ${VPN_PROTO}
auth-nocache
remote-cert-tls server
EOF
esac
cat << EOF >> ${VPN_CONF}
<tls-crypt-v2>
${VPN_TC}
</tls-crypt-v2>
<key>
${VPN_KEY}
</key>
<cert>
${VPN_CERT}
</cert>
<ca>
${VPN_CA}
</ca>
EOF
done
/etc/init.d/openvpn restart
ls ${VPN_DIR}/*.ovpn

To start VPN Server

/etc/init.d/openvpn restart

To stop VPN Server

/etc/init.d/openvpn stop

To check status VPN Server

/etc/init.d/openvpn status

After complete, you can find the OpenVPN client file under the path

ls ${VPN_DIR}/*.ovpn

/etc/openvpn/client.ovpn

Use command to view and copy content a new file in your local machine. Or you can use FTP or SCP service to download the file from router into your

cat /etc/openvpn/client.ovpn

Provide the file client.ovpn to the user who will connec to your VPN server.

Setup OpenVPN server with OpenWrt (2024)

FAQs

Setup OpenVPN server with OpenWrt? ›

Click on Network in the top bar and then on Interfaces to open the interfaces configuration page. Fill the form with the following values: Name = OpenVPN , Protocol = Unmanaged , Interface = tun0 . Then click on Create Interface.

How to configure OpenVPN on OpenWRT? ›

Click on Network in the top bar and then on Interfaces to open the interfaces configuration page. Fill the form with the following values: Name = OpenVPN , Protocol = Unmanaged , Interface = tun0 . Then click on Create Interface.

Does OpenWRT support VPN server? ›

Routers with OpenWRT firmware have been reported to support VPNs like NordVPN.

How to create OpenVPN server? ›

The purpose of this article is to provide the know-how needed to configure a working OpenVPN server on a Windows PC.
  1. Step 1: installing OpenVPN software. ...
  2. Step 2: preparing EasyRSA. ...
  3. Step 3: generating certificates and keys. ...
  4. Step 4: OpenVPN server configuration. ...
  5. Step 5: configuring clients. ...
  6. Step 6: launching the server.

How to setup OpenVPN server Docker? ›

Set Up OpenVPN on Docker Manually
  1. Step 1: Create Data Volume. ...
  2. Step 2: Create OpenVPN Container. ...
  3. Step 3: Set up Certificates. ...
  4. Step 4: Start OpenVPN Container. ...
  5. Step 5: Generate Client Certificate. ...
  6. Step 6: Compile OpenVPN Configuration File. ...
  7. Step 7: Connect to Server.
Sep 14, 2023

Which is more secure, WireGuard or OpenVPN? ›

While WireGuard is generally faster, OpenVPN provides heavier security.

What is the best VPN client for OpenWrt? ›

7 Best VPNs for OpenWrt so you can protect all your devices
  • NordVPN Our first choice. ...
  • Surfshark The top budget VPN for Openwrt users. ...
  • ExpressVPN Quick speeds, 90+ server locations, and custom firmware for routers. ...
  • PrivateVPN In-house support staff can walk you through the installation process.
Jul 21, 2023

Can I make my router a VPN server? ›

How to set up a VPN on your router
  1. Log into your router. You can access your router configuration panel by entering your router's IP address in your browser's URL bar. ...
  2. Look for the “VPN client” tab in the advanced settings of your router. ...
  3. Follow your VPN client's guidelines to set up the VPN on your router.
Jan 12, 2024

How to setup WireGuard VPN server on OpenWrt? ›

We will cover the following steps:
  1. Get your key pair.
  2. I have a key pair.
  3. I don't have a key pair.
  4. Choose a Surfshark server.
  5. Install and configure WireGuard.
  6. Configure the interface.
  7. Configure the VPN Zone.
  8. Ensure the connection is successful.
Jan 26, 2024

How do I deploy an OpenVPN server? ›

  1. Step 1 — Installing OpenVPN and Easy-RSA.
  2. Step 2 — Creating a PKI for OpenVPN.
  3. Step 3 — Creating an OpenVPN Server Certificate Request and Private Key.
  4. Step 4 — Signing the OpenVPN Server's Certificate Request.
  5. Step 5 — Configuring OpenVPN Cryptographic Material.
  6. Step 6 — Generating a Client Certificate and Key Pair.
May 6, 2020

How do I host OpenVPN? ›

Sign in to the CloudConnexa administration portal at https://cloud.openvpn.com .
  1. Navigate to Hosts.
  2. Click Add Host. You may click Skip Wizard and Add a Host using Form-based Configuration.
  3. Enter a Host Name.
  4. (Optional) Enter the Host Domain Name (ex: myhost.example.com). Note. ...
  5. (Optional) Enter a Description.

How do I manually start OpenVPN server? ›

To run OpenVPN, you can: Right click on an OpenVPN configuration file (.ovpn) and select Start OpenVPN on this configuration file. Once running, you can use the F4key to exit. Once running in a command prompt window, OpenVPN can be stopped by the F4 key.

What is an OpenVPN access server? ›

OpenVPN Access Server delivers an enterprise VPN solution for businesses around the globe. With this single solution, organizations can protect data communications, secure IoT resources, and provide encrypted remote access to on-premise, hybrid, and public cloud resources.

How to setup OpenVPN with Active Directory? ›

Tip
  1. Sign in to the Admin Web UI with the openvpn administrative account.
  2. Click Authentication > LDAP.
  3. Enter the address of your LDAP server, the details of your bind user, and the base DN of your LDAP directory.
  4. Set Enable LDAP authentication to Yes.
  5. Click Save Settings and Update Running Server.

What port does OpenVPN use? ›

The OpenVPN daemons and web services affect each other. By default, Access Server comes configured with OpenVPN daemons listening on UDP port 1194 and TCP port 443. Access Server's web services also use TCP 443 for the web interfaces.

How do I start OpenVPN with config? ›

On Windows, you can start OpenVPN by right clicking on an OpenVPN configuration file (. ovpn file) and selecting "Start OpenVPN on this config file". Once running in this fashion, several keyboard commands are available: F1 -- Conditional restart (doesn't close/reopen TAP adapter)

How do I import OVPN files into OpenWRT? ›

Navigate to VPN → OpenVPN.
  1. Under OVPN Configuration file upload, enter OVPN as Instance name, and select the configuration file you downloaded in Step 1 of this guide. Click Upload.
  2. On the newly-created OpenVPN configuration, click Edit.
  3. Click Create interface.
  4. Navigate to Networking → Firewall. ...
  5. Click Save & Apply.
Nov 8, 2021

How to setup OpenVPN client on router? ›

Case 1: Only one router in the home network map
  1. Log in to the web-based interface of the router. ...
  2. Go to Advanced > VPN Server > OpenVPN, and select Enable VPN Server. ...
  3. Select the Service Type (communication protocol) for OpenVPN Server: UDP, TCP.
Jun 27, 2022

How do I configure and configure OpenVPN on my DD WRT router? ›

Using the Web Interface, go to the "Services" tab and then the "VPN" tab (for older versions of dd-wrt go to the "Administration" tab and then the "Services" sub-tab). Enable OpenVPN Daemon or OpenVPN Client. If further options do not appear, click Apply Settings. Click Apply Settings.

References

Top Articles
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 5473

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.