0

setup: linux is configured with Eth0 and wwan0 interface. Eth0 is connected to ethernet and wwan0 is connected via dongle.Both of the connection are having internet connectivity.

Problem: When I bring-up my device, the default route is eth0 and I can ping eth0 as well. Although wwan0 is also up, but not able to ping through eth0. If I disconnect eth0, ping works fine with wwan0. Now If I insert ethernet again, I can't ping with eth0. In my test case, I need to handle frequent insertion of ethernet and dongle.

ifconfig -a

eth0      Link encap:Ethernet  HWaddr 70:B3:D5:9A:EF:FC
      inet addr:192.168.2.166  Bcast:192.168.3.255  Mask:255.255.252.0
      inet6 addr: fe80::72b3:d5ff:fe9a:effc%1996138192/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:129768 errors:0 dropped:0 overruns:0 frame:0
      TX packets:61524 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:12669568 (12.0 MiB)  TX bytes:1411543 (1.3 MiB)

wlan0     Link encap:Ethernet  HWaddr 60:F1:89:39:07:8E
          inet addr:192.168.42.1  Bcast:192.168.42.255  Mask:255.255.255.0
          inet6 addr: fe80::62f1:89ff:fe39:78e%1996138192/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2865 errors:0 dropped:0 overruns:0 frame:0
          TX packets:704 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:530933 (518.4 KiB)  TX bytes:152134 (148.5 KiB)

wwan0     Link encap:Ethernet  HWaddr 00:1E:10:1F:00:00
          inet addr:10.166.235.232  Bcast:10.166.235.239  Mask:255.255.255.240
          inet6 addr: fe80::21e:10ff:fe1f:0%1996138192/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:194 errors:0 dropped:0 overruns:0 frame:0
          TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30622 (29.9 KiB)  TX bytes:40449 (39.5 KiB)

Route when eth0 is default

default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
8.8.8.8         192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
10.166.235.224  *               255.255.255.240 U     0      0        0 wwan0
59.144.127.17   192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
192.168.0.0     *               255.255.252.0   U     0      0        0 eth0
192.168.2.1     *               255.255.255.255 UH    0      0        0 eth0
192.168.42.0    *               255.255.255.0   U     0      0        0 wlan0

Ping status at this time:

# ping -I eth0 -c 3 -W 10 www.google.com
PING www.google.com (172.217.166.36): 56 data bytes
64 bytes from 172.217.166.36: seq=0 ttl=57 time=17.688 ms
64 bytes from 172.217.166.36: seq=1 ttl=57 time=16.523 ms
64 bytes from 172.217.166.36: seq=2 ttl=57 time=16.279 ms

--- www.google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 16.279/16.830/17.688 ms
# ping -I wwan0 -c 3 -W 10 www.google.com
PING www.google.com (172.217.166.36): 56 data bytes


--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss

Trace route for wwan0

# traceroute -i wwan0 www.google.com
traceroute to www.google.com (172.217.166.36), 30 hops max, 38 byte packets
 1  local (10.166.235.232)  2996.178 ms !H  2995.670 ms !H  2999.194 ms !H
Here packets are getting dropped at wwan0 interface only.

Iptable -L

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             tcp dpts:0:1023
ACCEPT     udp  --  anywhere             anywhere             udp dpts:0:1023

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             192.168.0.0/16
ACCEPT     all  --  192.168.0.0/16       anywhere
ACCEPT     all  --  anywhere             192.168.0.0/16

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

IP table is same when wwan0 is the default route.

In short, among two interfaces, I can always ping only interface with default. Please help me so that I can ping on any interface at any time.

I tried to add default route for wwan0 with

ip route change to default dev wwan0 via 10.166.235.230

but after this I can ping through wwan0 but not through eth0.

EDIT1

I can solve this issue with adding route to eth0 and wwan0 each time I plug them back. But now, I need to add gateway to route for each interface. In my route table somehow, I can see only one gateway(default), not the other one. If I can get gateway for both the interface, I can run a script which will run as soon some plug/un-plug happens and can add route again. Please help regarding this.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
8.8.8.8         192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
**10.177.88.96    *               255.255.255.240 U     0      0        0 wwan0**
59.144.127.17   192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
192.168.0.0     *               255.255.252.0   U     0      0        0 eth0
192.168.2.1     *               255.255.255.255 UH    0      0        0 eth0
  • 2
    Probably a duplicate of several other posts, the answer to all of which is "you need policy routing via ip rule". – grawity Mar 15 '18 at 9:23
  • Can you please give me an example of that. My use case is that when ethernet is connected, internet should be always accessed to ethernet and when ethernet is removed, it should use the dongle. – Ashish Mar 15 '18 at 9:29
  • If I need to add default gateway in route for both the interface, how can I make sure that I get default gateway on the fly. My ifconfig -a doesn't provide gateway information. – Ashish Mar 16 '18 at 8:16
  • If you want to switch between a single default route on eth0/wwan0 depending on whether eth0 is up or down, you need to find out which part of your system is setting the routes. There are several candidates (network manager, traditional ifup/ifdown scripts, DCHP client(s) once an interface is up). Once you've found out, configure the candidates correctly. Note that the routes you receive via DHCP may be different each time. – dirkt Mar 16 '18 at 12:22
  • My standard (but quite obsolete) example there: lartc.org/howto/lartc.rpdb.multiple-links.html . 4.2 and 4.2.1 are ok, 4.2.2 probably can't work anymore as is – A.B Mar 16 '18 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.