Fix ‘iptables – Unable to Initialize Table Filter’ Error in Ubuntu 14.04

14.04iptables

I have a firewall file saved in /etc/firewall.conf. Everything is ok, I can use it for "iptables-restore /etc/firewall.conf" with success.

So, starting from this file, I created a php script(that runs as a cron) that writes a file called /etc/dinamic-firewall.conf; same content as firewall.conf with some additions.

The problem is, when I try to "iptables-restore /etc/dinamic-firewall.conf" I always get this error:

'ptables-restore v1.4.21: iptables-restore: unable to initialize table 'filter
Error occurred at line: 2
Try `iptables-restore -h' or 'iptables-restore --help' for more information.

First part of both files is the same

# Generated by myfirewall on Thu Nov 20 08:51:01 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:fail2ban-pure-ftpd - [0:0]
:fail2ban-ssh - [0:0]

Also, both files have same permissions/owner. So, what's wrong?
Thank you!

P.S. Ubuntu server 14.04.1 lts x64

Best Answer

The problem was the line-ending style; instead of "\r\n" I used "\n" and now everything works.