How to view blacklist ip ?
Hello,
I am using blacklist like
`````````` iptables -A INPUT -m recent --name blacklist --rcheck --seconds $BLACKLIST_INTERVAL -j DROP ```````````
and it is working really well. But is there any way to manage the blacklisted ip ? Manage means
1> view the ips which are blacklisted
2> manually remove an IP from blacklist
3> manually insert an IP as blacklist
See ipset.netfilter.org
Signature · 2 lines
Best regards Anatoly Muliarski
Quoted 3 lines · Anatoly Muliarski
See ipset.netfilter.org
Thanks, ipset needs kernel compilation to support it ; along with iptables compilation too. I am working on a remote production suse box so I can't have that much liberty. Any workarounds within the iptables itself ?
thanks for your time.
Hello,
Quoted 6 lines · J. Bakshi
iptables -A INPUT -m recent --name blacklist --rcheck --seconds $BLACKLIST_INTERVAL -j DROP
and it is working really well. But is there any way to manage the blacklisted ip ? Manage means
man iptables
Quoted 1 line
1> view the ips which are blacklisted
Read /proc/net/ipt_recent/<name>.
Quoted 1 line
2> manually remove an IP from blacklist
Write "-a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to remove. You can also write "clear" to flush the list.
Quoted 1 line
3> manually insert an IP as blacklist
Write "+a.b.c.d" or "a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to add or update.
Warning : ipt_recent may have been renamed xt_recent in recent kernels.
Quoted 11 lines · Pascal Hambourg
Hello,
Quoted 6 lines · J. Bakshi
iptables -A INPUT -m recent --name blacklist --rcheck --seconds $BLACKLIST_INTERVAL -j DROP
and it is working really well. But is there any way to manage the blacklisted ip ? Manage means
Quoted 9 lines
man iptables
Quoted 2 lines
1> view the ips which are blacklisted
Read /proc/net/ipt_recent/<name>.
Great !!!. Thanks a lot. Now I can write a shell script to manage the IPs.
Quoted 20 lines
Quoted 2 lines
2> manually remove an IP from blacklist
Write "-a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to remove. You can also write "clear" to flush the list.
Quoted 2 lines
3> manually insert an IP as blacklist
Write "+a.b.c.d" or "a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to add or update.
Warning :
ipt_recentmay have been renamedxt_recentin recent kernels. --
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines · J. Bakshi
Quoted 19 lines · Pascal Hambourg
Hello,
Quoted 7 lines · J. Bakshi
iptables -A INPUT -m recent --name blacklist --rcheck --seconds $BLACKLIST_INTERVAL -j DROP
and it is working really well. But is there any way to manage the blacklisted ip ? Manage means
man iptables
Quoted 3 lines
1> view the ips which are blacklisted
Quoted 8 lines
Quoted 4 lines
Read /proc/net/ipt_recent/<name>.
Great !!!. Thanks a lot. Now I can write a shell script to manage the IPs.
Though the content of the file consists of much more.
`````````` # cat /proc/net/ipt_recent/blacklist src=183.131.207.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=240.168.95.31 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=254.41.0.0 ttl: 0 last_seen: 4298215698 oldest_pkt: 1 4298215698 src=255.255.211.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=135.0.0.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=79.0.0.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=53.0.0.0 ttl: 0 last_seen: 4298215698 oldest_pkt: 1 4298215698 src=31.190.99.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=165.0.0.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=236.13.207.0 ttl: 0 last_seen: 4298214902 oldest_pkt: 1 4298214902 src=135.232.168.45 ttl: 0 last_seen: 4298215698 oldest_pkt: 1 4298215698 src=255.255.255.211 ttl: 0 last_seen: 4298215698 oldest_pkt: 2 4298212575 `````````````````````````````````
And If I try to remove a line it reports
``````````````` WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)? `````````````````
A yes puts me again into the file. and it is recursive.
Quoted 31 lines
Quoted 13 lines
Quoted 5 lines
2> manually remove an IP from blacklist
Write "-a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to remove. You can also write "clear" to flush the list.
Quoted 3 lines
3> manually insert an IP as blacklist
Quoted 11 lines
Write "+a.b.c.d" or "a.b.c.d" into /proc/net/ipt_recent/<name> where a.b.c.d is the address to add or update.
Warning :
ipt_recentmay have been renamedxt_recentin recent kernels. --
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · J. Bakshi
# cat /proc/net/ipt_recent/blacklistsrc=183.131.207.0 ttl: 0
last_seen: 4298214902oldest_pkt: 1 4298214902 src=240.168.95.31 ttl: 0last_seen: 4298214902oldest_pkt: 1 4298214902
[...]
Quoted 8 lines
And If I try to remove a line it reports
``````````````` WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)? `````````````````A yes puts me again into the file. and it is recursive.
You are not supposed to open this pseudo-file and remove lines with a text editor, you are supposed to *write* commands (e.g. with echo) into it as indicated in the manpage. This is not a real file but an interface to the kernel.
Quoted 16 lines · Pascal Hambourg
Quoted 5 lines · J. Bakshi
# cat /proc/net/ipt_recent/blacklistsrc=183.131.207.0 ttl: 0
last_seen: 4298214902oldest_pkt: 1 4298214902 src=240.168.95.31 ttl: 0last_seen: 4298214902oldest_pkt: 1 4298214902[...]
Quoted 7 lines
And If I try to remove a line it reports
``````````````` WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)? `````````````````
Quoted 8 lines
Quoted 2 lines
A yes puts me again into the file. and it is recursive.
You are not supposed to open this pseudo-file and remove lines with a text editor, you are supposed to *write* commands (e.g. with echo) into it as indicated in the manpage. This is not a real file but an interface to the kernel.
Hello,
Yes, I have found the specific section in the man page and it is successully do the job as described. Now I can modify my script accordingly to do the job.
Thanks a lot for he right direction.
wish you a nice time.
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 31 lines · J. Bakshi
Quoted 19 lines · Pascal Hambourg
Quoted 6 lines · J. Bakshi
# cat /proc/net/ipt_recent/blacklistsrc=183.131.207.0 ttl: 0
last_seen: 4298214902oldest_pkt: 1 4298214902 src=240.168.95.31 ttl: 0last_seen: 4298214902oldest_pkt: 1 4298214902[...]
Quoted 7 lines
And If I try to remove a line it reports
``````````````` WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)? `````````````````Quoted 9 lines
Quoted 3 lines
A yes puts me again into the file. and it is recursive.
You are not supposed to open this pseudo-file and remove lines with a text editor, you are supposed to *write* commands (e.g. with echo) into it as indicated in the manpage. This is not a real file but an interface to the kernel.
Quoted 9 lines
Hello,
Yes, I have found the specific section in the man page and it is successully do the job as described. Now I can modify my script accordingly to do the job.
Thanks a lot for he right direction.
wish you a nice time.
Hello Pascal,
I don't know if I should create a new thread or continue with this one. But this is a new issue though a continuation of ipt_recent and blacklist. My script to show the blacklisted ip is running well. During my experiment with blacklist I have found that blacklisted ips are still there at
/proc/net/ipt_recent/blacklist
Even after the blacklist interval the client can access the server successfully; the server still shows the client ip as blacklisted. Definately the ip can be removed or "clear" as described in the man page but storing the ip permanently at /proc/net/ipt_recent/blacklist is very confusing. How can you then check if the ip is still blacklisted or able to communicate with the server in real-life ?
Quoted 7 lines · J. Bakshi
Even after the blacklist interval the client can access the server successfully; the server still shows the client ip as blacklisted. Definately the ip can be removed or "clear" as described in the man page but storing the ip permanently at
/proc/net/ipt_recent/blacklistis very confusing. How can you then check if the ip is still blacklisted or able to communicate with the server in real-life ?
The list just stores source addresses and timestamps (the big numbers, measured in jiffies) of recently seen packets in a FIFO manner. Whether a packet will match the rule with 'recent' depends on its options --seconds and/or --hitcount. So it is up to you to parse the timestamps associated to an address and decide whether this address is blacklisted or not.
Quoted 10 lines · Pascal Hambourg
Quoted 7 lines · J. Bakshi
Even after the blacklist interval the client can access the server successfully; the server still shows the client ip as blacklisted. Definately the ip can be removed or "clear" as described in the man page but storing the ip permanently at
/proc/net/ipt_recent/blacklistis very confusing. How can you then check if the ip is still blacklisted or able to communicate with the server in real-life ?
Quoted 7 lines
The list just stores source addresses and timestamps (the big numbers, measured in jiffies) of recently seen packets in a FIFO manner. Whether a packet will match the rule with 'recent' depends on its options --seconds and/or --hitcount. So it is up to you to parse the timestamps associated to an address and decide whether this address is blacklisted or not.
Now understand the technique. I have 2 question here
1> how the time stamp is calculated here ? It might be possible to generate it through the date command.
2> How long these entries are kept at /proc/net/ipt_recent/ ? any way to modify that interval ?
Thanks
Quoted 3 lines · J. Bakshi
1> how the time stamp is calculated here ? It might be possible to generate it through the date command.
I don't know.
Quoted 1 line
2> How long these entries are kept at
/proc/net/ipt_recent/?
As long as newer data don't need the space. The list works as a FIFO.
Quoted 1 line
any way to modify that interval ?
You can only set the number of addresses and packets per address with the module parameters ip_list_tot and ip_pkt_list_tot described in the iptables manpage.
Quoted 2 lines · Pascal Hambourg
The list just stores source addresses and timestamps (the big numbers, measured in jiffies) of recently seen packets in a FIFO manner.
Could anyone suggest me how to get time in jiffies ? Tried with "date +%s" but it is not the jiffie value. Any clue please ?
2009/9/7 J. Bakshi <[email protected]>:
Quoted 2 lines
Could anyone suggest me how to get time in jiffies ? Tried with "date +%s" but it is not the jiffie value. Any clue please ?
You may use the first field in /proc/uptime - that gives you uptime in seconds.
IMHO, the recent module should be used for filtering purpose only not for managing black lists.
The right way is ipset :)
And it does not require you to recompile your kernel - you may install it as a module.
And yes, to use it you should recompile iptables if it does not support it by default.
Signature · 2 lines
Best regards Anatoly Muliarski
Quoted 8 lines · Anatoly Muliarski
2009/9/7 J. Bakshi <[email protected]>:
Quoted 3 lines
Could anyone suggest me how to get time in jiffies ? Tried with "date +%s" but it is not the jiffie value. Any clue please ?
You may use the first field in
/proc/uptime- that gives you uptime in seconds.
Quoted 9 lines
IMHO, the recent module should be used for filtering purpose only not for managing black lists.
The right way is ipset :)
And it does not require you to recompile your kernel - you may install it as a module.
And yes, to use it you should recompile iptables if it does not support it by default.
Hello Anatoly,
Thanks for your enlightenment. I have to check if iptables supports ipset by default in suse and debian. BTW any good tutorial to start with ipset ?
regards
Quoted 22 lines · J. Bakshi
Quoted 9 lines · Anatoly Muliarski
2009/9/7 J. Bakshi <[email protected]>:
Quoted 4 lines
Could anyone suggest me how to get time in jiffies ? Tried with "date +%s" but it is not the jiffie value. Any clue please ?
You may use the first field in
/proc/uptime- that gives you uptime in seconds.Quoted 10 lines
IMHO, the recent module should be used for filtering purpose only not for managing black lists.
The right way is ipset :)
And it does not require you to recompile your kernel - you may install it as a module.
And yes, to use it you should recompile iptables if it does not support it by default.
Quoted 8 lines
Hello Anatoly,
Thanks for your enlightenment. I have to check if iptables supports ipset by default in suse and debian. BTW any good tutorial to start with ipset ?
regards
Hello,
find iptree of ipset. seems it can do the job. iptree can store ip
addresses with a timeout value. So the next thing is to migrate the blacklisted ip from ipt_recent module to the iptree of ipset. I hope I am on te right track. need some guidance from you list.
regards.
An example is quite simple:
# Create iptree set to lock bad guys for 5 minutes ipset -N BAD_GUYS iptree --timeout 300
# to add a bad guy( classified by source ip ) into the set iptables -A SOMEWHERE <your_conditions> -j SET --add-set BAD_GUYS src # to manually delete a bad guy( classified by source ip ) from the set iptables -A SOMEWHERE <your_conditions> -j SET --del-set BAD_GUYS src # to view the list content ipset -L BAD_GUYS # to check ip in the list ipset -T BAD_GUYS <ip> OR iptables -A SOMEWHERE -m set --set BAD_GUYS src
If you do not need a timeout you may use iphash set type or ipmap for /16 network.
Signature · 2 lines
Best regards Anatoly Muliarski