1

I have installed Raspbian OS and enabled vnc through lan cable.(headless setup)[there is no internet on my LAN] both PC & Pi are connected to my router. When I connect my Raspberry Pi's (wifi) to a mobile hotspot (my phone) Raspberry Pi is connected to phone's wifi hotspot but internet is not available on the Pi.

But when I remove the lan cable and only connect the Pi's wifi to phone's hotspot internet seems to be working fine.

How can I setup to use my Pi's wifi (internet access) to download files and store it on a local NAS server(through LAN)?

Any help would be appreciated as i'm new to Linux

RPImaniac
  • 190
  • 1
  • 3
  • 16
new user
  • 11
  • 2
  • There should be no problem with the pi connecting to the internet first time. Are you trying to connect the pi to your network (LAN) and wifi hotspot at the same time? There could be a conflict of IP addresses between your hotspot and LAN which can cause problems. – Philip Couling Mar 08 '18 at 21:31
  • No there can not be a address conflict, the WiFi and LAN has different MAC addresses! It is a matter of routing and metrics. – MatsK Mar 09 '18 at 07:27
  • MAC addresses are always unique unless you spoof them. And totally unrelated in this context. They should never be confused with IP addresses. And don't confuse them with Linux network devices. Having 2 IP addresses in the same IP subnet but different physical networks causes much hilarity and is supprisingly common on `192.168.1.x`. though you might be correct about the default gateway being the issue – Philip Couling Mar 09 '18 at 08:01
  • Please post the output from `route -n` – MatsK Mar 09 '18 at 14:51

2 Answers2

2

When you have two interfaces connected the routing table is deciding what interface to send out the trafic through.check the routing table with:

route -n

By removing the default gateway (example 192.168.nnn.nnn) from the LAN configuration, your routing table for 0.0.0.0 (Internet) there will be no rute to internet trough the LAN only via WiFi.

sudo route delete default gateway 192.168.nnn.nnn

The other way is to change the metric for the 0.0.0.0 route so that the route via LAN has a higher metric than the one for the WiFi.

To make the router taböle permanent check out How to make a change to the routing table persist?

MatsK
  • 2,478
  • 3
  • 12
  • 20
1

This is modified version of MatsK answer. First confirm your default gateway is through the ethernet with just plain route. It will probably include this:

default  gateway  0.0.0.0  UG  0   0   0  eth0

First remove that with sudo route del default. Then, if the phone's hotspot IP is 10.0.0.1, use:

sudo route add default gw 10.0.0.1 dev wlan0
goldilocks
  • 56,430
  • 17
  • 109
  • 217