Skip to content

Instantly share code, notes, and snippets.

@braian87b
Last active June 30, 2023 12:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save braian87b/126f20a920e7aabdd495afc861c2a22c to your computer and use it in GitHub Desktop.
Save braian87b/126f20a920e7aabdd495afc861c2a22c to your computer and use it in GitHub Desktop.
/etc/config/mwan
# My documentation:
#
# Important: this works well on OpenWRT 15.05.1, on newer versions there was some breaking changes, for example, the wan ifaces have ipv6 capability and now are named with letters ("wan, wanb... , wanc" instead of "wan, wan2... wan3" so wanb6 means 2nd wan ipv6.): https://github.com/openwrt/packages/blob/master/net/mwan3/files/etc/config/mwan3
#
# We have Interfaces, Members, Policyes y Rules:
#
# Interfaces: Allows to identify the wan interface, we just need to have it enabled`
# the others parameters are only to track if the interface it is up or down.
#
# Members: Can be defined in some metric and weight, both values will be important ambos when used in policyes.
#
# Policyes: Will have asssigned members and a 'last_resort' behaviour.
# last_resort: defines waht to do when none of the assigned members are working, default value: 'unreachable'
# 'unreachable' and 'blackhole' could be also be used as policyes, not neccesary to be defined
# other value is 'blackhole', but this one will not return an unreachable ICMP and will get stuck until connection timeout.
# Members will be used according to metric defined order.
# ex. if there is 2 members with metric 1, and another with metric 2, then will browse internet using those both metric 1 connections and when both are down, the third will be used.
# then, both connection will be used at the same time of the same lower metric and if both stop working then there will be used the third, and so on.
# Weight: the weight define in which proportion will be used the connections of the same metric.
# ec. If there is 2 connection of same metric, but weight of one is 3 and the second one if 4 then will be used 43% and 57% of each connection
# then will be used 3 times of each 7 times the first connection, and 4 times of 7 times the second connection.
# ex. If both connection have same weigth, ex 2 and 2, then will be used each connection 50% of the time each one.
#
# Rules: we need to put the more specific-particular rules first, and the more general-global ones at last.
# Proto: 'tcp' or 'udp' or 'all' for both, default: 'all'
# Sticky: future connections will be handled by the same member of the previous policy of the rule, default: '0'
# Policyes IMPORTANT: name could not exceed 15 caracters
# Globals: there is a problem on newer versions than OpenWRT 15.05.1 that needs the globals section
# more info on: https://forum.openwrt.org/t/i-cant-start-mwan3-service/12800/2
# So... PLEASE MIX CAREFULLY this config with the defaults config.
# --------------------------------------------------
config globals 'globals'
option enabled '1'
config interface 'wan'
option enabled '1'
list track_ip '8.8.4.4'
list track_ip '8.8.8.8'
list track_ip '208.67.222.222'
list track_ip '208.67.220.220'
option reliability '2'
option count '1'
option timeout '2'
option interval '5'
option down '3'
option up '8'
config interface 'wan2'
option enabled '1'
list track_ip '8.8.8.8'
list track_ip '208.67.220.220'
option reliability '1'
option count '1'
option timeout '2'
option interval '5'
option down '3'
option up '8'
config interface 'wan3'
option enabled '1'
list track_ip '8.8.8.8'
list track_ip '208.67.220.220'
option reliability '1'
option count '1'
option timeout '2'
option interval '5'
option down '3'
option up '8'
# --------------------------------------------------
config member 'wan1_m1_w2'
option interface 'wan'
option metric '1'
option weight '2'
config member 'wan1_m1_w3'
option interface 'wan'
option metric '1'
option weight '3'
config member 'wan1_m1_w4'
option interface 'wan'
option metric '1'
option weight '4'
config member 'wan1_m2_w1'
option interface 'wan'
option metric '2'
option weight '1'
config member 'wan2_m1_w2'
option interface 'wan2'
option metric '1'
option weight '2'
config member 'wan2_m1_w3'
option interface 'wan2'
option metric '1'
option weight '3'
config member 'wan2_m1_w4'
option interface 'wan2'
option metric '1'
option weight '4'
config member 'wan2_m2_w1'
option interface 'wan2'
option metric '2'
option weight '1'
config member 'wan3_m1_w2'
option interface 'wan3'
option metric '1'
option weight '2'
config member 'wan3_m1_w3'
option interface 'wan3'
option metric '1'
option weight '3'
config member 'wan3_m1_w4'
option interface 'wan3'
option metric '1'
option weight '4'
config member 'wan3_m2_w1'
option interface 'wan3'
option metric '2'
option weight '1'
# --------------------------------------------------
config policy 'only_1'
list use_member 'wan1_m1_w2'
config policy 'only_2'
list use_member 'wan2_m1_w2'
config policy 'only_3'
list use_member 'wan3_m1_w2'
config policy 'then_1_2'
list use_member 'wan1_m1_w2'
list use_member 'wan2_m2_w1'
config policy 'then_2_1'
list use_member 'wan2_m1_w2'
list use_member 'wan1_m2_w1'
config policy 'more_1_2'
list use_member 'wan1_m1_w4'
list use_member 'wan2_m1_w3'
config policy 'more_3_2_1'
list use_member 'wan3_m1_w4'
list use_member 'wan2_m1_w3'
list use_member 'wan1_m1_w2'
config policy 'more_1_2_3'
list use_member 'wan1_m1_w4'
list use_member 'wan2_m1_w3'
list use_member 'wan3_m1_w2'
# --------------------------------------------------
# In case we need to query same wan interface ip often using same website:
#config rule 'wan3_ip'
# option dest_ip 'ip.changeip.com'
# option use_policy 'wan3_only'
# Make sure that this one is the first rule (because it is more specific)
config rule 'torrents'
option proto 'all'
option src_ip '192.168.1.12'
option sticky '0'
option use_policy 'only_3'
# Allow to connect the admin panel of CABLE Modem
config rule 'modem_cable_3'
option dest_ip '192.168.100.0/24'
option proto 'all'
option sticky '0'
option use_policy 'only_3'
# DDNS FailOver
config rule 'noip'
option dest_ip 'checkip.dyndns.com'
option proto 'all'
option sticky '0'
option use_policy 'then_2_1'
# Youtube Videos (need to install dnsmasq-full and set up ipset 'youtube' on /etc/firewall.rules using `/usr/sbin/ipset create youtube hash:ip`)
config rule 'youtube'
option sticky '1'
option ipset 'youtube'
option dest_port '80,443'
option proto 'tcp'
option use_policy 'more_3_2_1'
config rule 'https'
option sticky '1'
option dest_port '443'
option proto 'tcp'
option use_policy 'more_1_2'
config rule 'default_rule'
option dest_ip '0.0.0.0/0'
option use_policy 'more_1_2'
# --------------------------------------------------
# Ensures that default rule will be always be the last one
#uci reorder mwan3.default_rule='9999'
# save changes
#uci commit mwan3
# Be warned: this will take some time.
#/usr/sbin/mwan3 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment