LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-30-2017, 11:39 PM   #1
luofeiyu
Member
 
Registered: Aug 2015
Posts: 237

Rep: Reputation: Disabled
Can the ip address written into a file called by iptable?


It is smiple to block several ip with iptables.

To block 191.96.249.63 191.96.249.70 41.191.224.5 .

iptables -A INPUT -s 191.96.249.63 -j DROP
iptables -A INPUT -s 191.96.249.70 -j DROP
iptables -A INPUT -s 41.191.224.5 -j DROP
service iptables save

If there are 100 ip to be blocked, Which the simplest way to do that with iptables?

Can i write all the ip into a file ,one ip per line, called by iptables?
 
Old 10-31-2017, 12:27 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
The easiest and most efficient way I know is to use ipset (see man ipset).

Create a set for the type and options you want (default mask, counters, timeout, etc.), for example..

Code:
ipset create banned hash:ip netmask 24 counters timeout 3600
Then add the IP addresses (you can add more at any time)...

Code:
ipset add banned 41.191.224.5
...
Then in your iptables rules, add the rule to DROP all IPs found in the set...

Code:
iptables -A INPUT -m set --match-set banned src -j DROP
The size in memory for most set types is very efficient, as little as one bit per IP in a range, hashed lookup is fast.

You can easily save the list to a file and initialize the set at boot.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What file is being accessed/written to? CVAlkan Linux - General 2 10-08-2017 05:50 PM
iptable log mac address not showing sec_tech Linux - Security 6 02-20-2013 09:04 AM
Accept different source network address in iptable input chain kirukan Linux - Security 1 05-27-2010 02:09 AM
what is an iptable? & how to seperate the network on the basis of iptable vinod.wagh Linux - Networking 1 09-11-2008 01:28 AM
where is the iptable config file? what is it's name? gonus Linux - Networking 2 07-12-2004 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration