I’m trying to forward some ports of the NUC Balena is running on to other devices using iptables. However I’m not able to make it successful. (I’m just using the local IP of the device so nothing has to go via the internet).
What I used to do before we were running Balena was:
iptables -t nat -A PREROUTING -p tcp --dport 1011 -j DNAT --to-destination 10.39.46.11:22
iptables -t nat -A POSTROUTING -j MASQUERADE # Enable port forwarding
Here 10.39.46.0/24 is a LAN where all the devices are connected to (e.g. sensors, NUC, PLC). This rule would allow me to ssh into a sensor using the (W)LAN IP of the NUC and port 1011. Are the rules Balena sets by default in the iptables conflicting with these rules? Is there something else I should take into account?
Hi, iptables works in the same way under balenaOS and nothing should be conflicting with enabling port forwarding.
A few things you may check:
if you are running the iptables command from a container in a multicontainer application (with a docker-compose.yml file), then you will need to add to the following service configuration to the container in the docker-compose.yml file:
network_mode: "host"
cap_add:
- NET_ADMIN
Make sure IP forwarding is enabled in the kernel: sysctl net.ipv4.ip_forward should return 1.
Run ip route to make sure 10.39.46.0/24 is a routing entry. You may also try to ssh to 10.39.46.11 directly from the host OS to make sure access is available.
Please let us know whether any of this was of help.
I should try this out myself and see what results will I get. I can do it on Monday though as it is almost evening here at my location. Will that work for you?
Thanks,
Zahari
Hi,
It is because of the default forward policy is set to drop.
Can you please try adding iptables -P FORWARD ACCEPT and let me know if that works for you.
Thanks,
Zahari