i want to be able to access tcp port 9100 on my network printer when out in the field with it from a web-app running in AWS.
I want to have the printer plugged into eth0 on the Rpi3 and the wlan0 interface needs to be DHCP as it will connect to wifi (cannot alter the source wifi settings)
For ngrok to work the printer will need a static IP, currently it set to 10.0.0.2, so i tried to set eth0 as 10.0.0.1 with a gateway of 10.0.0.1
I have edited the /etc/dhcpcd.conf with the above entries for eth0 interface however there is no mention in there of the wlan0 interface.
I have then tried echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp --dport 9100 -i wlan0 -j DNAT --to 10.0.0.2:9100
and i could telnet to the pi over wifi but it did not pass the data onto the device connected to eth0.
Obviously I have this whole operation balls up haha. Please help.
EDIT for network diagram:
DHCP 10.0.0.2:9100 (tcp port)
/ /
4G LTE WiFi Router ------ wlan0 [RPI3B+] eth0 ------- Printer
\ \
Cannot alter DHCP settings 10.0.0.1
Data flow diagram:
Mobile App ----> NodeJS Webserver ----> ngrok custom URL ----> 4G Router ----> Rpi ----> Printer
EDIT 4 SOLVED
By using the following commands i was able to forward tcp connections successfully.
*get hardware interface name enxb827ebf40227 <- mine
ip addr show
*edit dhcpcd to enable static v4 IP onto this interface
sudo nano /etc/dhcpcd.conf
*find and uncomment the following lines
#Interface eth0
#static ip_address=0.0.0.0/24
*replace eth0 with hardware iface name enxb827ebf40227 as above, save and exit
*enable port forwarding on v4 IP networks (disabled by default)
nano /etc/sysctl.conf
*find and uncomment the following line
#net.ipv4.ip_forward = 1
,save and exit
*update the iptables to allow port 9100 routing between wlan0 and enxb827ebf40227
iptables -t nat -A PREROUTING -p tcp --dport 9100 -i wlan0 -j DNAT --to 10.0.0.2:9100 |
iptables -A FORWARD -i wlan0 -o enxb827ebf40227 -j ACCEPT |
iptables -A FORWARD -i enxb827ebf40227 -o wlan0 -m state --state ESTABLISHED,RELATED -j ACCEPT |
iptables -t nat -A POSTROUTING -o enxb827ebf40227 -j MASQUERADE
*test forwarding by telnet to port 9100 on host(rpi) IP address. It should now communicate with device plugged into eth0 port.
*install the iptables-persistent package to keep my rules automatically loaded.
apt-get install iptables persistent
*save iptables rules
iptables-save > /etc/iptables/rules.v4
*test iptables survival with a reboot
shutdown -r now
*Once rebooted check iptables with:
iptables -vnL