OpenWrt Forum Archive

Topic: 2 WANs (Ethernet & Wi-Fi, same gw). Is to possible to prefer Ethernet?

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello!

I have OpenWrt Attitude Adjustment 12.09.1 and a device with two WANs with the same gateway:
WAN1. Ethernet with static IP - 192.168.3.111, gateway 192.168.3.1 (hostname ibm_pc_xt), metric 10;
WAN2. Wi-Fi with static IP - 192.168.3.222, gateway 192.168.3.1 (hostname ibm_pc_xt), metric 20.

My /etc/config/network is:

config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config interface 'wan1'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '192.168.3.111'
    option netmask '255.255.255.0'
    option gateway '192.168.3.1'
    option dns '192.168.3.1'
    option send_rs '0'
    option metric '10'

config interface 'wan2'
    option proto 'static'
    option netmask '255.255.255.0'
    option gateway '192.168.3.1'
    option dns '192.168.3.1'
    option send_rs '0'
    option ipaddr '192.168.3.222'
    option metric '20'

My /etc/config/wireless is

config wifi-device 'wlan0'
    option type 'mac80211'
    option disabled '0'
    option channel 'auto'

config wifi-iface
    option ssid 'Wnet'
    option encryption 'psk2'
    option device 'wlan0'
    option mode 'sta'
    option network 'wan2'
    option key '_keykeykeykey_'

If I connect Ethernet cable and setup Wi-Fi I get 4 lines in route table:

route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         ibm_pc_xt       0.0.0.0         UG    10     0        0 eth0
default         ibm_pc_xt       0.0.0.0         UG    20     0        0 wlan0
192.168.3.0     *               255.255.255.0   U     10     0        0 eth0
192.168.3.0     *               255.255.255.0   U     20     0        0 wlan0

and I can ping from both devices:

 ping -c1 google.com -I eth0
PING google.com (173.194.47.166): 56 data bytes
64 bytes from 173.194.47.166: seq=0 ttl=56 time=10.085 ms

--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 10.085/10.085/10.085 ms


ping -c1 google.com -I wlan0
PING google.com (173.194.32.136): 56 data bytes
64 bytes from 173.194.32.136: seq=0 ttl=56 time=18.184 ms

--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 18.184/18.184/18.184 ms

If I disconnect Ethernet cable I can't ping by hostname, only by IP with wlan0 specified:

ping -c1 google.com -I wlan0
ping: bad address 'google.com'

ping -c1 8.8.8.8 -I wlan0
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=48 time=27.355 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 27.355/27.355/27.355 ms

If wlan0 is not specified I can't ping:

ping -c1 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss

 ping -c1 google.com
ping: bad address 'google.com'

So I have two questions:
1. Is it possible to correctly setup two WANs with the same gateway?
2. Is it possible to use WAN2 (Wi-Fi) only if WAN1 (Ethernet) is not available?

I read about multiwan and mwan3. But it seems that they does not solve my problem.

Do I need to write special script/program or I can use existent ones?
What do you recommend?


With best regards,
Norko.

(Last edited by norko.solko on 24 Aug 2013, 22:36)

this seems to me exactly what you need (from mwan3):

- provides outbound WAN traffic load balancing over multiple WAN interfaces based on a numeric weight assignment
- monitors each WAN connection using repeated ping tests and can automatically route outbound traffic to another WAN interface if the first WAN interface loses connectivity

why do you think it does not solve your problem?

nebbia88, thank you for reply.

I have the following config for it (/etc/config/mwan3):

config interface 'wan1'
    option enabled '1'
    option reliability '2'
    option count '1'
    option timeout '2'
    option interval '5'
    option down '3'
    option up '8'
    list track_ip '192.168.3.1'
    list track_ip '8.8.8.8'
    option reroute '1'

config interface 'wan2'
    option enabled '1'
    option reliability '1'
    option count '1'
    option timeout '2'
    option interval '5'
    option down '3'
    option up '8'
    list track_ip '192.168.3.1'
    list track_ip '8.8.8.8'
    option reroute '1'

config member 'wan1_m1_w3'
    option interface 'wan1'
    option metric '1'
    option weight '3'

config member 'wan1_m2_w3'
    option interface 'wan1'
    option metric '2'
    option weight '3'

config member 'wan2_m1_w2'
    option interface 'wan2'
    option metric '1'
    option weight '2'

config member 'wan2_m2_w2'
    option interface 'wan2'
    option metric '2'
    option weight '2'

config policy 'wan1_pri_wan2_sec'
    list use_member 'wan1_m1_w3'
    list use_member 'wan2_m2_w2'

May be I did not configured it correctly.

I tested same configuration on laptop with Ubuntu 12.04.3 - both Wi-Fi and Ethernet are connected to the same gateway with static IPs.
I can ping from these two interfaces and I can access my laptop from local network on two IPs.

Any ideas why it does not work on OpenWRT?

The discussion might have continued from here.