5

I have a scenario where I have a cellular Wifi hotspot modem also known as 'MiFi'. The problem I am encountering is all the tutorials I have come across are mostly outdated or purely just don't work.

What I am trying to achieve is the following:

  1. Having my Rpi 3 setup to handle all communication between devices (cellular, laptop and desktop)
  2. Desktop with ethernet cable to have internet and possibly communicate with laptops if necessary
  3. The WiFi modem only acts as a hotspot for the Rpi 3 and preferably nothing else all other devices communicate through the Rpi 3

I have the following equipment: Raspberry Pi 3B Panda Pau05 wireless adapter 16GB Memory card with Raspbian Stretch Lite Installed on it And then of course power adapter.

My aim is to have the internal wifi of the adapter connect to the WiFi modem, the Wireless adapter as a Hotspot and then the ethernet to provide internet to the Switch or Desktop with internet.

I don't mind if the Rpi 3 is on a different IP Range (eg:192.168.2.x) from the WiFi Modem (eg:192.168.1.x)

If anyone has managed something like this or can point me to a more recent post please that would be highly appreciated

user92651
  • 61
  • 1
  • 4

2 Answers2

2

You do not need a second wireless adapter. The Raspberry Pi is able to work as a wireless hotspot and simultanous connect to another hotspot as client. But the wifi device on the RasPi has a general limitation. The client connection cannot be bridged because lack of WDS (wireless distribution system) that is needed for bridging on wireless. But as you say that is no problem because you can use routing with different subnets. The wifi hotspot and the ethernet port can be bridged so your laptop on wifi and the desktop on wired ethernet are on a common subnet. So it seems that all fit your needs. How to configure it you can look at Wireless access point with bridged wired ethernet port and wireless client connection.

If you want to use a second wifi adapter you can look at RPI3 Raspbian Stretch regular connection on wlan0 AP on wlan1. It is only for connecting two wifi devices but you may get an idea how it could work.

Update:
As from the comments you used the same subnet from the internet router for the access point (AP) but fixed it by using a different subnet for the AP. Now you can ping 8.8.8.8, the google DNS nameserver on the internet from a device attached to the ethernet port eth0 but you cannot ping 8.8.8.8 from a device connected to the AP (ap0). That is something I do not understand. eth0 and ap0 are bridged, so on the ethernet link layer (OSI layer 2) there is no difference between both interfaces. Either both work or none of them. Maybe there is a problem with flood on/off on the interface but I don't believe it because of correct default settings. Or the device on the AP is the problem. On my tests with many bring up and shut down of the AP my mobile phone get stuck and I had to restart it. Try this first.

Then check if eth0 and ap0 are both slave interfaces of the bridge with:

rpi ~$ bridge link show
2: eth0 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 4
5: ap0 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100

Check if ip forwarding is active and the default route is set to the internet router:

rpi ~$ cat /proc/sys/net/ipv4/ip_forward   # should give 1
1

rpi ~$ ip route show
default via 192.168.10.1 dev wlan0 proto dhcp src 192.168.10.125 metric 1024
10.0.0.0/24 dev br0 proto kernel scope link src 10.0.0.1
192.168.10.0/24 dev wlan0 proto kernel scope link src 192.168.10.125
192.168.10.1 dev wlan0 proto dhcp scope link src 192.168.10.125 metric 1024

The line with default must point to the internet router and the source must be the ip address from wlan0.

Then NAT (network address translation) must be enabled. Check with:

rpi ~$ sudo iptables --table nat --list POSTROUTING --verbose
Chain POSTROUTING (policy ACCEPT 5 packets, 479 bytes)
 pkts bytes target     prot opt in     out     source               destination
   36  2685 MASQUERADE  all  --  any    wlan0   anywhere             anywhere

Yes, and sometimes ap0 gets stuck with unknown reason and needs a kick with:

rpi ~$ sudo ip link set ap0 up
Ingo
  • 40,606
  • 15
  • 76
  • 189
  • Hi Ingo. the first [link](https://raspberrypi.stackexchange.com/a/89804/79866) you provided me really helped a lot thank you so much. I am unable to comment on the post asking for help hence why I am commenting here now However I have managed to get internet connection to the ethernet port now which is exactly what I am looking for. I was not able to get internet connection when connecting to the ap0(RPiNet) Any suggestions going forward please? I have copy and pasted everything across using ssh. @Ingo – user92651 Oct 11 '18 at 13:49
  • Hi @user92651, your question was a trigger for me to optimize that answer. I have added routing through **wlan0** to the internet and reduced the setup for 2 steps. I have made some updates the last two days and I don't know what version you have used. The first versions weren't able to connect to the internet. The version just now can. You should have a look at it, but I'm still working on it. Please feel free to comment here and tell we what's going wrong. – Ingo Oct 11 '18 at 14:07
  • @user92651 And yes, you are free to up vote that linked answer ;-) – Ingo Oct 11 '18 at 14:16
  • Hi @Ingo, I have upvoted the your post thanks, unfortunately I am under 15 points so it doesn't show yet. However, I have redone everything just to make sure I wasn't missing anything. I am not sure about the versions you are running but I have followed the one on this [link](https://raspberrypi.stackexchange.com/questions/89803/wireless-access-point-with-bridged-wired-ethernet-port-and-wireless-client-conne/89804#89804) 'you mentioned reduced the setup for 2 steps' where about can I find this please. at the moment I am not using a secondary adapter only the onboard chip. – user92651 Oct 11 '18 at 14:52
  • @user92651 This version with 4 steps you linked to should work. I have just tested it three hours ago. At the end of the answer there is a link `edited $time ago`. You can click on this link and you will see the change history. The versions before had two steps more to create unneeded help services. – Ingo Oct 11 '18 at 15:10
  • ,my laptop gets an ip of x.x.8.53 through ethernet from pi, my iPad gets x.x.8.104 from router. can't ping iPad from laptop or pi. when laptop connects to RPiNet I still don't have internet unfortunately, but do get an ip of x.x.8.83 and cant ping anything. I have had a look, and I am definitely using the latest version you posted step for step. However. would it possibly be caused by the fact that I am using a pi 3 model b instead of b+? Sorry for hassling you like this and I truly do appreciate all the help you have provided so far. – user92651 Oct 11 '18 at 15:33
  • @user92651 I'm glad about feedback. It helps me to improve the setup. Subnet from your internet router is just x.x.8.0/24. **eth0** port and access point (**ap0**) have the same subnet (because of bridge) and it is also x.x.8.0/24. That cannot work because they must have different subnets (routing), e.g. x.x.8.0/24 for internet router and x.x.9.0/24 for eth0/AP. Are you able to ping ip addr. of **br0** from the laptop connected to AP? It doesn't matter if you use RPi3B or RPi3B+. – Ingo Oct 11 '18 at 15:58
  • @user92651 What ip address gets **wlan0** by DHCP from the internet router? – Ingo Oct 11 '18 at 16:07
  • sorry for getting back so late. br0 on pi has ip of x.x.8.1 when connected through ethernet from pi to laptop. ap0 has no ip in ifconfig on pi. wlan0 has ip of x.x.8.100 on pi laptop has ip of x.x.8.53 connected to RPiNet laptop eth0 gets ip of x.x.8.37 from pi. What I will try is change the ip quickly and see if that changes anything. will keep you posted – user92651 Oct 11 '18 at 17:14
  • I am unable to create a chat as I don't have enough user points. I went and created x.x.9.1/24 subnet as you were right I was on the wrong subnet. funny enough same results at the moment as previously. I can ping br0 @ x.x.9.1 from x.x.9.53 on ap0 but cant ping 8.8.8.8. I can ping br0 @ x.x.9.1 from x.x.9.37 on eth0 and can ping 8.8.8.8 same results as earlier when both subnets were the same. Confirmed on pi ifconfig: ap0 no ip, br0 is 192.168.9.1, eth0 no ip, wlan0 is 192.168.8.100, subnet of router is 192.168.8.x – user92651 Oct 11 '18 at 17:46
  • @user92651 I have updated my answer. – Ingo Oct 11 '18 at 21:37
  • pi@raspberrypi:~ $ ip route show default via 192.168.8.1 dev wlan0 proto dhcp src 192.168.8.102 metric 1024 192.168.8.0/24 dev wlan0 proto kernel scope link src **192.168.8.102** **192.168.8.1** dev wlan0 proto dhcp scope link src 192.168.8.102 metric 1024 **192.168.9.0/24** dev br0 proto kernel scope link src **192.168.9.1** , sudo iptables --table nat --list POSTROUTING --verbose , I just have more packets and bytes, Those in bold seem to be using wrong ip addr. I will try get them fixed today. Do you think it will be more stable using a secondary Wifi adapter by any chance? – user92651 Oct 12 '18 at 06:45
  • @user92651 I cannot read your comment. Can you please edit your question and put it into there? Using a second wifi adapter will not solve your routing problems. – Ingo Oct 12 '18 at 09:01
  • @user92651 Since my last program revision I had left a bug. The access point did not start automatically after boot. Sorry for that. The AP should come up with `sudo ip link set ap0 up`. But of course I have fixed the bug. **wpa_supplicant@wlan0.service** (`sudo systemctl edit wpa_supplicant@wlan0.service`) has changed there is a new service **ap-bring-up.service**. It can take up to 30 seconds until the AP is up. – Ingo Oct 14 '18 at 15:48
1

I have managed to get a working connection from wifi through to ethernet. I changed the network manager used on Raspbian to Network-manager-gnome and deviated from stretch-lite to stretch fully updated

  1. Install Network Manager Gnome

    sudo apt install network-manager network-manager-gnome

  2. Remove the unneeded package. (vital step else network-manager-gnome won't work at all)

    sudo apt purge openresolv dhcpcd5

  3. Now go to the top right corner and remove 'wireless and wired network' from the panel items

  4. Reboot the system (the new network manager panel should appear after reboot

    reboot

5.1 Right click on new network manager icon 5.2 edit connections 5.3 click on 'Wired Connection 1' the click on edit 5.4 select 'IPv4 Settings' 5.5 'Method drop down menu' then select 'Shared to other computers'

You can also add an adhoc, wifi sharing to other computers and a few others with this Network Manager.

Please note that I have not yet figured out how to configure the DHCP IP address settings to create your own range as it creates one in the 10.42.x.x range if I remember correct.

I have also noticed that if you are using a Mac that and connected to pi with ethernet that you preferably have to turn off your 'wifi' else the laptop battles to receive an IP Address even after renewing DHCP Lease

I haven't yet tried other settings with the wifi yet as it was out of my reach for the purpose I needed it but will give it a test some time soon and give feedback.

Ping time to 8.8.8.8

64 bytes from 8.8.8.8: icmp_seq=0 ttl=119 time=56.365 ms 64 bytes from 8.8.8.8: icmp_seq=1 ttl=119 time=42.128 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=119 time=50.178 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=119 time=68.017 ms

Thank you @Ingo for being such an amazing help at the time before I came to this solution

user92651
  • 61
  • 1
  • 4