I have:
- Raspi 3b+
- 1st internet connection on eth0 through built in adapter
- 2nd internet connection on eth1 through a USB-dongle
I followed the official manual and the AP is running just fine.
What I'm trying to do is routing the traffic though eth1 when no internet connection is available on eth0. It's working but with a very big latency and packets drops.
Case 1:
eth0 has internet
eth1 has internet
Result: everything works smoothly.
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.254 0.0.0.0 UG 202 0 0 eth0
default 192.168.8.1 0.0.0.0 UG 205 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
192.168.8.0 0.0.0.0 255.255.255.0 U 205 0 0 eth1
192.168.253.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
Case 2:
eth0 has no internet anymore
eth1 has internet
Result: big latency, packets drops.
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.8.1 0.0.0.0 UG 205 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
192.168.8.0 0.0.0.0 255.255.255.0 U 205 0 0 eth1
192.168.253.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
# cat /etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf
interface=wlan0
server=8.8.8.8
server=8.8.4.4
dhcp-range=192.168.253.2,192.168.253.254,255.255.255.0,12h
dhcp-authoritative
# iptables-save
# Generated by iptables-save v1.6.0 on Sun May 5 18:44:06 2019
*nat
:PREROUTING ACCEPT [2637:573309]
:INPUT ACCEPT [605:71308]
:OUTPUT ACCEPT [658:46686]
:POSTROUTING ACCEPT [10:1489]
-A POSTROUTING -o eth1 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Sun May 5 18:44:06 2019
# Generated by iptables-save v1.6.0 on Sun May 5 18:44:06 2019
*filter
:INPUT ACCEPT [1667:192581]
:FORWARD ACCEPT [24823:15540031]
:OUTPUT ACCEPT [1590:161791]
-A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o eth1 -j ACCEPT
COMMIT
# Completed on Sun May 5 18:44:06 2019
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.103 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 zzzzzzzzzzzzzzz prefixlen 64 scopeid 0x20<link>
ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)
RX packets 133500 bytes 132927619 (126.7 MiB)
RX errors 0 dropped 12 overruns 0 frame 0
TX packets 97296 bytes 63923420 (60.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.8.100 netmask 255.255.255.0 broadcast 192.168.8.255
inet6 vvvvvvvvvvvvvvvv prefixlen 64 scopeid 0x20<link>
ether yy:yy:yy:yy:yy:yy txqueuelen 1000 (Ethernet)
RX packets 23672 bytes 11549930 (11.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19765 bytes 10665918 (10.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 253 bytes 30503 (29.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 253 bytes 30503 (29.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.253.1 netmask 255.255.255.0 broadcast 192.168.253.255
inet6 mmmmmmmmmmmmmmmmmmmm prefixlen 64 scopeid 0x20<link>
ether aa:aa:aa:aa:aa:aa txqueuelen 1000 (Ethernet)
RX packets 155008 bytes 100683215 (96.0 MiB)
RX errors 0 dropped 8 overruns 0 frame 0
TX packets 193745 bytes 187522062 (178.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
When the USB dongle is plugged into PC I have a smooth Internet connection, so it's not a problem of the dongle.
Could anyone please help me to figure out what's going on and how to fix that? Thanks in advance.
[UPDATE]
Update infos from comments on answer: Mean while I have another problem after configuring bonding for interfaces. Eth1 is the usb-modem, which becomes the Ethernet interface with usb_modeswitch. When this interface is not bonding - it becomes 'up' with ip address (common situation). When bonding - eth1 is down, however the eth0 is up. I believe, the problem comes from usb dongle router.
Definitely, this issue happens right after I disable dhcp on eth1. echo "denyinterfaces eth0 eth1" >> /etc/dhcpcd.conf