HOWTO - Access Ethernet controller via WiFI with Raspberry PI 3

This is a script I developed to access a Ruida controller with ethernet via WiFi. A raspberry pi 3 is required to perform the port forwarding. You will need some familiarity with the basic setup of the WiFi, but the script works great once that is completed. I recommend that you start with a clean install of the latest Buster distribution and work from there. Setup of a RPi is outside the scope of this forum, I suggest that you search for additional information on the internet.


The updated script here will forward all UDP traffic sent to the RPi to the laser controller. This was tested with a Ruida controller, but should work with any other controller that uses UDP as the transport.

# 1 October 2020  Paul D. Fincato
# Updated 2 October 2020 - PDF
# This is based upon a collection of scripts and ideas found on the internet
# -
# -
# Allows access to a Ruida based ethernet controller
# over WiFi with a Raspberry pi3.  wlan0 is connected to your existing WiFi network
# eth0 is connected to the laser.
# This should work with no changes with the default Ruida controller IP address.
# The only changes should be to the configuration of your wireless network
# outside of this script  (sudo raspi-config   - the wireless network wlan0)
# Clean install of 2020-08-20-raspios-buster-armhf-lite installed on Rpi3
# wlan0 already configured for your existing wireless network (i.e. You can SSH to Rpi wireless)
# Install dnsmasq i.e. -  sudo apt-get install dnsmasq
# Execute this script on boot - i.e.  sudo crontab -e   add the line  @reboot /home/pi/
# The wlan0 address becomes the IP address for the Ruida laser controller
# and should be used in your laser software setup
# ifconfig -a
# wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
#        inet  netmask  broadcast
# Since only UDP is being forwarded, you retain the abilty to SSH (TCP) to the Rpi
# for any maintenance required 
# Remember to:  chmod +x

# Addresses of eth0 on rpi and the laser (same subnet)

# Really shouldn't need to change anything below here on a Rpi 3
# and default Ruida address of    YMMV...


sudo systemctl start &> /dev/null

sudo iptables -F
sudo iptables -t nat -F
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -A PREROUTING -p udp -m udp -i $wlan -j DNAT --to $laser
sudo iptables -t nat -A POSTROUTING -o $eth -j MASQUERADE

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

sudo ifconfig $eth $ip_address netmask $netmask
sudo systemctl stop dnsmasq
sudo rm -rf /etc/dnsmasq.d/* &> /dev/null

sudo route add -net default gw $ip_address netmask dev eth0 metric 1

echo -e "interface=$eth\n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /tmp/custom-dnsmasq.conf

sudo cp /tmp/custom-dnsmasq.conf /etc/dnsmasq.d/custom-dnsmasq.conf
sudo systemctl start dnsmasq
1 Like

Once you’ve accessed the controller, what does it do?

This permits the laser to reside on your local network and access it via WiFi. I used to have to move my laptop near the laser and connect via hardwired ethernet. Now I can access the laser as any other device on my WiFi network without moving the laptop.


Would this work for a Trocen controller as well?

The updated script in the first post should work. I presume that the Trocen controller has Ethernet capabilities…

The requirements are :

Ensure that the WiFi and the Trocen controller are on separate networks (i.e. 192.168.X.n and 192.168.Y.n)

My WiFi is 192.168.0.x so the RPi becomes (via DHCP on my WiFi router with a reservation) and the Ruida is on

(The reservation makes it consistently appear at the same IP address of

It would be easiest to change the IP Address on the Trocen to so there are fewer changes to the script.

If your WiFi happens to be 192.168.1.x then changes would need to be made to the script to make the RPi network different (192.168.2.n) (Changing the 3rd octet only keeps it simple - 192.168.1.n -> 192.168.2.n at all appearances in the script) The laser IP would become in this case.


I’m curious why all of this is necessary, and you couldn’t just go directly from the PC to the laser, without forwarding through the rPi?

OZ, you are correct it is not necessary. However it is very convenient to access the laser wirelessly instead of moving a computer and plugging cables. I guess it comes down to the shop layout and what else the computer is used for.

PS. The RPi also could also provide shared network storage, a webserver, etc as well as the laser interface. The script is a minimum case usage.


Convenient, yes, but it’s not stable. Ruida uses UDP, and that drops packets relatively often when wireless, because of interference / congestion. You can run a cable from the Ruida to any wireless gaming adapter or wireless router to accomplish the same thing.

I prefer using PowerLine adapters - they’re wired, but through home wiring, so they’re much more like a wired connection, but without the network cable.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.