Alan_uk
Posts: 10
Joined: Fri Apr 14, 2017 7:03 pm

Trying to access LAN via cable and WAN via mobile tethering

Wed May 03, 2017 2:19 pm

Hi
I have a presentation next Tues to U3A on the internet of things and wish to demonstrate IoT gadgets that I have using Node-Red on a Raspberry Pi 3 with Jessie (up to date). One of the demos accesses devices on the LAN and services in the cloud. But the venue has no internet so I thought I would try tethering.

My problem is getting the Pi to use the WAN via mobile tethering for external websites / cloud and the LAN via cable for local devices and to run the Pi headless from the same PC as the presentation slides.

I updated /etc/dhcpcd.conf and added at the bottom:

interface eth0
static routers=192.168.43.190 <<< my android phone - this is shown on the phone's tethering page when connected.
static domain_name_servers=8.8.8.8 8.8.4.4 <<< google DNS

After rebooting
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.43.190 0.0.0.0 UG 202 0 0 eth0
0.0.0.0 192.168.43.1 0.0.0.0 UG 303 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
192.168.43.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
192.168.43.190 0.0.0.0 255.255.255.255 UH 202 0 0 eth0

As I understand it the G means the gateway (i.e. internet access point).

I also listed /etc/resolv.conf:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 192.168.43.1
nameserver 2001:4860:4860:8888
nameserver 2001:4860:4860:8844

With ethernet cable plugged in but the WAN disabled on the Draytex, the Pi will not access web pages (both using domain names and IPs) and says "unreachable" but I can access and control my devices.
As soon as I unplug the ethernet cable, then the webpage loads (via the phone) but then I cannot reach my devices on the LAN.

My set up is:
Draytek 2760 modem/router with the wi-fi disabled and Strict MAC Bind on all devices to assign the same IP address every time.
Tp-Link TL-WA801N / TL-WA801ND wi-fi linked by cable to the Draytek and configured as an access point and again strict bind.

Ideas very welcome.
Thank you for reading.
Alan
PS I have looked at tethering the phone to the TP-Link but whilst the TP-Link sees the phone the phone does not see the TP-Link . If it did, I suspect I will have the same problem at routing WAN URLs via the phone.

I do have a RaspPi Wifi dongle so possibility of using Pi inbuilt wi-fi to connect to the LAN and the dongle to connect to the phone, but may well have the same routing problem.

Alan_uk
Posts: 10
Joined: Fri Apr 14, 2017 7:03 pm

Re: Trying to access LAN via cable and WAN via mobile tether

Thu May 11, 2017 5:37 pm

I managed to get this working for my situation by successfully tethering the Pi to the phone and removing the Draytek gateway from the Pi routing table. So for the benefit of any people directed from a google search here's what I did.

First thing to say is I learnt that Pi networking changed substantially after 2015, first with Wheezt and then Jessie and any advise given that is based on earlier OS releases is likely to make matters worse.

First I followed this posting https://raspberrypi.stackexchange.com/q ... 7921#37921 and:

- enabled SSH
- restored /etc/network/interfaces
- created/modified /etc/wpa_supplicant/wpa_supplicant.conf and defined the SSID and password for the mobile (see below)

The rest of the post gives 2 methods of setting static IPs but the author says this should not be needed if dhcpcd is doing its job. Personally I have previously in my router bound IPs to MAC addresses so I left that alone and my Pi gets the fixed address assigned by the router. I.e. I did NOT set on the Pi a static address for the Pi.

Second I tested that the PI could reach the internet via the router and also that the PCs on the LAN can access the Pi (I need that to run the Pi headless).

On the Pi type: route
to give something like this:
----------------------------
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 202 0 0 eth0
192.168.1.0 * 255.255.255.0 U 202 0 0 eth0
----------------------
Where G indicates Gateway.
This says send everything (default) to 192.168.1.1 the router gateway - i.e. to the WAN/internet except when the destination is 192.168.1.xxx (i.e. for other devices on the LAN - LAN addresses are always 192.168.1.xxx)

Also type: ip route show
for the same information in a different format.
--------------------
default via 192.168.1.1 dev eth0 metric 202
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.28 metric 202
--------------------

Third I set the PI WAN cable to be hot pluggable - this stops the wifi being lost when the WAN is lost or the ethernet cable unplugged.
- Create/edit /etc/default/ifplugd
INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

Fourth I enabled Tethering on my Samsung Android phone:
- click Settings / Tethering and Mobile Hotspots.
- click on Mobile Hotspot (this is not intuitive as it looks like a heading).
- click on the menu 3 dots and click on Configure hotspots.
- give your phone an ID (Network SSID), set security (WPA2 PSK is best) and a good password. Click Save.
- click on the slide button at the top right to connect - it goes green
- after 1 minute or so the phone should display the ID of the Raspberry Pi, the MAC address of the phone and the IP address of the phone. My IP address was 192.168.43.190. I believe the PI gives all wifi connections a 192.168.43.xxx address.
- run: route
which gives:
--------------------------
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 202 0 0 eth0
default 192.168.43.1 0.0.0.0 UG 303 0 0 wlan0
192.168.1.0 * 255.255.255.0 U 202 0 0 eth0
192.168.43.0 * 255.255.255.0 U 303 0 0 wlan0
--------------------------
We now have 2 gateways (Gs) to the WAN/internet, the first going to the router and the second to the phone.

Now removing the internet cable (or disabling WAN in the router) does not make the Pi switch to using the phone as it has no way of knowing the internet has been disconnected. Even a timeout does make it try the alternative phone (I believe there are network configurations that will do this)

- run: ip route show
again to give something like:
--------------------------
default via 192.168.1.1 dev eth0 metric 202
default via 192.168.43.1 dev wlan0 metric 303
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.28 metric 202
192.168.43.0/24 dev wlan0 proto kernel scope link src 192.168.43.190 metric 303
--------------------------

Sixth, we need to remove the 192.168.1.1 gateway from the routing table.
Type:
sudo ip route delete default via 192.168.1.1 dev eth0
sudo ip route flush cache

Now again: ip route show
--------------------------
default via 192.168.43.1 dev wlan0 metric 303
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.28 metric 202
192.168.43.0/24 dev wlan0 proto kernel scope link src 192.168.43.190 metric 303
--------------------------
The router gateway has gone leaving the phone as the gateway. However, the PI should be able to access other devices on the LAN.

To test, on a PC run RDP and login to the PI GUI. Open a browser and access an internet site. It should work and your mobile signal symbol should show traffic (hopefully you have a 4G signal).

Seventh: If you need to restore access via the router WAN then key:
sudo ip route add default via 192.168.1.1 dev eth0
sudo ip route flush cache
ip route show

Note: any PC or other device on the LAN cannot access the internet via the Pi and then the phone. Only the Pi can access the internet via the phone. I did find one posting where a guy with a Draytek 2760 router configured the router to use the routers fall back port 4. He then connected the port 4 to the Pi and tunnelled through the Pi (packet forwarding) to the phone. See https://raspberrypi.stackexchange.com/q ... s-wan-port
However, I guess this would stop the Pi accessing the LAN but I may be wrong. Alternatively, I guess, a 2nd Pi could be used to connect to the phone leaving the first Pi free to access the LAN and access the WAN via the router, 2nd Pi and phone.

You might find these links useful:
https://www.debian.org/doc/manuals/debi ... or_the_lan
https://wiki.linuxfoundation.org/networking/iproute2
http://www.policyrouting.org/iproute2.doc.html#ss9.5.3

Alan

iwl
Posts: 27
Joined: Mon Dec 17, 2012 5:35 pm

ifplugd outdated: Trying to access LAN via cable and WAN

Sun Jul 09, 2017 4:29 pm

Hi,

I've just got out that ifplugd is little outdated.

I have an usb-ethernet adapter here and ifplugd as ifplugstatus can't detect cable connected, it always shows connected up, disconnected down.

cat /sys/class/net/eth0/carrier shows cable plugged (1) or not (0) correct if the link is up ( ifconfig eth0 up )
ip link / ip monitor link also shows cable connect / disconnect reading RTNetlink, ifplugd doesn't notice.

Interface has to be up, so after ifdown you have to call ifconfig interface up to keep updated and ifup needs --force to work then, little dirty...

Ifplugd has to be updated or something new made around ip monitor link / RTNetLink.

The scripts around ifplugd haven't worked for me anyway, after some days of trying and rewriting scripts, interfaces, wpa-supplicant-conf on a bananapi internal eth0 ifplugd works with, I now managed to bring up/down usb wlan when I disconnect/connect ethernet cable and they use the same ip, so even ssh mostly survive switching from eth0 to wlan0 and back.

It took a lot of testing and monitoring debug output to hdmi monitor to see whats happen interfaces going up and down.

For the usb ethernet at my pizero I have to change from ifplugd to an own engine around ip monitor link now like told.

Return to “Troubleshooting”