This script creates VPN Policy Routing rules for the OpenVPN Client in AsusWRT Merlin firmware. It helps fetch IP addresses that belong to domain names and saves them into the router’s policy configuration. This allows selective VPN routing based on destination IPs.
🚨 Important: This version works only with firmware 386.3+. For older firmware, use release 2.07.
- Reads domain names from
domains.txt
- Resolves them into IP addresses (with optional subnet expansion)
- Adds static entries from
static.csv
- Generates routing rules for the selected OpenVPN client
- Saves rules to file (not NVRAM)
- Optionally restarts the VPN client
vpol.py
— core logicclient1.py
,client2.py
, ... — configurations for each VPN clientdomains.txt
— list of domain names (one per line)static.csv
— static entries in format:Description,Source IP,Destination IP,Iface
domain1.com
#example.com # commented out
domain2.com
@subnetdomain.com # use @ to resolve subnets (/xx)
ADomain,0.0.0.0,194.200.22.87/26,VPN
- Entware
- Python 3
bind-tools
orbind-dig
:opkg install bind-tools
whois
utility:opkg install whois
pip
:opkg install python3-pip
- Python module
pydig
:pip install pydig
- Optionally:
git
to clone the repository
-
Clone the repo:
git clone https://github.com/loglux/merlin-vpn-routing.git cd merlin-vpn-routing
-
Edit your client config (
client1.py
, etc):local
: local IP or subnet (e.g.192.168.0.10
,192.168.0.0/24
, or0.0.0.0
)name_length
: max description length (default: 10)client
: OpenVPN client number (1–5)conf_path
: optional path todomains.txt
andstatic.csv
-
Run the script:
python3 client1.py
To run the script automatically on VPN (re)start:
-
Create or edit
/jffs/scripts/openvpn-event
:#!/bin/sh python3 /path_to_script/client1.py
-
Make it executable:
chmod a+rx /jffs/scripts/openvpn-event
⚠️ Important: comment outrules.client_restart(client)
to prevent restart loops.
Old versions of AsusWRT Merlin used NVRAM for storing rules, with strict space limits. This script no longer supports that mode. To support legacy systems, use release 2.07.
Pull requests are welcome! If you have improvements, ideas, or bug fixes, feel free to fork the repo and submit a PR.