Answer the question
In order to leave comments, you need to log in
How to edit /etc/sysconfig/iptables file from php script?
Good afternoon.
Is there any way to edit the /etc/sysconfig/iptables file - by executing script.php ?
You need to add an IP there, and it takes a long time to do it with your hands. I can't figure out how to implement this, because the usual
$fp = fopen('/etc/sysconfig/iptables', 'a');
fwrite($fp, $ip."\n");
fclose($fp);
does not work.
Answer the question
In order to leave comments, you need to log in
Yes, you are a brave joker, my friend!
And of course the php script will be run remotely...
Run php as root and you will be happy!
In addition to changing the file, you would also need to restart iptables.
So maybe it's better to fill in the rules in IPTABLES without changing the file?
It will be an order of magnitude safer to write a regular file from a regular unprivileged user, somewhere in his home folder, and set inotify on it in monitor mode, which will see that it has changed, run a script with root privileges, it will parse it, generate a command to manage iptables and execute her. The file format is text, no direct commands. Work strictly according to the dictionary. The line did not pass the dictionary - it is deleted, a notification is written to the log.
Would you describe the problem. Maybe it's already been decided.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question