2

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

  • Or, of course, you could do away with all that configuring, run a FTP server on the RPi which shall accept documents and pass them on to the printer for printing. This would make your setup more secure, as FTP would require authentication. – user96931 Jun 6 at 16:15
  • @user96931 The link you have given is not usable for the problem. It described how to configure an access point. The RasPi has a client connection to the router. It is not an access point. Due to hardware limitations it is not possible to bridge a wifi client connection. Port forwarding as shown in the question is the right way for this. – Ingo Jun 7 at 9:41
0

It is very likely that you already have got a gateway ip address (default route) from the DHCP server on the router. I have very often seen on this site that it confuses the kernel if you define a second gateway. So please edit /etc/dhcpcd.conf and delete the entry for gateway 10.0.0.1. If it doesn't help, then please edit your question and add the output from ip route show. Then I will look at it.

  • @Jasonson Please give me a comment here when you edited your question. – Ingo Jun 7 at 9:37
  • I have edited with responses as requested. Thank you so much for taking the time to even look at this for a complete stranger. I really appreciate it. – Jasonson Jun 8 at 0:15
  • While your comment didn't solve my solution it put me well on the way to finding the solution. – Jasonson Jun 8 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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