https://github.com/loglux/merlin-vpn-routing
This tool helps to create VPN Routing Rules for AsusWRT Merlin OpenVPN Client
https://github.com/loglux/merlin-vpn-routing
asus asus-routers asuswrt-merlin nvram python router routing routing-rules routing-tables vpn vpn-client
Last synced: about 1 year ago
JSON representation
This tool helps to create VPN Routing Rules for AsusWRT Merlin OpenVPN Client
- Host: GitHub
- URL: https://github.com/loglux/merlin-vpn-routing
- Owner: loglux
- Created: 2020-12-13T20:48:51.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-05-26T13:36:12.000Z (about 1 year ago)
- Last Synced: 2025-06-08T06:27:40.905Z (about 1 year ago)
- Topics: asus, asus-routers, asuswrt-merlin, nvram, python, router, routing, routing-rules, routing-tables, vpn, vpn-client
- Language: Python
- Homepage:
- Size: 88.9 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# merlin-vpn-routing
This script creates **VPN Policy Routing rules** for the **OpenVPN Client** in [AsusWRT Merlin firmware](https://github.com/RMerl/asuswrt-merlin.ng). 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](https://github.com/loglux/merlin-vpn-routing/releases/tag/2.07).
---
## π§ What It Does
- 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
---
## π Files
- `vpol.py` β core logic
- `client1.py`, `client2.py`, ... β configurations for each VPN client
- `domains.txt` β list of domain names (one per line)
- `static.csv` β static entries in format: `Description,Source IP,Destination IP,Iface`
### Example: `domains.txt`
```
domain1.com
#example.com # commented out
domain2.com
@subnetdomain.com # use @ to resolve subnets (/xx)
```
### Example: `static.csv`
```
ADomain,0.0.0.0,194.200.22.87/26,VPN
```
---
## π οΈ Requirements (on router)
- Entware
- Python 3
- `bind-tools` or `bind-dig`:
```sh
opkg install bind-tools
```
- `whois` utility:
```sh
opkg install whois
```
- `pip`:
```sh
opkg install python3-pip
```
- Python module `pydig`:
```sh
pip install pydig
```
- Optionally: `git` to clone the repository
---
## π Usage
1. Clone the repo:
```sh
git clone https://github.com/loglux/merlin-vpn-routing.git
cd merlin-vpn-routing
```
2. Edit your client config (`client1.py`, etc):
- `local`: local IP or subnet (e.g. `192.168.0.10`, `192.168.0.0/24`, or `0.0.0.0`)
- `name_length`: max description length (default: 10)
- `client`: OpenVPN client number (1β5)
- `conf_path`: optional path to `domains.txt` and `static.csv`
3. Run the script:
```sh
python3 client1.py
```
---
## π
Auto-start with VPN
To run the script automatically on VPN (re)start:
1. Create or edit `/jffs/scripts/openvpn-event`:
```sh
#!/bin/sh
python3 /path_to_script/client1.py
```
2. Make it executable:
```sh
chmod a+rx /jffs/scripts/openvpn-event
```
> β οΈ Important: comment out `rules.client_restart(client)` to prevent restart loops.
---
## π Compatibility Note (Pre-386.3 Firmware)
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](https://github.com/loglux/merlin-vpn-routing/releases/tag/2.07).
---
## π References
- [Policy-based Routing β AsusWRT Wiki](https://github.com/RMerl/asuswrt-merlin.ng/wiki/Policy-based-routing)
- [User Scripts β AsusWRT Wiki](https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts)
---
## π Contributing
Pull requests are welcome! If you have improvements, ideas, or bug fixes, feel free to fork the repo and submit a PR.