
log file before deletion apiurl and apikey control local API parameters. Supposing you want to block 10k ip addresses, with just iptables you'll have to create 10k rules, one for each ip address, while with ipset you can create a single rule for a specific set of those ip addresses. IPSet (when using iptables mode) does not support a timeout greater than. IPset acts as add on or plugin to make IPtables Firewall Manager more efficient, it’s just another Kernel Module to make Blacklist or Whilelist of IP addresses read by IPtables as if they are loaded into the VPS RAM. Unlike normal iptables chains, which are stored and traversed linearly, IP sets are stored in indexed data structures, making lookups very efficient, even when dealing with large sets. IPset is an addon module for IPtables that can be used to create or load a massive long list of bad IP Addresses and Networks. Unlike other extensions such as Connection Tracking, ipset is more related to iptables than it is to the core Netfilter code. Ipset is an extension to iptables that allows you to create firewall rules that match entire "sets" of addresses at once. Not sure if that's what you're looking for but it's a good read nonetheless They provide different scenarios, how iptables works, performance tests and so on. It depends on the types of rules you have and the iptables extensions you use.

Which goes toward your goal: this single iptables rule will work correctly with set elements with or without a port, as documented in ipset.If you server receives really high traffic, a lot of iptables rules can have significant overhead especially on the CPU. NOTE: You may want to add a comment to these rules for documentation. sudo iptables -I INPUT -p tcp -dport 22 -m set -match-set ssh-allowed src -j ACCEPT. Now that we have our IP Set created, let's create a rule in iptables that tells it to allow SSH traffic from addresses inside this IP Set. This won't change the way to populate separately the sets using the ipset command, but you can do this: ipset create blocklist list:setĪnd replace the two previous iptables rules with only the one below: iptables -A INPUT -m set -match-set blocklist src,dst -j DROP Using the IP Set to Create an iptables Rule. Iptables -A INPUT -m set -match-set blocklistipport src,dst -j DROPĪbove src,dst means use the source IP address along the destination port address in the packet when looking for a match in the hash:ip,port set.Īlso, ipset has a special set list:set consisting of a list of other sets. A simple example here would be to check for the, to know where to put it, while reading the list from the file blocklist.txt: while read -r element doĪnd you can block everything in the list for example with: iptables -A INPUT -m set -match-set blocklistip src -j DROP Now your script has to check what type of element it got, to know in what ipset it will add it. Note like above that by default the protocol for the port is TCP unless explicitly stated otherwise ( udp: for UDP, sctp: for SCTP. Ipset add blocklistipport 192.0.2.3,udp:53 Ipset create blocklistipport hash:ip,port But you can use different sets, one for each type (full list available with ipset help): hash:ipįor example: ipset create blocklistip hash:ip

You can't put different types of elements in the same set with the ipset command.
