SAMBA shares are not working unless I enter an iptables command at every boot

I have recently enabled ufw in Linux and found that in order for my Samba shares to mount correctly, I need to enter this command

sudo iptables -t raw -A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns

However, it is somehow forgotten at the next reboot and I have to enter it every time.

Is there a way to make this iptables command stick?


Iptables rules are not persistent, and UFW cannot read and save rules added directly using iptables. Instead, you should be using the UFW to add the rules, e.g.

sudo ufw allow 134/udp

Or if you have Samba application rules installed:

sudo ufw allow samba

This will allow all ports used by Samba, as the application rule is something like:

[Samba] 
title=LanManager-like file and printer server for Unix 
description=The Samba software suite is a collection ...
ports=137,138/udp|139,445/tcp

You could also make iptables rules persistent by installing iptables-persistence and using iptables-save, but it is not recommended to mix this with UFW.