Multiwan jest pakietem realizującym idee udostępnienia wielu połączeń jako źródła sieci. Może pracować w kilku trybach jako loadbalancer (równoważenie obciążenia) jak również failover (przełączenie na inne łącze w przypadku awarii pierwszego). Ten szybki poradnik opisuje drugi przypadek. Do celów praktycznych przyjmujmy dwa łącza: wan jako połączenie kablowe (RJ45 do portu wan) oraz wan2 jako połączenie przez modem GSM. Łącze wan będzie traktowane jako podstawowe, łącze wan2 jako zapasowe, na które zostanie przełączona transmisja w przypadku padu pierwszego łącza.
Opis stworzenia łącza przez modem GSM został już wielokrotnie
opisany, na szybko jego konfiguracja sprowadza się do wydania poleceń:
opkg update
opkg install kmod-usb-core kmod-usb2 kmod-usb-serial kmod-usb-serial-option usb-modeswitch usb-modeswitch-data
opkg install chat comgt
uci set network.wan2=interface
uci set network.wan2.proto=3g
uci set network.wan2.service=umts
uci set network.wan2.device=/dev/ttyUSB0
uci set network.wan2.pincode=1234
uci set network.wan2.apn=internet
uci set network.wan2.username=''
uci set network.wan2.password=''
uci set network.wan2.auto=1
uci commit network
ifup wan2
Oczywiście device, pin i apn powinny zostać dobrane stosowanie do posiadanego modemu i operatora.
Instalacjaopkg update
opkg install multiwan
KonfiguracjaPakiet jest de-facto skryptem realizującym nadzorowanie obu łącz i przestawienie routingu w razie potrzeby. Jego konfiguracja zawarta jest standardowo w
/etc/config/multiwan. Jego konfiguracja dla w/w konfiguracji nie odbiega od tej domyślnej i powinna wyglądać w następujący sposób:
config 'interface' 'wan'
option 'weight' '10'
option 'health_interval' '10'
option 'icmp_hosts' 'dns'
option 'timeout' '3'
option 'health_fail_retries' '3'
option 'health_recovery_retries' '5'
option 'failover_to' 'wan2'
option 'dns' 'auto'
config 'interface' 'wan2'
option 'weight' '10'
option 'health_interval' '10'
option 'icmp_hosts' 'gateway'
option 'timeout' '3'
option 'health_fail_retries' '3'
option 'health_recovery_retries' '5'
option 'failover_to' 'none'
option 'dns' '8.8.8.8'
Pierwsza sekcja to konfiguracja dla łącza wan - sprawdzanie co 10s, 3s timeoutu, liczba prób przed przełączeniem itd. Jeżeli łącze zawiodło - ma się przełączyć na wan2. Druga sekcja dla łącza wan2 - parametry podobne, tyle że w przypadku jego awarii nie łączymy się z innym.
Przy takiej konfiguracji w przypadku zaniku łącza wan następuje przełączenie na łącze wan2, to pierwsze jest ciągle monitorowane i jeżeli działa ponownie - następuje powrót do pierwszego łącza.
Uruchomienie/etc/init.d/multiwan start
/etc/init.d/multiwan enable
TestyJedno łącze kablowe, drugie 3G. Na chwilę fizycznie odłączyłem kabel od wan, to rezulat pingowania:
root@OpenWrt:/# ping onet.pl
PING onet.pl (213.180.146.27): 56 data bytes
64 bytes from 213.180.146.27: seq=0 ttl=56 time=18.283 ms
64 bytes from 213.180.146.27: seq=1 ttl=56 time=19.275 ms
64 bytes from 213.180.146.27: seq=2 ttl=56 time=18.888 ms
64 bytes from 213.180.146.27: seq=3 ttl=56 time=17.614 ms
64 bytes from 213.180.146.27: seq=4 ttl=56 time=17.233 ms
64 bytes from 213.180.146.27: seq=5 ttl=56 time=19.136 ms
64 bytes from 213.180.146.27: seq=6 ttl=56 time=20.760 ms
tu nastąpiło przełączenie na wan2, widać po czasie pinga
64 bytes from 213.180.146.27: seq=33 ttl=48 time=994.675 ms
64 bytes from 213.180.146.27: seq=34 ttl=48 time=384.366 ms
64 bytes from 213.180.146.27: seq=35 ttl=48 time=364.188 ms
64 bytes from 213.180.146.27: seq=36 ttl=48 time=344.000 ms
64 bytes from 213.180.146.27: seq=37 ttl=48 time=353.805 ms
64 bytes from 213.180.146.27: seq=38 ttl=48 time=1173.619 ms
64 bytes from 213.180.146.27: seq=39 ttl=48 time=183.640 ms
64 bytes from 213.180.146.27: seq=40 ttl=48 time=93.230 ms
64 bytes from 213.180.146.27: seq=41 ttl=48 time=93.035 ms
64 bytes from 213.180.146.27: seq=42 ttl=48 time=92.825 ms
64 bytes from 213.180.146.27: seq=43 ttl=48 time=102.634 ms
64 bytes from 213.180.146.27: seq=44 ttl=48 time=92.437 ms
64 bytes from 213.180.146.27: seq=45 ttl=48 time=92.241 ms
64 bytes from 213.180.146.27: seq=46 ttl=48 time=92.045 ms
64 bytes from 213.180.146.27: seq=47 ttl=48 time=91.850 ms
64 bytes from 213.180.146.27: seq=48 ttl=48 time=91.657 ms
64 bytes from 213.180.146.27: seq=49 ttl=48 time=91.477 ms
64 bytes from 213.180.146.27: seq=50 ttl=48 time=91.233 ms
64 bytes from 213.180.146.27: seq=51 ttl=48 time=71.039 ms
64 bytes from 213.180.146.27: seq=52 ttl=48 time=90.862 ms
64 bytes from 213.180.146.27: seq=53 ttl=48 time=90.668 ms
64 bytes from 213.180.146.27: seq=54 ttl=48 time=70.460 ms
64 bytes from 213.180.146.27: seq=55 ttl=48 time=70.374 ms
64 bytes from 213.180.146.27: seq=56 ttl=48 time=90.000 ms
64 bytes from 213.180.146.27: seq=57 ttl=48 time=89.815 ms
64 bytes from 213.180.146.27: seq=58 ttl=48 time=89.631 ms
64 bytes from 213.180.146.27: seq=59 ttl=48 time=89.447 ms
64 bytes from 213.180.146.27: seq=60 ttl=48 time=89.266 ms
64 bytes from 213.180.146.27: seq=61 ttl=48 time=89.077 ms
64 bytes from 213.180.146.27: seq=62 ttl=48 time=88.896 ms
64 bytes from 213.180.146.27: seq=63 ttl=48 time=88.710 ms
64 bytes from 213.180.146.27: seq=64 ttl=48 time=88.524 ms
64 bytes from 213.180.146.27: seq=65 ttl=48 time=88.357 ms
64 bytes from 213.180.146.27: seq=66 ttl=48 time=88.162 ms
64 bytes from 213.180.146.27: seq=67 ttl=48 time=87.973 ms
64 bytes from 213.180.146.27: seq=68 ttl=48 time=87.762 ms
64 bytes from 213.180.146.27: seq=69 ttl=48 time=87.561 ms
64 bytes from 213.180.146.27: seq=70 ttl=48 time=87.368 ms
64 bytes from 213.180.146.27: seq=71 ttl=48 time=87.175 ms
64 bytes from 213.180.146.27: seq=72 ttl=48 time=96.979 ms
64 bytes from 213.180.146.27: seq=73 ttl=48 time=66.787 ms
64 bytes from 213.180.146.27: seq=74 ttl=48 time=66.591 ms
64 bytes from 213.180.146.27: seq=75 ttl=48 time=76.398 ms
64 bytes from 213.180.146.27: seq=76 ttl=48 time=66.203 ms
64 bytes from 213.180.146.27: seq=77 ttl=48 time=86.008 ms
64 bytes from 213.180.146.27: seq=78 ttl=48 time=85.824 ms
64 bytes from 213.180.146.27: seq=79 ttl=48 time=85.639 ms
64 bytes from 213.180.146.27: seq=80 ttl=48 time=105.442 ms
64 bytes from 213.180.146.27: seq=81 ttl=48 time=85.237 ms
64 bytes from 213.180.146.27: seq=82 ttl=48 time=75.036 ms
64 bytes from 213.180.146.27: seq=83 ttl=48 time=74.864 ms
64 bytes from 213.180.146.27: seq=84 ttl=48 time=74.698 ms
64 bytes from 213.180.146.27: seq=85 ttl=48 time=94.505 ms
64 bytes from 213.180.146.27: seq=86 ttl=48 time=94.311 ms
64 bytes from 213.180.146.27: seq=87 ttl=48 time=94.113 ms
64 bytes from 213.180.146.27: seq=88 ttl=48 time=93.916 ms
64 bytes from 213.180.146.27: seq=89 ttl=48 time=93.725 ms
64 bytes from 213.180.146.27: seq=90 ttl=48 time=93.539 ms
64 bytes from 213.180.146.27: seq=91 ttl=48 time=93.362 ms
64 bytes from 213.180.146.27: seq=92 ttl=48 time=113.166 ms
64 bytes from 213.180.146.27: seq=93 ttl=48 time=92.979 ms
64 bytes from 213.180.146.27: seq=94 ttl=48 time=92.763 ms
64 bytes from 213.180.146.27: seq=95 ttl=48 time=92.624 ms
tu nastąpiło przełączenie na wan, widać po czasie pinga (brak utraconych pakietów)
64 bytes from 213.180.146.27: seq=96 ttl=56 time=19.880 ms
64 bytes from 213.180.146.27: seq=97 ttl=56 time=18.668 ms
64 bytes from 213.180.146.27: seq=98 ttl=56 time=17.593 ms
64 bytes from 213.180.146.27: seq=99 ttl=56 time=18.067 ms
64 bytes from 213.180.146.27: seq=100 ttl=56 time=41.597 ms
64 bytes from 213.180.146.27: seq=101 ttl=56 time=17.011 ms
64 bytes from 213.180.146.27: seq=102 ttl=56 time=17.030 ms
64 bytes from 213.180.146.27: seq=103 ttl=56 time=17.205 ms
64 bytes from 213.180.146.27: seq=104 ttl=56 time=23.157 ms
64 bytes from 213.180.146.27: seq=105 ttl=56 time=20.484 ms
64 bytes from 213.180.146.27: seq=106 ttl=56 time=18.175 ms
64 bytes from 213.180.146.27: seq=107 ttl=56 time=30.111 ms
64 bytes from 213.180.146.27: seq=108 ttl=56 time=18.154 ms
64 bytes from 213.180.146.27: seq=109 ttl=56 time=17.711 ms
64 bytes from 213.180.146.27: seq=110 ttl=56 time=18.206 ms
64 bytes from 213.180.146.27: seq=111 ttl=56 time=17.370 ms
64 bytes from 213.180.146.27: seq=112 ttl=56 time=17.661 ms
64 bytes from 213.180.146.27: seq=113 ttl=56 time=17.538 ms
64 bytes from 213.180.146.27: seq=114 ttl=56 time=18.852 ms
64 bytes from 213.180.146.27: seq=115 ttl=56 time=18.840 ms
64 bytes from 213.180.146.27: seq=116 ttl=56 time=16.696 ms
64 bytes from 213.180.146.27: seq=117 ttl=56 time=18.832 ms
64 bytes from 213.180.146.27: seq=118 ttl=56 time=17.900 ms
64 bytes from 213.180.146.27: seq=119 ttl=56 time=19.204 ms
64 bytes from 213.180.146.27: seq=120 ttl=56 time=17.687 ms
64 bytes from 213.180.146.27: seq=121 ttl=56 time=18.690 ms
64 bytes from 213.180.146.27: seq=122 ttl=56 time=17.623 ms
64 bytes from 213.180.146.27: seq=123 ttl=56 time=17.092 ms
64 bytes from 213.180.146.27: seq=124 ttl=56 time=17.017 ms
64 bytes from 213.180.146.27: seq=125 ttl=56 time=16.934 ms
64 bytes from 213.180.146.27: seq=126 ttl=56 time=18.230 ms
64 bytes from 213.180.146.27: seq=127 ttl=56 time=18.504 ms
64 bytes from 213.180.146.27: seq=128 ttl=56 time=18.247 ms
64 bytes from 213.180.146.27: seq=129 ttl=56 time=18.129 ms
64 bytes from 213.180.146.27: seq=130 ttl=56 time=18.088 ms
64 bytes from 213.180.146.27: seq=131 ttl=56 time=18.237 ms
64 bytes from 213.180.146.27: seq=132 ttl=56 time=17.805 ms
64 bytes from 213.180.146.27: seq=133 ttl=56 time=17.618 ms
64 bytes from 213.180.146.27: seq=134 ttl=56 time=27.373 ms
64 bytes from 213.180.146.27: seq=135 ttl=56 time=17.532 ms
64 bytes from 213.180.146.27: seq=136 ttl=56 time=19.274 ms
64 bytes from 213.180.146.27: seq=137 ttl=56 time=18.434 ms
64 bytes from 213.180.146.27: seq=138 ttl=56 time=18.967 ms
64 bytes from 213.180.146.27: seq=139 ttl=56 time=20.173 ms
64 bytes from 213.180.146.27: seq=140 ttl=56 time=18.237 ms
64 bytes from 213.180.146.27: seq=141 ttl=56 time=20.001 ms
64 bytes from 213.180.146.27: seq=142 ttl=56 time=17.894 ms
64 bytes from 213.180.146.27: seq=143 ttl=56 time=18.266 ms
64 bytes from 213.180.146.27: seq=144 ttl=56 time=18.208 ms
64 bytes from 213.180.146.27: seq=145 ttl=56 time=19.630 ms
Oczywiście informacje o przełączeniu znajdziemy też w logach (logread) - oto wycinek z logów:
May 7 14:38:16 OpenWrt user.notice multiwan: Succesfully Initialized on Sat, 07 May 2011 14:38:16 +0000.
May 7 14:38:48 OpenWrt kern.info kernel: eth1: link down
May 7 14:39:13 OpenWrt user.notice multiwan: wan has failed and is currently offline.
May 7 14:39:30 OpenWrt kern.info kernel: eth1: link up (100Mbps/Full duplex)
May 7 14:40:16 OpenWrt user.notice multiwan: wan has recovered and is back online!
PS. Istnieje także odpowiedni pakiet dla LuCI (luci-app-multiwan) który umożliwia wyklikanie konfiguracji w gui.
----- Dodano ----- 8 maja 2011, o 08:22 -----
Wydzielenie drugiego portu wan na podstawie konfiguracji w TP-Linku TP-WR1043ND.
Standardowa konfiguracja przełącznika w w/w urządzeniu wygląda następująco:
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '1'
option 'ports' '1 2 3 4 5t'
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '2'
option 'ports' '0 5t'
eth0.1 wykorzystywane jest jako lan, eth0.2 jako wan. Wystarczy więc odpowiednio podzielić konfiguracje:
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '1'
option 'ports' '2 3 4 5t'
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '2'
option 'ports' '0 5t'
config 'switch_vlan'
option 'device' 'rtl8366rb'
option 'vlan' '3'
option 'ports' '1 5t'
Dzięki czemu został zrobiony nowy interfejs, eth0.3
eth0.1 składa się z fizycznych portów 2, 3 i 4 i odpowiada za lan,
eth0.2 składa się z fizycznego portu wan i odpowiada za wan,
eth0.3 składa się z fizycznego portu 1 i może odpowiadać za wan2
Zostaje tylko stworzenie nowej sekcji wan2 i wskazanie interfejsu eth0.3.