- My socat didn't forward traffic when the UDP broadcast destination was 255.255.255.255. I avoided this by restricting the broadcast subnet to the one I use is probably safer.
- When I set the bind address to 0.0.0.0, I ran into a broadcast storm due to traffic bouncing back into socat from my LAN. I first solved this by binding to my public ddns, however this is not ideal because ddns may not be available and my dynamically assigned IP address my change.
The ugly
Since I couldn'twas able to bind to all interfaces with0.0.0.0 bind=0.0.0.0, my solution is to bind(all addresses) and avoid the broadcast storm by adding an iptables rule to block incoming broadcast from bouncing back into socat from the wan IP addressLAN side. This rule, that wayin addition to an iptables rule to accept traffic that gets broadcast on the lan no longer reachesUDP port 9, and an iptables rule to log it we get the wan interface again. I discover my public wan IP address by bindingfollowing three rules in addition to my ddns hostnamethe socat command.
socatiptables -uI input_wan_rule -T1p UDPudp -LISTEN:-dport 9,bind=vitto.example.net,fork UDP-DATAGRAM:192.168.20.255:9,broadcast Verify socat is listening with netstat:
netstatj ACCEPT -tunam |comment grep--comment ":9""firewall entry to allow udp port 9 to socat" On OpenWrt (, and most iptables systems), this also requires the following line, so the packet isn't dropped:
iptables -I INPUTinput_wan_rule -p udp --dport 9 -j ACCEPTLOG --log-prefix 'Received MAGIC PACKET on udp/9' I couldn't figure out a way for socat to "bind to the IP of my wan interface", so I pointed it to my public hostname vitto.example.net. While this works, it will not update if the IP address changes, and the IP address it resolves to at boot time, may not be the one on the interface at the time.
For the lazy OpenWRTers, paste this into /etc/firewall.user
iptables -I INPUTinput_lan_rule -p udp --dport 9 -d 192.168.20.0/24 -j ACCEPTDROP -m comment --comment "firewall"block entrybroadcast tofrom allowbouncing udpback portto 9socat to socat"avoid storm" killall socat 2>/dev/null socat -u -T1 UDP-LISTEN:9,bind=vittobind=0.somewhere0.net0.0,fork UDP-DATAGRAM:192.168.20.255:9,broadcast & Then issue:For the OpenWRTers, pasting this into /etc/firewall.user and issuing /etc/init.d/firewall restart is sufficient.
/etc/init.d/firewall restart