2

I want to share my phone data by connecting to my pi4 running buster. I wish the data to pass through the ethernet which has a router connected to it. The router has both wireless and wired connections. The router will be used as normal as if the data was coming directly to it say via an ethernet broadband connection.

This is simple in windows, I share my NDIS network adaptor(my phone) with ethernet 2 the nic on my pc. The router is connected to the network port and broadcasts to my other devices.
How or can this be done in Raspbian.

I have looked up guides but they all seem to mention using the pi as a DHCP server, not too sure that I want/need this.
tia

6
  • I'm not using MS Window$ so I do not understand how its network sharing works. Just to understand why your clients find the default gateway to the internet: does all clients incl. phone and MS Windows are on the same subnet (all have an ip address from the same address range)? Do you know if there is a DHCP server running on the MS Windows PC? Is it possible that there are two DHCP server running (router and MS Win PC)?
    – Ingo
    Jan 6, 2020 at 9:42
  • it is possible but of course I do not know or care, it works and that is what I am looking for.
    – freezing77
    Jan 6, 2020 at 20:07
  • I'm afraid you will not have luck with just point and click on a Raspberry Pi. It is made for learning hardware and Unix. You should not use it. Sell it on ebay.
    – Ingo
    Jan 6, 2020 at 20:17
  • I do use one as a file server. I will come up with a more interesting project for the other one.
    – freezing77
    Jan 7, 2020 at 0:08
  • I'm not sure that you will find some one now who is willing to take effort for helping you, but only to hear "that's to much for me".
    – Ingo
    Jan 7, 2020 at 0:31

2 Answers 2

2

As you mentioned, it's easy to do it on Windows OS, however, it's a bit different on Raspberry Pi and Linux.

I have looked up guides but they all seem to mention using the pi as a DHCP server, not too sure what I want/need this.

In your situation, the phone is a device that has an internet connection. Obviously, the devices/clients must connect to your phone anyhow.
So, as you did, you must connect the phone to the RPi, and, connect RPi to the router. In this way, the router's clients connected to your phone logically with the RPi as a bridge.
What's the problem? The clients connected logically by hardware sight but they didn't connect to the phone by software sight and OSI model.
The clients connected to the router, in the router, there is a DHCP server which the gateway IP address has configured is the router's IP address. I mean, the gateway of the clients is the router. Therefore, the clients send their outside packet (the destination of the packets is not in the local LAN) to the router and the router has no internet connectivity hence the clients have no, too.

To solve this problem, you need to route clients' outside packets to the phone. I mean, the phone must be the client's gateway.
The problem here is, you can not connect the phone directly to the router, by that, we set the RPi as a gateway and config RPi to forward clients' outside packets to the phone virtual interface.


Follow the instructions on Raspberry Pi:
Take into consideration that we imagined the phone virtual interface of the Raspberry Pi is eth1.

1. Set a static IP address to the eth0 which would be router's clients' default gateway. To do it, there is plenty of procedure:

sudo nano /etc/dhcpcd.conf 

Put lines below to this file:

interface eth0
static ip_address=192.168.100.254/24

2. Install the DHCP server package:

sudo apt-get -y install dnsmasq 

3. Configure the DHCP server. At first, create a backup of the config file:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak  

sudo nano /etc/dnsmasq.conf  

Put lines below to this file:

interface=eth0 
listen-address=192.168.100.254
bind-interfaces 
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.100.10,192.168.100.100,24h  

4. Enable IP Forwarding to forward router's clientsi packets:

nano /etc/sysctl.conf 

Uncomment this line:

net.ipv4.ip_forward=1  

5. Follow these commands for the firewall to allow forwarding between interfaces:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT  

sh -c "iptables-save > /etc/iptables.ipv4.nat"  

6. Open rc.local to add command for restoring firewall configuration on each RPi startup:

sudo nano /etc/rc.local  

Add this line before Exit 0:

iptables-restore < /etc/iptables.ipv4.nat  

7. Make sure that eth1 is on DHCP mode to get ip address from the phone.

Now, you have configured Raspberry Pi as a bridge for the router to the phone.


Router configuration:
In this step, you must disable any static routes and disable the DHCP server of the router because the DHCP requests of the clients must forward to the RPi interface.

8
  • 1
    Thank you very much for your time and effort but I suspect the answer may be beyond me. Will stick with my windows set up for this. Would have liked to have used a low powered pi but I can see the OS it is not for the mainstream as yet.
    – freezing77
    Jan 3, 2020 at 18:16
  • 1
    What is your definite purpose?
    – M. Rostami
    Jan 3, 2020 at 22:13
  • 1
    As in my original request, I have a spare desktop I am using but would have preferred to use the pi .A bit greener. Additionally I have a file server connected to the router using a static IP. I would prefer not to mess with both the pi, the router with dhcp and the file server and plex server. KISS and all that.
    – freezing77
    Jan 3, 2020 at 22:55
  • 1
    As you said, I share my NDIS network adaptor(my phone) with ethernet 2 the nic on my pc. The router is connected to the network port and broadcasts to my other devices. To achieve this feature on Raspbian, you need to follow this answer. It's impossible to do it with the router's DHCP server. How you have done it by Windows?
    – M. Rostami
    Jan 3, 2020 at 23:10
  • To share in windows just select the ndis adaptor, choose share this internet connection, in the pull down menu I choose ethernet 2 and that is it. So anything connected to ethernet 2 has access to mobile data in this cause I connect ethernet 2 to the wan port on my router which then deals with the rest of the network. I am currently typing this on a laptop connected by wifi to said router. Data being provided by my old Samsung S4 acting as a "modem"
    – freezing77
    Jan 4, 2020 at 10:07
0

Please note the port designations ETH0 and ETH1 should be reversed in step 5 above. You want internal to external packets accepted by default, not vice versa.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.