arpitjindal97 / raspbian-recipes

Raspberry networking made easy - Need Contributors
GNU General Public License v3.0
408 stars 165 forks source link

Port Forwarding #42

Closed Nickjallday closed 4 years ago

Nickjallday commented 4 years ago

So first off thank you so much for this script. It's really awesome I use the wifi-to-eth-route.sh on one of my 3d printers that only has an ethernet interface.

My issue is for this script to work well for me I need to be able to forward port 80 from an ethernet device to the Pi's wifi so I can access its web interface from the wifi network. I accomplished this by adding variables to the script to access my 3d printer:

duet2port="80"
duet2ip="192.168.2.2"

and the following two lines after sudo iptables -A FORWARD -i $eth -o $wlan -j ACCEPT

sudo iptables -t nat -A PREROUTING -p tcp -i $wlan --dport $duet2port -j DNAT --to-destination $duet2ip:$duet2port
sudo iptables -A FORWARD -p tcp -d $duet2ip --dport $duet2port -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

For some reason on this second setup the wifi-to-eth-route.sh works I can access the internet from behind the pi ethernet, but I cannot get access to the web interface via wifi of the device on the Pi's ethernet. I know it's not necessarily an issue, but I was hoping for a bit of guidance on how to accomplish this on my second pi setup. The only differences in the setups are this one is a Pi3 running Buster. The Pi2 is running Jesse.

arpitjindal97 commented 4 years ago

@saikhurana98

Nickjallday commented 4 years ago

Any idea? I haven't made any progress.

arpitjindal97 commented 4 years ago

Your iptables looks fine to me. Can u try SSHing into RPi and do curl over 192.168.2.2.

I want to make sure if service is accessible to Pi

Nickjallday commented 4 years ago

I figured it out, I had to uncomment net.ipv4.ip_forward=1 in /etc/sysctl.conf. Thanks guys!