Port Forwarding on Raspberry PI

ยท

1 min read

Hello there!! Hope these steps will be handy when you need to access the Web-UI of the device connected to Raspberry-PI, from your Personal Computer. Follow the below steps on raspberry-pi:

Install necessary packages

#sudo apt-get install iptables-persistent

Enable forwarding

#sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf

Configure iptables

# Generated by xtables-save v1.8.2 on Fri Dec  4 01:05:43 2020
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
# Completed on Fri Dec  4 01:05:43 2020
# Generated by xtables-save v1.8.2 on Fri Dec  4 01:05:43 2020
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.1
-A POSTROUTING -o eth1+ -j MASQUERADE
COMMIT
# Completed on Fri Dec  4 01:05:43 2020
# Generated by xtables-save v1.8.2 on Fri Dec  4 01:05:43 2020
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth1+ -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
COMMIT
# Completed on Fri Dec  4 01:05:43 2020

Type in the IP address of the raspberry-pi on any of your favorite browser on your Personal Computer. Tadah!!!!