Page 1 of 1

p2p internet sharing between two RPI 3

Posted: Thu May 04, 2017 9:33 pm
by Stanley783
So my goal basically is as mentioned to share internet from one RPI (connected to internet via ethernet cable) with second RPI using p2p. Now, i connected two RPIs following this guide:

https://raspberrypi.stackexchange.com/q ... -fi-direct

and got them both ping-ing each other. Each p2p-wlan0 has its IP address but i am unable to connect to internet with second one. I would be glad for any help, especially more detailed not like "do DHCP stuff" but would appreciate link to config or basic steps since i am not very skilled.

I am using only implemented p2p module, but if there is another "working" solution for example if u have any experience with batman-adv i would certainly try it.

EDIT: Actually just found this:
https://www.raspberrypi.org/documentati ... s-point.md
but not yet tested. May this thing be "the thing"?

Re: p2p internet sharing between two RPI 3

Posted: Thu May 04, 2017 10:15 pm
by topguy
if you want to keep the "ad-hoc" (or peer2peer) wifi link then I guess you are basically just missing a couple of simple "iptables" rules in the Pi with internet access to get it to route the traffic from the other Pi. You will still have to configure ip-adress and DNS server manually for the "other" pi.
(this is one example I belive: http://www.revsys.com/writings/quicktips/nat.html this is not a guide for Debian so some things might be slightly different on debian.)

But the "Pi as an AccessPoint" method you linked to is probably a more common solution, even if it involves more software. But you then have a AP to connect other wireless devices to too if you want.

Re: p2p internet sharing between two RPI 3

Posted: Fri May 05, 2017 11:46 am
by Stanley783
Thanks for guidance. Yeah, goal is to do this in "ad-hoc" style. I just wonder if "virtual" p2p-wlan0-0 ip address on second Pi (created during p2p connection) counts as sufficient for this or should be configured on wlan0 interface also.

Re: p2p internet sharing between two RPI 3

Posted: Fri May 05, 2017 12:06 pm
by topguy
Stanley783 wrote:Thanks for guidance. Yeah, goal is to do this in "ad-hoc" style. I just wonder if "virtual" p2p-wlan0-0 ip address on second Pi (created during p2p connection) counts as sufficient for this or should be configured on wlan0 interface also.
Both ends of the p2p link must have a complete network config: address + netmask + gateway

Example:
* 1st pi ( the one with ethernet )
adress 192.168.10.1
netmask 255.255.255.0
gateway 192.168.10.1

* 2nd pi
address 192.168.10.2
netmask 255.255.255.0
gateway 192.168.10.1

Re: p2p internet sharing between two RPI 3

Posted: Fri May 05, 2017 1:04 pm
by Stanley783
EDIT: i understood but that was not what i asked, anyway i got it running aferwards, thanks topguy for hints

after pairing and NOT configuring IP stuff:

RPI 1 (p2p-wlan0-0: IP 169.254.207.187 mask 255.255.0.0) netstat -nr

Code: Select all

Destination             Gateway                      genmask                   iface
0.0.0.0                     192.168.2.1                0.0.0.0                       eth0
169.254.0.0            0.0.0.0                         255.255.0.0              p2p-wlan0-0 
192.168.2.0             0.0.0.0                        255.255.255.0          eth0  
RPI 2 (p2p-wlan0-0: IP 169.254.54.224 mask 255.255.0.0) netstat -nr

Code: Select all

Destination             Gateway                      genmask                   iface
0.0.0.0                     169.254.207.187       0.0.0.0                       p2p-wlan0-0 
169.254.0.0            0.0.0.0                         255.255.0.0              p2p-wlan0-0 

first i edited /etc/network/interfaces and added

Code: Select all

iface p2p-wlan0-0 inet static
address    192.168.2.22
netmask    255.255.255.0
gateway    192.168.2.1

which did nothing when typed "ifconfig" so i commented/deleted those


then i did on RPI 2

Code: Select all

 sudo route add default gw 169.254.207.187 

and on RPI 1 edited /etc/sysctl.conf

Code: Select all

net.ipv4.ip_forward=1
and wrote

Code: Select all

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 
after that on RPI 2 i

Code: Select all

ping 8.8.8.8
which said it was recieved and succesful (DNS not yet configured)

after that sudo nano /etc/resolv.conf (needed chmod 777 first)

Code: Select all

nameserver  208.67.222.222
nameserver 208.67.220.220
EDIT: found topic where is recomended to edit /etc/network/interfaces instead resolv.conf

Code: Select all

dns-nameservers 8.8.4.4 8.8.8.8

If somebody ever wonder how to do this as there were never complete guide...after this i was able to browse web on second PI, soooo, done....as additional info i did this on Raspbian kernel 4.9.24-v7+ and wpa_cli 2.3 (someone recomended to download custom 2.6 for p2p connecting but that was not really needed)