You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

890 lines
41 KiB

  1. # VPN Policy-Based Routing
  2. ## Description
  3. This service allows you to define rules (policies) for routing traffic via WAN or your L2TP, Openconnect, OpenVPN, PPTP or Wireguard tunnels. Policies can be set based on any combination of local/remote ports, local/remote IPv4 or IPv6 addresses/subnets or domains. This service supersedes the ```VPN Bypass``` available on [GitHub](https://github.com/openwrt/packages/blob/master/net/vpnbypass/files/README.md)/[jsDelivr](https://cdn.jsdelivr.net/gh/openwrt/packages@master/net/vpnbypass/files/README.md) service, by supporting IPv6 and by allowing you to set explicit rules not just for WAN interface (bypassing OpenVPN tunnel), but for L2TP, Openconnect, OpenVPN, PPTP and Wireguard tunnels as well.
  4. ## Features
  5. ### Gateways/Tunnels
  6. - Any policy can target either WAN or a VPN tunnel interface.
  7. - L2TP tunnels supported (with protocol names l2tp\*).
  8. - Openconnect tunnels supported (with protocol names openconnect\*).
  9. - OpenVPN tunnels supported (with device names tun\* or tap\*).<sup>[1](#footnote1)</sup> <sup>[2](#footnote2)</sup>
  10. - PPTP tunnels supported (with protocol names pptp\*).
  11. - Wireguard tunnels supported (with protocol names wireguard\*).
  12. ### IPv4/IPv6/Port-Based Policies
  13. - Policies based on local names, IPs or subnets. You can specify a single IP (as in ```192.168.1.70```) or a local subnet (as in ```192.168.1.81/29```) or a local device name (as in ```nexusplayer```). IPv6 addresses are also supported.
  14. - Policies based on local ports numbers. Can be set as an individual port number (```32400```), a range (```5060-5061```), a space-separated list (```80 8080```) or a combination of the above (```80 8080 5060-5061```). Limited to 15 space-separated entries per policy.
  15. - Policies based on remote IPs/subnets or domain names. Same format/syntax as local IPs/subnets.
  16. - Policies based on remote ports numbers. Same format/syntax and restrictions as local ports.
  17. - You can mix the IP addresses/subnets and device (or domain) names in one field separating them by space (like this: ```66.220.2.74 he.net tunnelbroker.net```).
  18. - See [Policy Options](#policy-options) section for more information.
  19. ### Domain-Based Policies
  20. - Policies based on (remote) domain names can be processed in different ways, please review the [Policy Options](#policy-options) section and [Footnotes/Known Issues](#footnotesknown-issues) section, specifically [<sup>#5</sup>](#footnote5) and any other information in that section relevant to domain-based routing/DNS.
  21. ### Physical Device Policies
  22. - Policies based on a local physical device (like a specially created wlan), please review the [Policy Options](#policy-options) section and [Footnotes/Known Issues](#footnotesknown-issues) section, specifically [<sup>#6</sup>](#footnote6) and any other information in that section relevant to handling physical device.
  23. ### DSCP Tag-Based Policies
  24. You can also set policies for traffic with specific DSCP tag. On Windows 10, for example, you can mark traffic from specific apps with DSCP tags (instructions for tagging specific app traffic in Windows 10 can be found [here](http://serverfault.com/questions/769843/cannot-set-dscp-on-windows-10-pro-via-group-policy)).
  25. ### Custom User Files
  26. If the custom user file includes are set, the service will load and execute them after setting up ip tables and ipsets and processing policies. This allows, for example, to add large numbers of domains/IP addresses to ipsets without manually adding all of them to the config file.
  27. Two example custom user-files are provided: ```/etc/vpn-policy-routing.aws.user``` and ```/etc/vpn-policy-routing.netflix.user```. They are provided to pull the AWS and Netflix IP addresses into the ```wan``` ipset respectively.
  28. ### Strict Enforcement
  29. - Supports strict policy enforcement, even if the policy interface is down -- resulting in network being unreachable for specific policy (enabled by default).
  30. ### Use DNSMASQ ipset
  31. - Service can be set to utilize ```dnsmasq```'s ```ipset``` support, which requires the ```dnsmasq-full``` package to be installed (see [How to install dnsmasq-full](#how-to-install-dnsmasq-full)). This significantly improves the start up time because ```dnsmasq``` resolves the domain names and adds them to appropriate ```ipset``` in background. Another benefit of using ```dnsmasq```'s ```ipset``` is that it also automatically adds third-level domains to the ```ipset```: if ```domain.com``` is added to the policy, this policy will affect all ```*.domain.com``` subdomains. This also works for top-level domains as well, a policy targeting the ```at``` for example, will affect all the ```*.at``` domains.
  32. - Please review the [Footnotes/Known Issues](#footnotesknown-issues) section, specifically [<sup>#5</sup>](#footnote5) and any other information in that section relevant to domain-based routing/DNS.
  33. ### Customization
  34. - Can be fully configured with ```uci``` commands or by editing ```/etc/config/vpn-policy-routing``` file.
  35. - Has a companion package (```luci-app-vpn-policy-routing```) so policies can be configured with Web UI.
  36. ### Other Features
  37. - Doesn't stay in memory, creates the routing tables and ```iptables``` rules/```ipset``` entries which are automatically updated when supported/monitored interface changes.
  38. - Proudly made in :maple_leaf: Canada :maple_leaf: , using locally-sourced electrons.
  39. ## Screenshots (luci-app-vpn-policy-routing)
  40. Service Status
  41. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-status.png "Service Status")
  42. Configuration - Basic Configuration
  43. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-config-basic.png "Basic Configuration")
  44. Configuration - Advanced Configuration
  45. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-config-advanced.png "Advanced Configuration")
  46. Configuration - WebUI Configuration
  47. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-config-webui.png "WebUI Configuration")
  48. Policies
  49. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-policies.png "Policies")
  50. DSCP Tagging
  51. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-dscp.png "DSCP Tagging")
  52. Custom User File Includes
  53. ![screenshot](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/screenshots/vpn-policy-routing/screenshot04-userfiles.png "Custom User File Includes")
  54. ## How It Works
  55. On start, this service creates routing tables for each supported interface (WAN/WAN6 and VPN tunnels) which are used to route specially marked packets. For the ```mangle``` table's ```PREROUTING```, ```FORWARD```, ```INPUT``` and ```OUTPUT``` chains, the service creates corresponding ```VPR_*``` chains to which policies are assigned. Evaluation and marking of packets happen in these ```VPR_*``` chains. If enabled, the service also creates the remote/local ipsets per each supported interface and the corresponding ```iptables``` rule for marking packets matching the ```ipset```. The service then processes the user-created policies.
  56. ### Processing Policies
  57. Each policy can result in either a new ```iptables``` rule or, if ```src_ipset``` or ```dest_ipset``` are enabled, an ```ipset``` or a ```dnsmasq```'s ```ipset``` entry.
  58. - Policies with local MAC-addresses, IP addresses or local device names can be created as ```iptables``` rules or ```ipset``` entries.
  59. - Policies with local or remote ports are always created as ```iptables``` rules.
  60. - Policies with local or remote netmasks can be created as ```iptables``` rules or ```ipset``` entries.
  61. - Policies with **only** remote IP address or a domain name can be created as ```iptables``` rules or ```dnsmasq```'s ```ipset``` or an ```ipset``` (if enabled).
  62. ### Policies Priorities
  63. - If support for ```src_ipset``` and ```dest_ipset``` is disabled, then only ```iptables``` rules are created. The policy priority is the same as its order as listed in Web UI and ```/etc/config/vpn-policy-routing```. The higher the policy is in the Web UI and configuration file, the higher its priority is.
  64. - If support for ```src_ipset``` and ```dest_ipset``` is enabled, then the ```ipset``` entries have the highest priority (irrelevant of their position in the policies list) and the other policies are processed in the same order as they are listed in Web UI and ```/etc/config/vpn-policy-routing```.
  65. - If there are conflicting ```ipset``` entries for different interfaces, the priority is given to the interface which is listed first in the ```/etc/config/network``` file.
  66. - If set, the ```DSCP``` policies trump all other policies, including the ```ipset``` ones.
  67. ## How To Install
  68. Please make sure that the [requirements](#requirements) are satisfied and install ```vpn-policy-routing``` and ```luci-app-vpn-policy-routing``` from Web UI or connect to your router via ssh and run the following commands:
  69. ```sh
  70. opkg update
  71. opkg install vpn-policy-routing luci-app-vpn-policy-routing
  72. ```
  73. If these packages are not found in the official feed/repo for your version of OpenWrt/LEDE Project, you will need to add a custom repo to your router following instructions on [GitHub](https://github.com/stangri/openwrt_packages/blob/master/README.md#on-your-router)/[jsDelivr](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/README.md#on-your-router) first.
  74. These packages have been designed to be backwards compatible with OpenWrt 19.07, OpenWrt 18.06, LEDE Project 17.01 and OpenWrt 15.05. However, on systems older than OpenWrt 18.06.6 and/or a system which has deviated too far (or haven't been updated to keep in-sync) with official OpenWrt release you may get a message about missing ```luci-compat``` dependency, which (and only which) you can safely ignore and force-install the luci app using ```opkg install --force-depends``` command instead of ```opkg install```.
  75. ### Requirements
  76. This service requires the following packages to be installed on your router: ```ipset```, ```resolveip```, ```ip-full``` (or a ```busybox``` built with ```ip``` support), ```kmod-ipt-ipset``` and ```iptables```.
  77. To satisfy the requirements, connect to your router via ssh and run the following commands:
  78. ```sh
  79. opkg update; opkg install ipset resolveip ip-full kmod-ipt-ipset iptables
  80. ```
  81. ### How to install dnsmasq-full
  82. If you want to use ```dnsmasq```'s ```ipset``` support, you will need to install ```dnsmasq-full``` instead of the ```dnsmasq```. To do that, connect to your router via ssh and run the following command:
  83. ```sh
  84. opkg update; opkg remove dnsmasq; opkg install dnsmasq-full;
  85. ```
  86. ### Unmet dependencies
  87. If you are running a development (trunk/snapshot) build of OpenWrt on your router and your build is outdated (meaning that packages of the same revision/commit hash are no longer available and when you try to satisfy the [requirements](#requirements) you get errors), please flash either current OpenWrt release image or current development/snapshot image.
  88. ## Service Configuration Settings
  89. As per screenshots above, in the Web UI the ```vpn-policy-routing``` configuration is split into ```Basic```, ```Advanced``` and ```WebUI``` settings. The full list of configuration parameters of ```vpn-policy-routing.config``` section is:
  90. |Web UI Section|Parameter|Type|Default|Description|
  91. | --- | --- | --- | --- | --- |
  92. |Basic|enabled|boolean|0|Enable/disable the ```vpn-policy-routing``` service.|
  93. |Basic|verbosity|integer|2|Can be set to 0, 1 or 2 to control the console and system log output verbosity of the ```vpn-policy-routing``` service.|
  94. |Basic|strict_enforcement|boolean|1|Enforce policies when their interface is down. See [Strict enforcement](#strict-enforcement) for more details.|
  95. |Basic|dest_ipset|string|none|Enable/disable use of one of the ipset options for compatible remote policies (policies with only a remote hostname and no other fields set). This speeds up service start-up and operation. Currently supported options are ```none```, ```ipset``` and ```dnsmasq.ipset``` (see [Use DNSMASQ ipset](#use-dnsmasq-ipset) for more details). Make sure the [requirements](#requirements) are met.|
  96. |Basic|src_ipset|boolean|0|Enable/disable use of ```ipset``` entries for compatible local policies (policies with only a local IP address or MAC address and no other fields set). Using ```ipset``` for local IPs/MACs is faster than using ```iptables``` rules, however it makes it impossible to enforce policies priority/order. Make sure the [requirements](#requirements) are met.|
  97. |Basic|ipv6_enabled|boolean|0|Enable/disable IPv6 support.|
  98. |Advanced|supported_interface|list/string||Allows to specify the space-separated list of interface names (in lower case) to be explicitly supported by the ```vpn-policy-routing``` service. Can be useful if your OpenVPN tunnels have dev option other than tun\* or tap\*.|
  99. |Advanced|ignored_interface|list/string||Allows to specify the space-separated list of interface names (in lower case) to be ignored by the ```vpn-policy-routing``` service. Can be useful if running both VPN server and VPN client on the router.|
  100. |Advanced|boot_timeout|number|30|Allows to specify the time (in seconds) for ```vpn-policy-routing``` service to wait for WAN gateway discovery on boot. Can be useful on devices with ADSL modem built in.|
  101. |Advanced|iptables_rule_option|append/insert|append|Allows to specify the iptables parameter for rules: ```-A``` for ```append``` and ```-I``` for ```insert```. Append is generally speaking more compatible with other packages/firewall rules. Recommended to change to ```insert``` only to enable compatibility with the ```mwan3``` package.|
  102. |Advanced|iprule_enabled|boolean|0|Add an ```ip rule```, not an ```iptables``` entry for policies with just the local address. Use with caution to manipulate policies priorities.|
  103. |Advanced|icmp_interface|string||Set the default ICMP protocol interface (interface name in lower case). Use with caution.|
  104. |Advanced|append_src_rules|string||Append local IP Tables rules. Can be used to exclude local IP addresses from destinations for policies with local address set.|
  105. |Advanced|append_dest_rules|string||Append local IP Tables rules. Can be used to exclude remote IP addresses from sources for policies with remote address set.|
  106. |Advanced|wan_tid|integer|201|Starting (WAN) Table ID number for tables created by the ```vpn-policy-routing``` service.|
  107. |Advanced|wan_mark|hexadecimal|0x010000|Starting (WAN) fw mark for marks used by the ```vpn-policy-routing``` service. High starting mark is used to avoid conflict with SQM/QoS, this can be changed by user. Change with caution together with ```fw_mask```.|
  108. |Advanced|fw_mask|hexadecimal|0xff0000|FW Mask used by the ```vpn-policy-routing``` service. High mask is used to avoid conflict with SQM/QoS, this can be changed by user. Change with caution together with ```wan_mark```.|
  109. |Web UI|webui_enable_column|boolean|0|Shows ```Enable``` checkbox column for policies, allowing to quickly enable/disable specific policy without deleting it.|
  110. |Web UI|webui_protocol_column|boolean|0|Shows ```Protocol``` column for policies, allowing to specify the protocol for ```iptables``` rules for policies.|
  111. |Web UI|webui_supported_protocol|list|0|List of protocols to display in the ```Protocol``` column for policies.|
  112. |Web UI|webui_chain_column|boolean|0|Shows ```Chain``` column for policies, allowing to specify ```PREROUTING``` (default), ```FORWARD```, ```INPUT```, or ```OUTPUT``` chain for ```iptables``` rules for policies.|
  113. |Web UI|webui_sorting|boolean|1|Shows the Up/Down buttons for policies, allowing you to move a policy up or down in the list/priority.|
  114. ||wan_dscp|integer||Allows use of [DSCP-tag based policies](#dscp-tag-based-policies) for WAN interface.|
  115. ||{interface_name}_dscp|integer||Allows use of [DSCP-tag based policies](#dscp-tag-based-policies) for a VPN interface.|
  116. ### Default Settings
  117. Default configuration has service disabled (use Web UI to enable/start service or run ```uci set vpn-policy-routing.config.enabled=1; uci commit vpn-policy-routing;```).
  118. ### Policy Options
  119. Each policy may have a combination of the options below, the ```name``` and ```interface``` options are required.
  120. The ```src_addr```, ```src_port```, ```dest_addr``` and ```dest_port``` options supports parameter negation, for example if you want to **exclude** remote port 80 from the policy, set ```dest_port="!80"``` (notice lack of space between ```!``` and parameter).
  121. |Option|Default|Description|
  122. | --- | --- | --- |
  123. |**name**||Policy name, it **must** be set.|
  124. |enabled|1|Enable/disable policy. To display the ```Enable``` checkbox column for policies in the WebUI, make sure to select ```Enabled``` for ```Show Enable Column``` in the ```Web UI``` tab.|
  125. |**interface**||Policy interface, it **must** be set.|
  126. |src_addr||List of space-separated local/source IP addresses, CIDRs, hostnames or mac addresses (colon-separated). You can also specify a local physical device (like a specially created wlan) prepended by an ```@``` symbol.|
  127. |src_port||List of space-separated local/source ports or port-ranges.|
  128. |dest_addr||List of space-separated remote/target IP addresses, CIDRs or hostnames/domain names.|
  129. |dest_port||List of space-separated remote/target ports or port-ranges.|
  130. |proto|auto|Policy protocol, can be any valid protocol from ```/etc/protocols``` for CLI/uci or can be selected from the values set in ```webui_supported_protocol```. To display the ```Protocol``` column for policies in the WebUI, make sure to select ```Enabled``` for ```Show Protocol Column``` in the ```Web UI``` tab.<br/>Special cases: ```auto``` will try to intelligently insert protocol-agnostic policy and fall back to TCP/UDP if the protocol must be selected for specific policy; ```all``` will always insert a protocol-agnostic policy (which may fail depending on the policy).|
  131. |chain|PREROUTING|Policy chain, can be either ```PREROUTING```, ```FORWARDING```, ```INPUT``` or ```OUTPUT```. This setting is case-sensitive. To display the ```Chain``` column for policies in the WebUI, make sure to select ```Enabled``` for ```Show Chain Column``` in the ```Web UI``` tab.|
  132. ### Custom User Files Include Options
  133. |Option|Default|Description|
  134. | --- | --- | --- |
  135. |**path**||Path to a custom user file (in a form of shell script), it **must** be set.|
  136. |enabled|1|Enable/disable setting.|
  137. ### Example Policies
  138. #### Single IP, IP Range, Local Machine, Local MAC Address
  139. The following policies route traffic from a single IP address, a range of IP addresses, a local machine (requires definition as DHCP host record in DHCP config), a MAC-address of a local device and finally all of the above via WAN.
  140. ```text
  141. config policy
  142. option name 'Local IP'
  143. option interface 'wan'
  144. option src_addr '192.168.1.70'
  145. config policy
  146. option name 'Local Subnet'
  147. option interface 'wan'
  148. option src_addr '192.168.1.81/29'
  149. config policy
  150. option name 'Local Machine'
  151. option interface 'wan'
  152. option src_addr 'dell-ubuntu'
  153. config policy
  154. option name 'Local MAC Address'
  155. option interface 'wan'
  156. option src_addr '00:0F:EA:91:04:08'
  157. config policy
  158. option name 'Local Devices'
  159. option interface 'wan'
  160. option src_addr '192.168.1.70 192.168.1.81/29 dell-ubuntu 00:0F:EA:91:04:08'
  161. ```
  162. #### Logmein Hamachi
  163. The following policy routes LogMeIn Hamachi zero-setup VPN traffic via WAN.
  164. ```text
  165. config policy
  166. option name 'LogmeIn Hamachi'
  167. option interface 'wan'
  168. option dest_addr '25.0.0.0/8 hamachi.cc hamachi.com logmein.com'
  169. ```
  170. #### SIP Port
  171. The following policy routes standard SIP port traffic via WAN for both TCP and UDP protocols.
  172. ```text
  173. config policy
  174. option name 'SIP Ports'
  175. option interface 'wan'
  176. option dest_port '5060'
  177. option proto 'tcp udp'
  178. ```
  179. #### Plex Media Server
  180. The following policies route Plex Media Server traffic via WAN. Please note, you'd still need to open the port in the firewall either manually or with the UPnP.
  181. ```text
  182. config policy
  183. option name 'Plex Local Server'
  184. option interface 'wan'
  185. option src_port '32400'
  186. config policy
  187. option name 'Plex Remote Servers'
  188. option interface 'wan'
  189. option dest_addr 'plex.tv my.plexapp.com'
  190. ```
  191. #### Emby Media Server
  192. The following policy route Emby traffic via WAN. Please note, you'd still need to open the port in the firewall either manually or with the UPnP.
  193. ```text
  194. config policy
  195. option name 'Emby Local Server'
  196. option interface 'wan'
  197. option src_port '8096 8920'
  198. config policy
  199. option name 'Emby Remote Servers'
  200. option interface 'wan'
  201. option dest_addr 'emby.media app.emby.media tv.emby.media'
  202. ```
  203. #### Local OpenVPN Server + OpenVPN Client (Scenario 1)
  204. If the OpenVPN client on your router is used as default routing (for the whole internet), make sure your settings are as following (three dots on the line imply other options can be listed in the section as well).
  205. Relevant part of ```/etc/config/vpn-policy-routing```:
  206. ```text
  207. config vpn-policy-routing 'config'
  208. list ignored_interface 'vpnserver'
  209. ...
  210. config policy
  211. option name 'OpenVPN Server'
  212. option interface 'wan'
  213. option proto 'tcp'
  214. option src_port '1194'
  215. option chain 'OUTPUT'
  216. ```
  217. The network/firewall/openvpn settings are below.
  218. Relevant part of ```/etc/config/network``` (**DO NOT** modify default OpenWrt network settings for neither ```wan``` nor ```lan```):
  219. ```text
  220. config interface 'vpnclient'
  221. option proto 'none'
  222. option ifname 'ovpnc0'
  223. config interface 'vpnserver'
  224. option proto 'none'
  225. option ifname 'ovpns0'
  226. option auto '1'
  227. ```
  228. Relevant part of ```/etc/config/firewall``` (**DO NOT** modify default OpenWrt firewall settings for neither ```wan``` nor ```lan```):
  229. ```text
  230. config zone
  231. option name 'vpnclient'
  232. option network 'vpnclient'
  233. option input 'REJECT'
  234. option forward 'ACCEPT'
  235. option output 'REJECT'
  236. option masq '1'
  237. option mtu_fix '1'
  238. config forwarding
  239. option src 'lan'
  240. option dest 'vpnclient'
  241. config zone
  242. option name 'vpnserver'
  243. option network 'vpnserver'
  244. option input 'ACCEPT'
  245. option forward 'REJECT'
  246. option output 'ACCEPT'
  247. option masq '1'
  248. config forwarding
  249. option src 'vpnserver'
  250. option dest 'wan'
  251. config forwarding
  252. option src 'vpnserver'
  253. option dest 'lan'
  254. config forwarding
  255. option src 'vpnserver'
  256. option dest 'vpnclient'
  257. config rule
  258. option name 'Allow-OpenVPN-Inbound'
  259. option target 'ACCEPT'
  260. option src '*'
  261. option proto 'tcp'
  262. option dest_port '1194'
  263. ```
  264. Relevant part of ```/etc/config/openvpn```:
  265. ```text
  266. config openvpn 'vpnclient'
  267. option client '1'
  268. option dev_type 'tun'
  269. option dev 'ovpnc0'
  270. option proto 'udp'
  271. option remote 'some.domain.com 1197' # DO NOT USE PORT 1194 for VPN Client
  272. ...
  273. config openvpn 'vpnserver'
  274. option port '1194'
  275. option proto 'tcp'
  276. option server '192.168.200.0 255.255.255.0'
  277. ...
  278. ```
  279. #### Local OpenVPN Server + OpenVPN Client (Scenario 2)
  280. If the OpenVPN client is **not** used as default routing and you create policies to selectively use the OpenVPN client, make sure your settings are as following (three dots on the line imply other options can be listed in the section as well).
  281. Relevant part of ```/etc/config/vpn-policy-routing```:
  282. ```text
  283. config vpn-policy-routing 'config'
  284. list ignored_interface 'vpnserver'
  285. option append_src_rules '! -d 192.168.200.0/24'
  286. ...
  287. ```
  288. The network/firewall/openvpn settings are below.
  289. Relevant part of ```/etc/config/network``` (**DO NOT** modify default OpenWrt network settings for neither ```wan``` nor ```lan```):
  290. ```text
  291. config interface 'vpnclient'
  292. option proto 'none'
  293. option ifname 'ovpnc0'
  294. config interface 'vpnserver'
  295. option proto 'none'
  296. option ifname 'ovpns0'
  297. option auto '1'
  298. ```
  299. Relevant part of ```/etc/config/firewall``` (**DO NOT** modify default OpenWrt firewall settings for neither ```wan``` nor ```lan```):
  300. ```text
  301. config zone
  302. option name 'vpnclient'
  303. option network 'vpnclient'
  304. option input 'REJECT'
  305. option forward 'ACCEPT'
  306. option output 'REJECT'
  307. option masq '1'
  308. option mtu_fix '1'
  309. config forwarding
  310. option src 'lan'
  311. option dest 'vpnclient'
  312. config zone
  313. option name 'vpnserver'
  314. option network 'vpnserver'
  315. option input 'ACCEPT'
  316. option forward 'REJECT'
  317. option output 'ACCEPT'
  318. option masq '1'
  319. config forwarding
  320. option src 'vpnserver'
  321. option dest 'wan'
  322. config forwarding
  323. option src 'vpnserver'
  324. option dest 'lan'
  325. config forwarding
  326. option src 'vpnserver'
  327. option dest 'vpnclient'
  328. config rule
  329. option name 'Allow-OpenVPN-Inbound'
  330. option target 'ACCEPT'
  331. option src '*'
  332. option proto 'tcp'
  333. option dest_port '1194'
  334. ```
  335. Relevant part of ```/etc/config/openvpn```:
  336. ```text
  337. config openvpn 'vpnclient'
  338. option client '1'
  339. option dev_type 'tun'
  340. option dev 'ovpnc0'
  341. option proto 'udp'
  342. option remote 'some.domain.com 1197' # DO NOT USE PORT 1194 for VPN Client
  343. list pull_filter 'ignore "redirect-gateway"' # for OpenVPN 2.4 and later
  344. option route_nopull '1' # for OpenVPN earlier than 2.4
  345. ...
  346. config openvpn 'vpnserver'
  347. option port '1194'
  348. option proto 'tcp'
  349. option server '192.168.200.0 255.255.255.0'
  350. ...
  351. ```
  352. #### Local Wireguard Server + Wireguard Client (Scenario 1)
  353. Yes, I'm aware that technically there are no clients nor servers in Wireguard, it's all peers, but for the sake of README readability I will use the terminology similar to the OpenVPN Server + Client setups.
  354. If the Wireguard tunnel on your router is used as default routing (for the whole internet), make sure your settings are as following (three dots on the line imply other options can be listed in the section as well).
  355. Relevant part of ```/etc/config/vpn-policy-routing```:
  356. ```text
  357. config vpn-policy-routing 'config'
  358. list ignored_interface 'wgserver'
  359. ...
  360. config policy
  361. option name 'Wireguard Server'
  362. option interface 'wan'
  363. option proto 'udp'
  364. option src_port '61820'
  365. option chain 'OUTPUT'
  366. ```
  367. The recommended network/firewall settings are below.
  368. Relevant part of ```/etc/config/network``` (**DO NOT** modify default OpenWrt network settings for neither ```wan``` nor ```lan```):
  369. ```text
  370. config interface 'wgclient'
  371. option proto 'wireguard'
  372. ...
  373. config wireguard_wgclient
  374. list allowed_ips '0.0.0.0/0'
  375. list allowed_ips '::0/0'
  376. option endpoint_port '51820'
  377. option route_allowed_ips '1'
  378. ...
  379. config interface 'wgserver'
  380. option proto 'wireguard'
  381. option listen_port '61820'
  382. list addresses '192.168.200.1'
  383. ...
  384. config wireguard_wgserver
  385. list allowed_ips '192.168.200.2/32'
  386. option route_allowed_ips '1'
  387. ...
  388. ```
  389. Relevant part of ```/etc/config/firewall``` (**DO NOT** modify default OpenWrt firewall settings for neither ```wan``` nor ```lan```):
  390. ```text
  391. config zone
  392. option name 'wgclient'
  393. option network 'wgclient'
  394. option input 'REJECT'
  395. option forward 'ACCEPT'
  396. option output 'REJECT'
  397. option masq '1'
  398. option mtu_fix '1'
  399. config forwarding
  400. option src 'lan'
  401. option dest 'wgclient'
  402. config zone
  403. option name 'wgserver'
  404. option network 'wgserver'
  405. option input 'ACCEPT'
  406. option forward 'REJECT'
  407. option output 'ACCEPT'
  408. option masq '1'
  409. config forwarding
  410. option src 'wgserver'
  411. option dest 'wan'
  412. config forwarding
  413. option src 'wgserver'
  414. option dest 'lan'
  415. config forwarding
  416. option src 'wgserver'
  417. option dest 'wgclient'
  418. config rule
  419. option name 'Allow-WG-Inbound'
  420. option target 'ACCEPT'
  421. option src '*'
  422. option proto 'udp'
  423. option dest_port '61820'
  424. ```
  425. #### Local Wireguard Server + Wireguard Client (Scenario 2)
  426. Yes, I'm aware that technically there are no clients nor servers in Wireguard, it's all peers, but for the sake of README readability I will use the terminology similar to the OpenVPN Server + Client setups.
  427. If the Wireguard client is **not** used as default routing and you create policies to selectively use the Wireguard client, make sure your settings are as following (three dots on the line imply other options can be listed in the section as well).
  428. Relevant part of ```/etc/config/vpn-policy-routing```:
  429. ```text
  430. config vpn-policy-routing 'config'
  431. list ignored_interface 'wgserver'
  432. option append_src_rules '! -d 192.168.200.0/24'
  433. ...
  434. ```
  435. The recommended network/firewall settings are below.
  436. Relevant part of ```/etc/config/network``` (**DO NOT** modify default OpenWrt network settings for neither ```wan``` nor ```lan```):
  437. ```text
  438. config interface 'wgclient'
  439. option proto 'wireguard'
  440. ...
  441. config wireguard_wgclient
  442. list allowed_ips '0.0.0.0/0'
  443. list allowed_ips '::0/0'
  444. option endpoint_port '51820'
  445. ...
  446. config interface 'wgserver'
  447. option proto 'wireguard'
  448. option listen_port '61820'
  449. list addresses '192.168.200.1/24'
  450. ...
  451. config wireguard_wgserver
  452. list allowed_ips '192.168.200.2/32'
  453. option route_allowed_ips '1'
  454. ...
  455. ```
  456. Relevant part of ```/etc/config/firewall``` (**DO NOT** modify default OpenWrt firewall settings for neither ```wan``` nor ```lan```):
  457. ```text
  458. config zone
  459. option name 'wgclient'
  460. option network 'wgclient'
  461. option input 'REJECT'
  462. option forward 'ACCEPT'
  463. option output 'REJECT'
  464. option masq '1'
  465. option mtu_fix '1'
  466. config forwarding
  467. option src 'lan'
  468. option dest 'wgclient'
  469. config zone
  470. option name 'wgserver'
  471. option network 'wgserver'
  472. option input 'ACCEPT'
  473. option forward 'REJECT'
  474. option output 'ACCEPT'
  475. option masq '1'
  476. config forwarding
  477. option src 'wgserver'
  478. option dest 'wan'
  479. config forwarding
  480. option src 'wgserver'
  481. option dest 'lan'
  482. config forwarding
  483. option src 'wgserver'
  484. option dest 'wgclient'
  485. config rule
  486. option name 'Allow-WG-Inbound'
  487. option target 'ACCEPT'
  488. option src '*'
  489. option proto 'udp'
  490. option dest_port '61820'
  491. ```
  492. #### Netflix Domains
  493. The following policy should route US Netflix traffic via WAN. For capturing international Netflix domain names, you can refer to the getdomainnames.sh-specific instructions on [GitHub](https://github.com/Xentrk/netflix-vpn-bypass/blob/master/README.md#ipset_netflix_domainssh)/[jsDelivr](https://cdn.jsdelivr.net/gh/Xentrk/openwrt_packages@master/netflix-vpn-bypass/README.md#ipset_netflix_domainssh) and don't forget to adjust them for OpenWrt. This may not work if Netflix changes things. For more reliable US Netflix routing you may want to consider using [custom user files](#custom-user-files).
  494. ```text
  495. config policy
  496. option name 'Netflix Domains'
  497. option interface 'wan'
  498. option dest_addr 'amazonaws.com netflix.com nflxext.com nflximg.net nflxso.net nflxvideo.net dvd.netflix.com'
  499. ```
  500. #### Example Custom User Files Includes
  501. ```text
  502. config include
  503. option path '/etc/vpn-policy-routing.netflix.user'
  504. config include
  505. option path '/etc/vpn-policy-routing.aws.user'
  506. ```
  507. #### Basic OpenVPN Client Config
  508. There are multiple guides online on how to configure the OpenVPN client on OpenWrt "the easy way", and they usually result either in a kill-switch configuration or configuration where the OpenVPN tunnel cannot be properly (and separately from WAN) routed, either way, incompatible with the VPN Policy-Based Routing.
  509. Below is the sample OpenVPN client configuration for OpenWrt which is guaranteed to work. If you have already deviated from the instructions below (ie: made any changes to any of the ```wan``` or ```lan``` configurations in either ```/etc/config/network``` or ```/etc/config/firewall```), you will need to start from scratch with a fresh OpenWrt install.
  510. Relevant part of ```/etc/config/vpn-policy-routing```:
  511. ```text
  512. config vpn-policy-routing 'config'
  513. list supported_interface 'vpnc'
  514. ...
  515. ```
  516. The recommended network/firewall settings are below.
  517. Relevant part of ```/etc/config/network``` (**DO NOT** modify default OpenWrt network settings for neither ```wan``` nor ```lan```):
  518. ```text
  519. config interface 'vpnc'
  520. option proto 'none'
  521. option ifname 'ovpnc0'
  522. ```
  523. Relevant part of ```/etc/config/firewall``` (**DO NOT** modify default OpenWrt firewall settings for neither ```wan``` nor ```lan```):
  524. ```text
  525. config zone
  526. option name 'vpnc'
  527. option network 'vpnc'
  528. option input 'REJECT'
  529. option forward 'REJECT'
  530. option output 'ACCEPT'
  531. option masq '1'
  532. option mtu_fix '1'
  533. config forwarding
  534. option src 'lan'
  535. option dest 'vpnc'
  536. ```
  537. If you have a Guest Network, add the following to the ```/etc/config/firewall```:
  538. ```text
  539. config forwarding
  540. option src 'guest'
  541. option dest 'vpnc'
  542. ```
  543. Relevant part of ```/etc/config/openvpn``` (configure the rest of the client connection for your specifics by either referring to an existing ```.ovpn``` file or thru the OpenWrt uci settings):
  544. ```text
  545. config openvpn 'vpnc'
  546. option enabled '1'
  547. option client '1'
  548. option dev_type 'tun'
  549. option dev 'ovpnc0'
  550. ...
  551. ```
  552. ## Footnotes/Known Issues
  553. 1. <a name="footnote1"> </a> See [note about multiple OpenVPN clients](#multiple-openvpn-clients).
  554. 2. <a name="footnote2"> </a> If your ```OpenVPN``` interface has the device name different from tun\* or tap\*, is not up and is not explicitly listed in ```supported_interface``` option, it may not be available in the policies ```Interface``` drop-down within WebUI.
  555. 3. <a name="footnote3"> </a> If your default routing is set to the VPN tunnel, then the true WAN interface cannot be discovered using OpenWrt built-in functions, so service will assume your network interface ending with or starting with ```wan``` is the true WAN interface.
  556. 4. <a name="footnote4"> </a> The service does **NOT** support the "killswitch" router mode (where if you stop the VPN tunnel, you have no internet connection). For proper operation, leave all the default OpenWrt ```network``` and ```firewall``` settings for ```lan``` and ```wan``` intact.
  557. 5. <a name="footnote5"> </a> When using the ```dnsmasq.ipset``` option, please make sure to flush the DNS cache of the local devices, otherwise domain policies may not work until you do. If you're not sure how to flush the DNS cache (or if the device/OS doesn't offer an option to flush its DNS cache), reboot your local devices when starting to use the service and/or when connecting data-capable device to your WiFi.
  558. 6. <a name="footnote6"> </a> When using the policies targeting physical devices, make sure you have the following packages installed: ```kmod-br-netfilter```, ```kmod-ipt-physdev``` and ```iptables-mod-physdev```. Also, if your physical device is a part of the bridge, you may have to set ```net.bridge.bridge-nf-call-iptables``` to `1` in your ```/etc/sysctl.conf```.
  559. ### First Troubleshooting Step
  560. If your router is set to use [default routing via VPN tunnel](#a-word-about-default-routing) and the WAN-targeting policies do not work, you need to stop your VPN tunnel first and ensure that you still have internet connection. If your router is set up to use the default routing via VPN tunnel and when you stop the VPN tunnel you have no internet connection, this package can't help you. You first need to make sure that you do have internet connection when the VPN tunnel is stopped.
  561. ### Multiple OpenVPN Clients
  562. If you use multiple OpenVPN clients on your router, the order in which their devices are named (tun0, tun1, etc) is not guaranteed by OpenWrt/LEDE Project. The following settings are recommended in this case.
  563. For ```/etc/config/network```:
  564. ```text
  565. config interface 'vpnclient0'
  566. option proto 'none'
  567. option ifname 'ovpnc0'
  568. config interface 'vpnclient1'
  569. option proto 'none'
  570. option ifname 'ovpnc1'
  571. ```
  572. For ```/etc/config/openvpn```:
  573. ```text
  574. config openvpn 'vpnclient0'
  575. option client '1'
  576. option dev_type 'tun'
  577. option dev 'ovpnc0'
  578. ...
  579. config openvpn 'vpnclient1'
  580. option client '1'
  581. option dev_type 'tun'
  582. option dev 'ovpnc1'
  583. ...
  584. ```
  585. For ```/etc/config/vpn-policy-routing```:
  586. ```text
  587. config vpn-policy-routing 'config'
  588. list supported_interface 'vpnclient0 vpnclient1'
  589. ...
  590. ```
  591. ### A Word About Default Routing
  592. Service does not alter the default routing. Depending on your VPN tunnel settings (and settings of the VPN server you are connecting to), the default routing might be set to go via WAN or via VPN tunnel. This service affects only routing of the traffic matching the policies. If you want to override default routing, follow the instructions below.
  593. #### OpenVPN tunnel configured via uci (/etc/config/openvpn)
  594. Set the following to the appropriate section of your ```/etc/config/openvpn```:
  595. - For OpenVPN 2.4 and newer client config:
  596. ```text
  597. list pull_filter 'ignore "redirect-gateway"'
  598. ```
  599. - For OpenVPN 2.3 and older client config:
  600. ```text
  601. option route_nopull '1'
  602. ```
  603. - For your Wireguard (client) config:
  604. ```text
  605. option route_allowed_ips '0'
  606. ```
  607. #### OpenVPN tunnel configured with .ovpn file
  608. Set the following to the appropriate section of your ```.ovpn``` file:
  609. - For OpenVPN 2.4 and newer client ```.ovpn``` file:
  610. ```text
  611. pull-filter ignore "redirect-gateway"
  612. ```
  613. - For OpenVPN 2.3 and older client ```.ovpn``` file:
  614. ```text
  615. route-nopull "1"
  616. ```
  617. #### Wireguard tunnel
  618. - For your Wireguard (client) config:
  619. ```text
  620. option route_allowed_ips '0'
  621. ```
  622. - Routing Wireguard traffic may require setting `net.ipv4.conf.wg0.rp_filter = 2` in `/etc/sysctl.conf`. Please refer to [issue #41](https://github.com/stangri/openwrt_packages/issues/41) for more details.
  623. ### A Word About HTTP/3 (QUICK)
  624. If you want to target traffic using HTTP/3 protocol, you can use the ```AUTO``` as the protocol (the policy will be either protocol-agnostic or ```TCP/UDP```) or explicitly use ```UDP``` as a protocol.
  625. ### A Word About DNS-over-HTTPS
  626. Some browsers, like [Mozilla Firefox](https://support.mozilla.org/en-US/kb/firefox-dns-over-https#w_about-dns-over-https) or [Google Chrome/Chromium](https://blog.chromium.org/2019/09/experimenting-with-same-provider-dns.html) have [DNS-over-HTTPS proxy](https://en.wikipedia.org/wiki/DNS_over_HTTPS) built-in. Their requests to web-sites cannot be affected if the ```dnsmasq.ipset``` is set for the ```dest_ipset``` option. To fix this, you can try either of the following:
  627. 1. Disable the DNS-over-HTTPS support in your browser and use the OpenWrt's ```net/https-dns-proxy``` (README on [GitHub](https://github.com/openwrt/packages/tree/master/net/https-dns-proxy)/[jsDelivr](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/https-dns-proxy/files/README.md)) package with optional ```https-dns-proxy``` WebUI/luci app. You can then continue to use ```dnsmasq.ipset``` setting for the ```dest_ipset``` in VPN Policy Routing.
  628. 2. Continue using DNS-over-HTTPS in your browser (which, by the way, also limits your options for router-level AdBlocking as described in ```dnsmasq.ipset``` option description here of ```net/simple-adblock``` README on [GitHub](https://github.com/openwrt/packages/tree/master/net/simple-adblock/files#dns-resolution-option)/[jsDelivr](https://cdn.jsdelivr.net/gh/stangri/openwrt_packages@master/simple-adblock/files/README.md#dns-resolution-option)), you than would either have to disable the ```dest_ipset``` or switch it to ```ipset```. Please note, you will lose all the benefits of [```dnsmasq.ipset```](#use-dnsmasq-ipset) option.
  629. ### A Word About Cloudflare's 1.1.1.1 App
  630. Cloudflare has released an app for [iOS](https://itunes.apple.com/us/app/1-1-1-1-faster-internet/id1423538627) and [Android](https://play.google.com/store/apps/details?id=com.cloudflare.onedotonedotonedotone), which can also be configured to route traffic thru their own VPN tunnel (WARP+).
  631. If you use Cloudlfare's VPN tunnel (WARP+), none of the policies you set up with the VPN Policy Routing will take effect on your mobile device. Disable WARP+ for your home WiFi to keep VPN Policy Routing affecting your mobile device.
  632. If you just use the private DNS queries (WARP), [A Word About DNS-over-HTTPS](#a-word-about-DNS-over-HTTPS) applies. You can also disable WARP for your home WiFi to keep VPN Policy Routing affecting your mobile device.
  633. ## Discussion
  634. Please head to [OpenWrt Forum](https://forum.openwrt.org/t/vpn-policy-based-routing-web-ui-discussion/10389) for discussions of this service.
  635. ## Getting Help
  636. If things are not working as intended, please include the following in your post:
  637. - content of ```/etc/config/dhcp```
  638. - content of ```/etc/config/firewall```
  639. - content of ```/etc/config/network```
  640. - content of ```/etc/config/vpn-policy-routing```
  641. - the output of ```/etc/init.d/vpn-policy-routing support```
  642. - the output of ```/etc/init.d/vpn-policy-routing reload``` with verbosity setting set to 2
  643. If you don't want to post the ```/etc/init.d/vpn-policy-routing support``` output in a public forum, there's a way to have the support details automatically uploaded to my account at paste.ee by running: ```/etc/init.d/vpn-policy-routing support -p```. You need to have the following packages installed to enable paste.ee upload functionality: ```curl libopenssl ca-bundle```.
  644. WARNING: while paste.ee uploads are unlisted/not indexed at the web-site, they are still publicly available.
  645. ## Thanks
  646. I'd like to thank everyone who helped create, test and troubleshoot this service. Without contributions from [@hnyman](https://github.com/hnyman), [@dibdot](https://github.com/dibdot), [@danrl](https://github.com/danrl), [@tohojo](https://github.com/tohojo), [@cybrnook](https://github.com/cybrnook), [@nidstigator](https://github.com/nidstigator), [@AndreBL](https://github.com/AndreBL), [@dz0ny](https://github.com/dz0ny), rigorous testing/bugreporting by [@dziny](https://github.com/dziny), [@bluenote73](https://github.com/bluenote73), [@buckaroo](https://github.com/pgera), [@Alexander-r](https://github.com/Alexander-r), [n8v8R](https://github.com/n8v8R), [psherman](https://forum.openwrt.org/u/psherman), [@Vale-max](https://github.com/Vale-max), multiple contributions from [dl12345](https://github.com/dl12345) and [trendy](https://forum.openwrt.org/u/trendy) and feedback from other OpenWrt users it wouldn't have been possible. Wireguard/IPv6 support is courtesy of [Mullvad](https://www.mullvad.net) and [IVPN](https://www.ivpn.net/).