Keenetic / NetCraze
On Keenetic and NetCraze, keen-pbr is installed from Entware. Entware is a set of extra programs for the router, installed on a USB drive. Do use a USB drive: that way installing packages and running programs does not wear out the router’s built-in memory. You install programs from Entware with the opkg command over SSH.
Install Entware
If Entware is already on your router, go to the next step.
Installation instructions are in the Keenetic or NetCraze knowledge base:
- Find the page for your router model.
- Search for “Installing the Entware repository on a USB drive”.
- Follow the instructions step by step. They also explain how to connect to the router over SSH, which you need later.
Install KeeneticOS components
Open the router’s components page in a browser: http://my.keenetic.net/system/osAndUpdates (or http://<router-IP>/system/osAndUpdates). Install these components:
- Network Functions / IPv6 Protocol. NDMS 5.0 and newer do not have this item: the protocol is built in.
- OPKG Packages / Open Package System Support
- OPKG Packages / Netfilter Subsystem Kernel Modules
- OPKG Packages / Xtables-addons Extension Package for Netfilter
- Utilities and services / DNS-over-TLS proxy (optional, but recommended)
- Utilities and services / DNS-over-HTTPS proxy (optional, but recommended)
Turn on DNS encryption (recommended)
DoH (DNS-over-HTTPS) and DoT (DNS-over-TLS) send DNS requests in encrypted form. Your provider cannot tamper with the answers, so sites open at the correct addresses.
How to set it up: DoH and DoT proxy servers for DNS requests encryption.
Install keen-pbr
- Open the keen-pbr repository page.
- On the left, select the OS Keenetic / NetCraze, the OS version current (Keenetic has only this one) and the architecture of your router.
- To find the architecture, run
opkg print-architectureover SSH.
- To find the architecture, run
- Connect to the router over SSH and run the commands from the repository page, in order.
- Install the package:
bash
opkg install keen-pbr # version without the web UI and API: # opkg install keen-pbr-headless
At the end of the installation you will see Installation complete! and the web UI address.
keen-pbr-headless takes less space: about 1.2 MB instead of 2.8 MB. It has no web UI and no API, so you configure it through the config file. If in doubt, install the regular keen-pbr.Check that the service is running
Run over SSH:
/opt/etc/init.d/S80keen-pbr statusIf everything is fine, you will see alive:
~ # /opt/etc/init.d/S80keen-pbr status
Checking keen-pbr... alive.If it says dead instead, open Service does not start.
Open the web UI
Open http://my.keenetic.net:12121 in your browser. If the address does not open, enter http://<router-ip>:12121, for example http://192.168.1.1:12121.
The headless version has no web UI. Its configuration is the file /opt/etc/keen-pbr/config.json.
Set up your first rules
Go to the Quick Start page and open the Web UI tab. If you installed keen-pbr-headless, open the JSON tab.
Service commands
| Action | Command |
|---|---|
| Start | /opt/etc/init.d/S80keen-pbr start |
| Restart | /opt/etc/init.d/S80keen-pbr restart |
| Check that it works | /opt/etc/init.d/S80keen-pbr status |
RAW or mangle
You do not need to change anything at first: keen-pbr picks a suitable mode itself. This section helps if you assign policies to devices in Keenetic Connection Policies, or if connections through the VPN sometimes drop.
keen-pbr marks the packets that must go to a VPN or another channel. This mark is called fwmark. It can be set in one of two firewall tables of the router: RAW or mangle.
| Mode | Benefit | Trade-off |
|---|---|---|
| RAW (default when the router supports it) | Keenetic does not rebuild this table, so keen-pbr rules work without gaps. Gaming sessions and other long connections do not break, and traffic does not bypass the VPN. | Policies from Connection Policies > Policy Bindings run later and overwrite the keen-pbr mark. RAW therefore works only for devices with the Default policy. |
| mangle | keen-pbr runs after Keenetic policies and can change the route for devices with any policy. | Keenetic rebuilds the mangle table (about every five minutes, and also, for example, after a DHCP lease renewal). During that time keen-pbr rules are missing. A few packets can take the ordinary route, and a sensitive connection such as a gaming session can break. |
More about how Keenetic rebuilds iptables: Keenetic Community forum thread.
The mode is chosen separately for IPv4 and IPv6. The system log of the router shows which one was chosen after the service starts:
IPv4 raw PREROUTING available
WARNING: IPv6 raw PREROUTING unavailable: ...To always use mangle, add this line to /opt/etc/keen-pbr/defaults:
KEEN_PBR_RAW_PREROUTING="disable"and restart the service:
/opt/etc/init.d/S80keen-pbr restartThe other values of this setting are described in CLI.
Separate DNS servers for lists (dnsmasq)
keen-pbr does not need dnsmasq for routing. Install it only if you want to send the domains of some lists to separate DNS servers, or set your own main DNS servers. See Do I need dnsmasq?.
Install dnsmasq
- Install the package over SSH. Entware has only
dnsmasq-full; the namednsmasqresolves to it:bashopkg install dnsmasq-full - To apply the recommended dnsmasq settings, run this over SSH:
It replacesbash
/opt/usr/lib/keen-pbr/dnsmasq-hook.sh install-recommended-config/opt/etc/dnsmasq.confand saves the previous file as/opt/etc/dnsmasq.conf.backup-keenpbr.my.keenetic.netkeeps resolving. - Open http://my.keenetic.net/a (if the link does not open, use
http://<router-ip>/a) and run:Run these commands only after dnsmasq is installed. Without dnsmasq,opkg dns-override system configuration savedns-overrideleaves the LAN without DNS. - Reboot the router. This is required: without a reboot LAN clients keep using the built-in DNS proxy, and dnsmasq does not get their queries.
- In the Web UI, open General > Settings > Local DNS server management and turn on Manage dnsmasq configuration. The DNS servers and DNS rules pages become available.
Return to how it was
Do the steps in this order, so the LAN keeps DNS all the time:
- In the Web UI, turn off Manage dnsmasq configuration (General > Settings > Local DNS server management) and apply the config. dnsmasq keeps running and uses the servers from
/opt/etc/keen-pbr/dnsmasq-fallback.conf, so DNS keeps working. If dnsmasq has servers of its own, these are added to them; clear the file to avoid that. - In the web CLI (http://my.keenetic.net/a) run:
no opkg dns-override system configuration save - Reboot the router. This is required.
- Remove the package:
bash
opkg remove dnsmasq-full
To keep dnsmasq with its previous settings after install-recommended-config, put the saved file back instead of removing the package:
cp /opt/etc/dnsmasq.conf.backup-keenpbr /opt/etc/dnsmasq.conf
/opt/etc/init.d/S56dnsmasq restart