How can I programmatically manage iptables rules on the fly?

后端 未结 9 1281
盖世英雄少女心
盖世英雄少女心 2020-11-29 00:20

I need to query existing rules, as well as being able to easily add and delete rules. I haven\'t found any API\'s for doing this. Is there something that I\'m missing?

9条回答
  •  旧时难觅i
    2020-11-29 00:56

    This morning I woke up to find that was getting a Denial Of Service (DOS) attack from Russia. They were hitting me from dozens of IP blocks. They must have either had a large pool of IPs or some sort of proxy list/service. Every time I blocked an IP, another one popped up. Finally, I looked for a script, and found I needed to write my own solution. The following is a bit agressive, but they were running my TOP LOAD LEVEL to over 200.

    Here is a quick script I wrote to block the DOS in realtime.

    cat  **"output of the logs"** | php ipchains.php **"something unique in the logs"**
    

    ==> PHP Script:

    
    

    Assumptions:

    1) BLOCK1 is a Chain already created. 
    2) BLOCK1 is a Chain that is run/called from the INPUT CHAIN 
    3) Periodically you will need to run "ipchains -S BLOCK1" and put output in /etc/sysconfig file. 
    4) You are familiar with PHP 
    5) You understand web log line items/fields and output.
    

提交回复
热议问题