Content-type: text/html
Man page of IPSET
IPSET
Section: (8)
Updated: Aug 28, 2007
Index
NAME
ipset - administration tool for IP sets
SYNOPSIS
ipset -N set type-specification [options]
ipset -[XFLSHh] [set] [options]
ipset -[EW] from-set to-set
ipset -[ADU] set entry
ipset -B set entry -b binding
ipset -T set entry [-b binding]
ipset -R
DESCRIPTION
ipset
is used to set up, maintain and inspect so called IP sets in the Linux
kernel. Depending on the type, an IP set may store IP addresses, (TCP/UDP)
port numbers or additional informations besides IP addresses: the word IP
means a general term here. See the set type definitions below.
Any entry in a set can be bound to another set, which forms a relationship
between a set element and the set it is bound to. In order to define a
binding it is not required that the entry be already added to the set.
The sets may have a default binding, which is valid for every set element
for which there is no binding defined at all.
IP set bindings pointing to sets and iptables matches and targets
referring to sets creates references, which protects the given sets in
the kernel. A set cannot be removed (destroyed) while there is a single
reference pointing to it.
OPTIONS
The options that are recognized by
ipset
can be divided into several different groups.
COMMANDS
These options specify the specific action to perform. Only one of them
can be specified on the command line unless otherwise specified
below. For all the long versions of the command and option names, you
need to use only enough letters to ensure that
ipset
can differentiate it from all other options.
- -N, --create setname type type-specific-options
-
Create a set identified with setname and specified type.
Type-specific options must be supplied.
- -X, --destroy [setname]
-
Destroy the specified set, or all sets if none or the keyword
:all:
is specified.
Before destroying the set, all bindings belonging to the
set elements and the default binding of the set are removed.
If the set has got references, nothing is done.
- -F, --flush [setname]
-
Delete all entries from the specified set, or flush
all sets if none or the keyword
:all:
is given. Bindings are not affected by the flush operation.
- -E, --rename from-setname to-setname
-
Rename a set. Set identified by to-setname must not exist.
- -W, --swap from-setname to-setname
-
Swap two sets as they referenced in the Linux kernel.
iptables
rules or
ipset
bindings pointing to the content of from-setname will point to
the content of to-setname and vice versa. Both sets must exist.
- -L, --list [setname]
-
List the entries and bindings for the specified set, or for
all sets if none or the keyword
:all:
is given. The
-n, --numeric
option can be used to suppress name lookups and generate numeric
output. When the
-s, --sorted
option is given, the entries are listed sorted (if the given set
type supports the operation).
- -S, --save [setname]
-
Save the given set, or all sets if none or the keyword
:all:
is specified to stdout in a format that --restore can read.
- -R, --restore
-
Restore a saved session generated by --save. The saved session
can be fed from stdin.
When generating a session file please note that the supported commands
(create set, add element, bind) must appear in a strict order: first create
the set, then add all elements. Then create the next set, add all its elements
and so on. Finally you can list all binding commands. Also, it is a restore
operation, so the sets being restored must not exist.
- -A, --add setname IP
-
Add an IP to a set.
- -D, --del setname IP
-
Delete an IP from a set.
- -T, --test setname IP
-
Test wether an IP is in a set or not. Exit status number is zero
if the tested IP is in the set and nonzero if it is missing from
the set.
- -T, --test setname IP --binding to-setname
-
Test wether the IP belonging to the set points to the specified binding.
Exit status number is zero if the binding points to the specified set,
otherwise it is nonzero. The keyword
:default:
can be used to test the default binding of the set.
- -B, --bind setname IP --binding to-setname
-
Bind the IP in setname to to-setname.
- -U, --unbind setname IP
-
Delete the binding belonging to IP in set setname.
- -H, --help [settype]
-
Print help and settype specific help if settype specified.
At the
-B, -U
and
-T
commands you can use the token
:default:
to bind, unbind or test the default binding of a set instead
of an IP. At the
-U
command you can use the token
:all:
to destroy the bindings of all elements of a set.
OTHER OPTIONS
The following additional options can be specified:
- -b, --binding setname
-
The option specifies the value of the binding for the
-B
binding command, for which it is a mandatory option.
You can use it in the
-T
test command as well to test bindings.
- -s, --sorted
-
Sorted output. When listing sets, entries are listed sorted.
- -n, --numeric
-
Numeric output. When listing sets, bindings, IP addresses and
port numbers will be printed in numeric format. By default the
program will try to display them as host names, network names
or services (whenever applicable), which can trigger
slow
DNS
lookups.
- -q, --quiet
-
Suppress any output to stdout and stderr. ipset will still return
possible errors.
SET TYPES
ipset supports the following set types:
ipmap
The ipmap set type uses a memory range, where each bit represents
one IP address. An ipmap set can store up to 65536 (B-class network)
IP addresses. The ipmap set type is very fast and memory cheap, great
for use when one want to match certain IPs in a range. Using the
--netmask
option with a CIDR netmask value between 0-32 when creating an ipmap
set, you will be able to store and match network addresses: i.e an
IP address will be in the set if the value resulted by masking the address
with the specified netmask can be found in the set.
Options to use when creating an ipmap set:
- --from from-IP
-
- --to to-IP
-
Create an ipmap set from the specified range.
- --network IP/mask
-
Create an ipmap set from the specified network.
- --netmask CIDR-netmask
-
When the optional
--netmask
parameter specified, network addresses will be
stored in the set instead of IP addresses, and the from-IP parameter
must be a network address.
macipmap
The macipmap set type uses a memory range, where each 8 bytes
represents one IP and a MAC addresses. A macipmap set type can store
up to 65536 (B-class network) IP addresses with MAC.
When adding an entry to a macipmap set, you must specify the entry as
IP:MAC.
When deleting or testing macipmap entries, the
:MAC
part is not mandatory. (The old "%" separation token instead of ":", i.e
IP%MAC is accepted as well.)
Options to use when creating an macipmap set:
- --from from-IP
-
- --to to-IP
-
Create a macipmap set from the specified range.
- --network IP/mask
-
Create a macipmap set from the specified network.
- --matchunset
-
When the optional
--matchunset
parameter specified, IP addresses which could be stored
in the set but not set yet, will always match.
Please note, the
set
and
SET
netfilter kernel modules
always
use the source MAC address from the packet to match, add or delete
entries from a macipmap type of set.
portmap
The portmap set type uses a memory range, where each bit represents
one port. A portmap set type can store up to 65536 ports.
The portmap set type is very fast and memory cheap.
Options to use when creating an portmap set:
- --from from-port
-
- --to to-port
-
Create a portmap set from the specified range.
iphash
The iphash set type uses a hash to store IP addresses.
In order to avoid clashes in the hash double-hashing, and as a last
resort, dynamic growing of the hash performed. The iphash set type is
great to store random addresses. By supplyig the
--netmask
option with a CIDR netmask value between 0-32 at creating the set,
you will be able to store and match network addresses instead: i.e
an IP address will be in the set if the value of the address
masked with the specified netmask can be found in the set.
Options to use when creating an iphash set:
- --hashsize hashsize
-
The initial hash size (default 1024)
- --probes probes
-
How many times try to resolve clashing at adding an IP to the hash
by double-hashing (default 8).
- --resize percent
-
Increase the hash size by this many percent (default 50) when adding
an IP to the hash could not be performed after
probes
number of double-hashing.
- --netmask CIDR-netmask
-
When the optional
--netmask
parameter specified, network addresses will be
stored in the set instead of IP addresses.
The iphash type of sets can store up to 65535 entries. If a set is full,
no new entries can be added to it.
Sets created by zero valued resize parameter won't be resized at all.
The lookup time in an iphash type of set approximately linearly grows with
the value of the
probes
parameter. At the same time higher
probes
values result a better utilized hash while smaller values
produce a larger, sparse hash.
nethash
The nethash set type uses a hash to store different size of
network addresses. The
IP
"address" used in the ipset commands must be in the form
IP-address/cidr-size
where the CIDR block size must be in the inclusive range of 1-31.
In order to avoid clashes in the hash
double-hashing, and as a last resort, dynamic growing of the hash performed.
Options to use when creating an nethash set:
- --hashsize hashsize
-
The initial hash size (default 1024)
- --probes probes
-
How many times try to resolve clashing at adding an IP to the hash
by double-hashing (default 4).
- --resize percent
-
Increase the hash size by this many percent (default 50) when adding
an IP to the hash could not be performed after
The nethash type of sets can store up to 65535 entries. If a set is full,
no new entries can be added to it.
An IP address will be in a nethash type of set if it is in any of the
netblocks added to the set and the matching always start from the smallest
size of netblock (most specific netmask) to the biggest ones (least
specific netmasks). When adding/deleting IP addresses
to a nethash set by the
SET
netfilter kernel module, it will be added/deleted by the smallest
netblock size which can be found in the set.
The lookup time in a nethash type of set is approximately linearly
grows with the times of the
probes
parameter and the number of different mask parameters in the hash.
Otherwise the same speed and memory efficiency comments applies here
as at the iphash type.
ipporthash
The ipporthash set type uses a hash to store IP address and port pairs.
In order to avoid clashes in the hash double-hashing, and as a last
resort, dynamic growing of the hash performed. An ipporthash set can
store up to 65536 (B-class network) IP addresses with all possible port
values. When adding, deleting and testing values in an ipporthash type of
set, the entries must be specified as
"IP:port".
(Old "IP%port" format accepted as well.)
The ipporthash types of sets evaluates two src/dst parameters of the
set
match and
SET
target.
Options to use when creating an ipporthash set:
- --from from-IP
-
- --to to-IP
-
Create an ipporthash set from the specified range.
- --network IP/mask
-
Create an ipporthash set from the specified network.
- --hashsize hashsize
-
The initial hash size (default 1024)
- --probes probes
-
How many times try to resolve clashing at adding an IP to the hash
by double-hashing (default 8).
- --resize percent
-
Increase the hash size by this many percent (default 50) when adding
an IP to the hash could not be performed after
probes
number of double-hashing.
The same resizing, speed and memory efficiency comments applies here
as at the iphash type.
iptree
The iptree set type uses a tree to store IP addresses, optionally
with timeout values.
Options to use when creating an iptree set:
- --timeout value
-
The timeout value for the entries in seconds (default 0)
If a set was created with a nonzero valued
--timeout
parameter then one may add IP addresses to the set with a specific
timeout value using the syntax
IP:timeout-value.
Similarly to the hash types, the iptree type of sets can store up to 65535
entries.
iptreemap
The iptreemap set type uses a tree to store IP addresses or networks,
where the last octet of an IP address are stored in a bitmap.
As input entry, you can add IP addresses, CIDR blocks or network ranges
to the set. Network ranges can be specified in the format
IP1:IP2
Options to use when creating an iptreemap set:
- --gc value
-
How often the garbage collection should be called, in seconds (default 300)
GENERAL RESTRICTIONS
Setnames starting with colon (:) cannot be defined. Zero valued set
entries cannot be used with hash type of sets.
COMMENTS
If you want to store same size subnets from a given network
(say /24 blocks from a /8 network), use the ipmap set type.
If you want to store random same size networks (say random /24 blocks),
use the iphash set type. If you have got random size of netblocks,
use nethash.
DIAGNOSTICS
Various error messages are printed to standard error. The exit code
is 0 for correct functioning. Errors which appear to be caused by
invalid or abused command line parameters cause an exit code of 2, and
other errors cause an exit code of 1.
BUGS
Bugs? No, just funny features. :-)
OK, just kidding...
SEE ALSO
iptables(8),
AUTHORS
Jozsef Kadlecsik wrote ipset, which is based on ippool by
Joakim Axelsson, Patrick Schaaf and Martin Josefsson.
Sven Wegener wrote the iptreemap type.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- OPTIONS
-
- COMMANDS
-
- OTHER OPTIONS
-
- SET TYPES
-
- ipmap
-
- macipmap
-
- portmap
-
- iphash
-
- nethash
-
- ipporthash
-
- iptree
-
- iptreemap
-
- GENERAL RESTRICTIONS
-
- COMMENTS
-
- DIAGNOSTICS
-
- BUGS
-
- SEE ALSO
-
- AUTHORS
-
This document was created by
man2html,
using the manual pages.
Time: 10:31:59 GMT, August 28, 2007