Iptables – How to config CSF to allow postrouting in iptables for installing OpenVPN

csffirewalliptableslfdopenvpn

I am installing OpenVPN on my server and according to the tutorial I'm following I have to add the following line to iptables:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

I add it and save it and successfully restart iptables but then I have noticed that when I use CSF, it overrides iptables and this line get erased. How can I prevent CSF+LFD from erasing this line?

Best Answer

For future reference, this is possible by adding a bash file named csfpre.sh in /etc/csf/ directory with the iptables rules that you want CSF to load each time it starts.

On CentOS, I had to write /sbin/iptables instead of iptables alone because writing iptables alone gave the "command not found" error in bash. In other words, you should write

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

in csfpre.sh for it to work correctly.

Related Topic