1

I'm trying to share the internet connection from a RPi2 connected to internet via wifi to a RPi B+ over ethernet.

I want to use static ip addresses for simplicity.

So RPi2 ("master") is 10.0.0.1 and RPi B+ ("slave") is 10.0.0.2.

I've configured the /etc/network/interfaces as following:

RPi2

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 10.0.0.1
    gateway 10.0.0.1
    netmask 255.255.255.0
    broadcast 10.0.0.0

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid "XXX"
    wpa-psk "YYY"

iface default inet dhcp

RPi

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 10.0.0.2
    gateway 10.0.0.1
    netmask 255.255.255.0
    broadcast 10.0.0.0

iface default inet dhcp

I've also applied some rules to iptables on RPi2:

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             10.0.0.0/24         state RELATED,ESTABLISHED
ACCEPT     all  --  10.0.0.0/24         anywhere            

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  10.0.0.0/24        !10.0.0.0/24

The /etc/resolv.conf on the "slave" machine is set to nameserver 10.0.0.1 I can ping successfully each other machine, the "master" can access the internet, but when I try to ping google.com from the "slave" I get this error:

ping: unknown host google.com

Any idea how can I make it working?

Thanks

2 Answers 2

1

Your need is a little bit more complicated that what it looks; to share your WI-FI connection on wlan0 with one (or more) devices, you may need a physical Ethernet switch, so both Ethernet (I'm not sure is you can just connect the Ethernet port as peer-to-peer)

Install dnsmasq: you will create a dns and dhcp servers, however you can still use fixed ip's on your clients; the goal is to have DNS/DHCP on the Ethernet side and a floating (public IP) on WLAN

apt-get install -y dnsmasq dnsutils

after the install just a few changes to the dnsmasq config file.

nano /etc/dnsmasq.conf

#dhcp-range=192.168.0.50,192.168.0.150,12h
dhcp-range=10.0.0.10,10.0.0.99,12h
# add the google server 
server=8.8.8.8
# change your domain name
domain=home
# uncommented so, the local files will be tried here
local=/home/
# uncomment
interface=eth0

Reboot and you will be able to share your wifi.

2
  • You certainly do not need a physical switch. I've actually explained how to get such a connection working with internet sharing here, although it doesn't use orthodox methodology (/etc/network/interfaces, etc., which I think are often more complicated to use than just a few basic manual commands).
    – goldilocks
    Commented Dec 29, 2015 at 16:59
  • Thanks goldilocks, then switch will be needed if you want to share with more than one client.
    – fcm
    Commented Dec 29, 2015 at 18:12
0

The /etc/resolv.conf on the "slave" machine is set to nameserver 10.0.0.1

Simply calling a machine a DNS server does not make it one. Try nameserver 8.8.8.8 (google's free public ones). If that works, you could try the actual router address (can't promise it will work, but it might), or if you want to get fancy, transfer the resolv.conf from the master after the connection is established (maybe if-up scripts can do that).

If dhcpd turns out to be running on the slave it may complicate this and you probably want to disable that as it serves no purpose.

3
  • Changing the namesever from 10.0.0.1 to 8.8.8.8 didn't fix the issue, I still can't ping google.com Commented Dec 29, 2015 at 16:18
  • Can you ping 8.8.8.8? If not, then DNS is not the issue, you simply have no internet access.
    – goldilocks
    Commented Dec 29, 2015 at 16:20
  • When I ping 8.8.8.8 I get connect: Network is unreachable, but it works on the RPi2 (which is connected to wifi) Commented Dec 29, 2015 at 16:53

Your Answer

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

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