1

I'm currently working on a little hobby project with my Raspberry Pi 2 and I'm not sure how to proceed. I have basic knowledge of Linux but i still have much to learn.

What I'm trying to accomplish is to have my pi act as a proxy to my laptop. My Pi will have Pi-Hole(https://pi-hole.net) running as well as OpenVPN once i got Pi-Hole to run

My plan is to have everything setup like this:

[Laptop]--eth0-->[Pi-Hole]--wlan0-->[Router]-->Internet

My laptop will be connected to the pi via Ethernet cable and the pi will then forward the traffic over wlan0 to my router which is connected to the internet. My Pi is running Raspbian stretch lite since i will be using it headlessly. Once I manage to run Pi-Hole correctly and filter out some of the garbage, I will install openVPN to make sure my traffic is protected.

Here is where i have issues. dhcp seems to messing up my interfaces file, if i disable dhcp the pi becomes unreachable and I'm not sure how to fix that. I'm not sure if any significant changes been made to the networking between jessie and stretch.. I understand that once i disable dhcp then we need to specify how the pi i supposed to connect to the internet.

I set my interfaces file like this:

auto lo 
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
    adress 192.168.1.99
    netmask 255.255.255.0
    gateway 192.168.1.1
    network 192.168.1.0
    broadcast 192.168.1.255


allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

and then i just removed dhcp

sudo apt-get remove dhcpcd5 isc-dhcp-client isc-dhcp-common

Since I'm running headless it means that when this does not work the pi becomes unreachable once i reboot. Ssh just time-out, my router does not show any connections from the static IP and a ping from my laptop shows the host is unreachable. I just reflashed the SD card and am now back where i started.

What did i do wrong/not understand/miss and how do i fix it? Also, any pointers to good resources or things i should lookup when working on this project? Any advice would be helpful and if it works well once completed, i'll make sure to post the full process somewhere so that others can make use of it as well.

Thank you for taking the time to read my question.

Cheers!

1
  • This question is unclear. Firstly you assume dhcp is causing your (unstated) problem - probably due to the obsolete and incomplete interfaces. You then remove the default network manager dhcpcd and the dhcp client as well - do you expect wlan0 to be assigned an address? Stretch DOES NOT have wlan0 or eth0 by default (unless you modify settings).
    – Milliways
    Oct 11, 2017 at 4:56

1 Answer 1

1

I am going to assume your /etc/wpa_supplicant/wpa_supplicant.conf looks something like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

country=US

network=
{
        ssid="RouterSomething"
        psk="MyPassword"
        key_mgmt=WPA-PSK
}

With that you should be able to connect to the wireless router but without the dhcp client daemon (dhcpcd) the router will not serve an IP Address. So, that needs to be fixed. Reinstalling the dhcp client daemon should do that.

On the eth0 side of the Pi router you will need to set a static ip. This is easily done in /etc/rc.local by adding a line: ifconfig eth0 192.168.24.1 before the exit 0. You should be able to set this in dhcpcd.conf but it would not work for me.

I am assuming you do not want to set your laptop to a static IP Address, so you will need a dhcp server such as dnsmasq or isc-dhcp-server.

Once the dhcp server is configured you should be able to connect the laptop to the Pi router, be served an IP Address and SSH in.

Now the Pi router can talk to both networks but there is not communication between the networks. For that we need IP packet forwarding

Edit the /etc/sysctl.conf file and remove the # from the beginning of the line containing net.ipv4.ip_forward=1. This will enable it on the next reboot. To enable it immediately:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Now to establish a NAT between the wlan0 interface and the eth0 interface use the following commands:

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

I found these iptables rules somewhere on the internet and wish I could give proper credit. I only sort of know how these work so, don't ask me to explain.

These rules must be applied every time the RPi_AP reboots, so, to save the rules to the file /etc/iptables.ipv4.nat use:

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

I have actually done this except my iptable rules were the opposite since my Pi router was connected to my main router via eth0 and I created an access point on the wlan0 side.

Hope that helps.

2
  • Firstly, Thank you for this very good answer. I am unfortunately going to be out and about for a few hours but I will try this asap and report back. Secondly, Since i re-flashed my SDcard the dhcp client daemon should be there again. I actually did not set my wpa_supplicant.conf file quite like yours. I did not add the lines above the network={...} part so that's something to try.
    – PJernlund
    Oct 10, 2017 at 16:54
  • I was unclear, My laptop (on the eth0 side of the pi) is running windows 10. I'm actually fine with a static IP on my wired interface since the wireless interface is separate and thus it will acquire an address dynamically if i am not using the wired interface with the PI, or have i got that all wrong as well? Thanks again @LeePartridge
    – PJernlund
    Oct 10, 2017 at 16:56

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.