IPSET(8) IPSET(8) (NAME) ipset - IP (IP sets) (SYNOPSIS) ipset [ OPTIONS ] COMMAND [ COMMAND-OPTIONS ] COMMANDS := { create | add | del | test | destroy | list | save | restore | flush | rename | swap | help | version | - } OPTIONS := { -exist | -output { plain | save | xml } | json } | -quiet | -resolve | -sorted | -name | -terse | -file filename } ipset create SETNAME TYPENAME [ CREATE-OPTIONS ] ipset add SETNAME ADD-ENTRY [ ADD-OPTIONS ] ipset del SETNAME DEL-ENTRY [ DEL-OPTIONS ] ipset test SETNAME TEST-ENTRY [ TEST-OPTIONS ] ipset destroy [ SETNAME ] ipset list [ SETNAME ] ipset save [ SETNAME ] ipset restore ipset flush [ SETNAME ] ipset rename SETNAME-FROM SETNAME-TO ipset swap SETNAME-FROM SETNAME-TO ipset help [ TYPENAME ] ipset version ipset - (DESCRIPTION) ipset IP ( IP sets) . IP IP(v4/v6) (TCP/UDP) IP MAC IP . . Iptables (references) . (destroy). (OPTIONS) ipset . (COMMANDS) . . ipset . ipset . n, create SETNAME TYPENAME [ CREATE-OPTIONS ] setname (typename). . -exist ipset . add SETNAME ADD-ENTRY [ ADD-OPTIONS ] . -exist ipset . del SETNAME DEL-ENTRY [ DEL-OPTIONS ] . -exist ( ) . test SETNAME TEST-ENTRY [ TEST-OPTIONS ] . . x, destroy [ SETNAME ] () . (reference) . list [ SETNAME ] [ OPTIONS ] . -resolve ( ) . -sorted ( ). -output : plain save xml json. ( plain ). -name . -terse . -file . save [ SETNAME ] ( ) restore . -file . restore save . -file . restore . list help version restore. flush [ SETNAME ] . e, rename SETNAME-FROM SETNAME-TO . SETNAME-TO . w, swap SETNAME-FROM SETNAME-TO . . help [ TYPENAME ] TYPENAME . version . - ipset . quit . (OTHER OPTIONS) . . -!, -exist . -o, -output { plain | save | xml | json } list. -q, -quiet . ipset . -r, -resolve . IP DNS . -s, -sorted . . -n, -name . -t, -terse . -f, -file filename ( list save) ( restore). (INTRODUCTION) ( ) . TYPENAME create : TYPENAME := method:datatype[,datatype[,datatype]] bitmap hash list : ip net mac port iface. . entry : ipset add foo ipaddr,portnum,ipaddr IP . : ipset add foo [test-hostname],[ftp-data] DNS ipset IP . bitmap list . hash () . (clash) (chaining) ipset . (target) SET iptables/ip6tables . (GENERIC CREATE AND ADD OPTIONS) timeout timeout . timeout create ( ) . timeout timeout . . timeout -exist . timeout 2147483 ( ) . : ipset create test hash:ip timeout 300 ipset add test 192.168.0.1 timeout 60 ipset -exist add test 192.168.0.1 timeout 600 timeout : (garbage collector) . counters, packets, bytes counters . (packet) (byte) . ( ) packets bytes . : ipset create foo hash:ip counters ipset add foo 192.168.1.1 packets 42 bytes 1024 comment comment () . ipset ipset . ipset . (\) . : ipset add foo 1.1.1.1 comment "this comment is \"bad\"" ipset comment . "ipset save" "ipset restore" . : ipset create foo hash:ip comment ipset add foo 192.168.1.1/24 comment "allow access to SMB share on \\\\fileserv\\" : "allow access to SMB share on \\fileserv\" skbinfo, skbmark, skbprio, skbqueue skbinfo . ( firewall mark tc ) SET --map-set . skbmark: MARK MARK/MASK MARK MASK 0x . mark 0xffffffff . skbprio tc : MAJOR:MINOR major minor 0x . skbqueue . ipset create foo hash:ip skbinfo ipset add foo 192.168.0.1 skbmark 0x1111/0xff00ffff skbprio 1:10 skbqueue 10 hashsize create hash . 1024 . . : ipset create test hash:ip hashsize 1536 maxelem create hash . 65536 . : ipset create test hash:ip maxelem 2048 bucketsize create hash . (bucket) . 2 14 14 . ipset . : ipset create test hash:ip bucketsize 2 family { inet | inet6 } create hash hash:mac . IP . inet ( IPv4) . inet IPv4 IP : ipaddr := { ip | fromaddr-toaddr | ip/cidr } netaddr := { fromaddr-toaddr | ip/cidr } : ipset create test hash:ip family inet6 nomatch hash net ( hash:*net*) nomatch . nomatch . hash:net . ipset (test) nomatch . nomatch . forceadd forceadd . . ipset create foo hash:ip forceadd wildcard hash:net,iface . . "eth" . (SET TYPES) bitmap:ip bitmap:ip IPv4 () IPv4 . bitmap:ip 65536 . CREATE-OPTIONS := range fromip-toip|ip/cidr [ netmask cidr ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := { ip | fromip-toip | ip/cidr } ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := { ip | fromip-toip | ip/cidr } TEST-ENTRY := ip create: range fromip-toip|ip/cidr IPv4 . ( ) 65536 . create: netmask cidr netmask IP . cidr 1 32 . IP . bitmap:ip . : ipset create foo bitmap:ip range 192.168.0.0/16 ipset add foo 192.168.1/24 ipset test foo 192.168.1.1 bitmap:ip,mac bitmap:ip,mac IPv4 MAC . bitmap:ip,mac 65536 . CREATE-OPTIONS := range fromip-toip|ip/cidr [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ip[,macaddr] ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ip[,macaddr] TEST-ENTRY := ip[,macaddr] bitmap:ip,mac: range fromip-toip|ip/cidr IPv4 . 65536 . bitmap:ip,mac MAC . MAC MAC MAC . src set MAC dst MAC . timeout IP MAC . bitmap:ip,mac src/dst set SET . MAC << >> . : ipset create foo bitmap:ip,mac range 192.168.0.0/16 ipset add foo 192.168.1.1,12:34:56:78:9A:BC ipset test foo 192.168.1.1 bitmap:port bitmap:port 65536 . CREATE-OPTIONS := range fromport-toport [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := { [proto:]port | [proto:]fromport-toport } ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := { [proto:]port | [proto:]fromport-toport } TEST-ENTRY := [proto:]port bitmap:port: range [proto:]fromport-toport . set SET TCP UDP . proto TCP . . : ipset create foo bitmap:port range 0-1024 ipset add foo 80 ipset test foo 80 ipset del foo udp:[macon-udp]-[tn-tl-w2] hash:ip hash:ip IP () . IP hash:ip . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ netmask cidr ] [ bitmask mask ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr TEST-ENTRY := ipaddr create: netmask cidr netmask IP . cidr 1 32 IPv4 1 128 IPv6 . IP . : ipset create foo hash:ip netmask 30 ipset add foo 192.168.1.0/24 ipset test foo 192.168.1.2 bitmask mask netmask IPv4/v6 . netmask . hash:mac hash:mac MAC . MAC hash:mac . MAC << >> . CREATE-OPTIONS := [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := macaddr ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := macaddr TEST-ENTRY := macaddr : ipset create foo hash:mac ipset add foo 01:02:03:04:05:06 ipset test foo 01:02:03:04:05:06 hash:ip,mac hash:ip,mac IP MAC . MAC hash:ip,mac . MAC << >> . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr,macaddr ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr,macaddr TEST-ENTRY := ipaddr,macaddr : ipset create foo hash:ip,mac ipset add foo 1.1.1.1,01:02:03:04:05:06 ipset test foo 1.1.1.1,01:02:03:04:05:06 hash:net hash:net IP . . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := netaddr ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := netaddr TEST-ENTRY := netaddr netaddr := ip[/cidr] cidr . . . set ( ) ( ) . IP SET . . : ipset create foo hash:net ipset add foo 192.168.0.0/24 ipset add foo 10.1.0.0/16 ipset add foo 192.168.0/24 ipset add foo 192.168.0/30 nomatch IP 192.168.0.0/24 10.1.0.0/16 192.168.0/24 192.168.0/30 . hash:net,net hash:net,net IP . nomatch . . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ netmask cidr ] [ bitmask mask ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := netaddr,netaddr ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := netaddr,netaddr TEST-ENTRY := netaddr,netaddr netaddr := ip[/cidr] cidr . . . set ( ) ( ) . IP SET . . . create: netmask cidr netmask IP . cidr 1 32 IPv4 1 128 IPv6 . IP . bitmask mask netmask IPv4/v6 . netmask . : ipset create foo hash:net,net ipset add foo 192.168.0.0/24,10.0.1.0/24 ipset add foo 10.1.0.0/16,10.255.0.0/24 ipset add foo 192.168.0/24,192.168.54.0-192.168.54.255 ipset add foo 192.168.0/30,192.168.64/30 nomatch IP 192.168.0.0/24<->10.0.1.0/24 10.1.0.0/16<->10.255.0.0/24 192.168.0/24<->192.168.54.0/24 192.168.0/30<->192.168.64/30 . hash:ip,port hash:ip,port IP . ( TCP) . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ netmask cidr ] [ bitmask mask ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr,[proto:]port ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr,[proto:]port TEST-ENTRY := ipaddr,[proto:]port [proto:]port : portname[-portname] TCP TCP /etc/services portnumber[-portnumber] TCP TCP tcp|sctp|udp|udplite:portname|portnumber[-portname|portnumber] TCP SCTP UDP UDPLITE () () icmp:codename|type/code / ICMP. ICMP help . icmpv6:codename|type/code / ICMPv6. ICMPv6 help . proto:0 /etc/protocols . . hash:ip,port src/dst set SET . create: netmask cidr netmask IP . cidr 1 32 IPv4 1 128 IPv6 . IP . bitmask mask netmask IPv4/v6 . netmask . : ipset create foo hash:ip,port ipset add foo 192.168.1.0/24,80-82 ipset add foo 192.168.1.1,udp:53 ipset add foo 192.168.1.1,vrrp:0 ipset test foo 192.168.1.1,80 hash:net,port hash:net,port IP . ( TCP) . . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := netaddr,[proto:]port ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := netaddr,[proto:]port TEST-ENTRY := netaddr,[proto:]port netaddr := ip[/cidr] netaddr hash:net . [proto:]port hash:ip,port . cidr . . . set ( ) ( ) . IP SET . . : ipset create foo hash:net,port ipset add foo 192.168.0/24,25 ipset add foo 10.1.0.0/16,80 ipset test foo 192.168.0/24,25 hash:ip,port,ip hash:ip,port,ip IP IP . ( TCP) . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr,[proto:]port,ip ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr,[proto:]port,ip TEST-ENTRY := ipaddr,[proto:]port,ip ipaddr [proto:]port hash:ip,port . hash:ip,port,ip src/dst set SET . : ipset create foo hash:ip,port,ip ipset add foo 192.168.1.1,80,10.0.0.1 ipset test foo 192.168.1.1,udp:53,10.0.0.1 hash:ip,port,net hash:ip,port,net IP IP . ( TCP) . . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr,[proto:]port,netaddr ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr,[proto:]port,netaddr TEST-ENTRY := ipaddr,[proto:]port,netaddr netaddr := ip[/cidr] ipaddr [proto:]port hash:ip,port . netaddr hash:net . set ( cidr) ( cidr) . SET cidr cidr . cidr . hash:ip,port,net src/dst set SET . : ipset create foo hash:ip,port,net ipset add foo 192.168.1,80,10.0.0/24 ipset add foo 192.168.2,25,10.1.0.0/16 ipset test foo 192.168.1,80.10.0.0/24 hash:ip,mark hash:ip,mark IP (packet mark) . CREATE-OPTIONS := [ family { inet | inet6 } ] [ markmask value ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := ipaddr,mark ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := ipaddr,mark TEST-ENTRY := ipaddr,mark create: markmask value . AND . markmask 1 4294967295 . mark 0 4294967295 . hash:ip,mark src/dst set SET . : ipset create foo hash:ip,mark ipset add foo 192.168.1.0/24,555 ipset add foo 192.168.1.1,0x63 ipset add foo 192.168.1.1,111236 hash:net,port,net hash:net,port,net hash:ip,port,net cidr . /0 . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := netaddr,[proto:]port,netaddr ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := netaddr,[proto:]port,netaddr TEST-ENTRY := netaddr,[proto:]port,netaddr netaddr := ip[/cidr] [proto:]port hash:ip,port . netaddr hash:net . set ( cidr) ( cidr) . SET cidr cidr . hash:net,net. cidr cidr . hash:net,port,net src/dst set SET . : ipset create foo hash:net,port,net ipset add foo 192.168.1.0/24,0,10.0.0/24 ipset add foo 192.168.2.0/24,25,10.1.0.0/16 ipset test foo 192.168.1.1,80,10.0.0.1 hash:net,iface hash:net,iface IP . CREATE-OPTIONS := [ family { inet | inet6 } ] [ hashsize value ] [ maxelem value ] [ bucketsize value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := netaddr,[physdev:]iface ADD-OPTIONS := [ timeout value ] [ nomatch ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] [ wildcard ] DEL-ENTRY := netaddr,[physdev:]iface TEST-ENTRY := netaddr,[physdev:]iface netaddr := ip[/cidr] netaddr hash:net . cidr . . . set ( ) ( ) . IP SET . set SET : src ( -i iptables) dst ( -o iptables) . physdev: (bridge port) . . hash:net,iface . : ipset create foo hash:net,iface ipset add foo 192.168.0/24,eth0 ipset add foo 10.1.0.0/16,eth1 ipset test foo 192.168.0/24,eth0 list:set list:set . CREATE-OPTIONS := [ size value ] [ timeout value ] [ counters ] [ comment ] [ skbinfo ] ADD-ENTRY := setname [ { before | after } setname ] ADD-OPTIONS := [ timeout value ] [ packets value ] [ bytes value ] [ comment string ] [ skbmark value ] [ skbprio value ] [ skbqueue value ] DEL-ENTRY := setname [ { before | after } setname ] TEST-ENTRY := setname [ { before | after } setname ] create: size value 8 . 6.24 ipset . ipset list:set . set SET list:set . . : . a b list:set : iptables -m set --match-set a src,dst -j SET --add-set b src,dst a b a src src,dst b . list:set . : ipset list:set (test) ( IP) . (GENERAL RESTRICTIONS) . . (COMMENTS) ( /24 /8) bitmap:ip . ( /24) hash:ip . hash:net . MAC dst set MAC PREROUTING INPUT FORWARD MAC ( MAC ) . MAC IP . MAC ( OUTPUT) . ipset . iptree iptreemap : hash:ip . (DIAGNOSTICS) . (0) . (BUGS) ! :\-) ... (SEE ALSO) iptables(8), ip6tables(8) iptables-extensions(8) (AUTHORS) Jozsef Kadlecsik ipset ippool Joakim Axelsson Patrick Schaaf Martin Josefsson . Sven Wegener iptreemap . (LAST REMARK) I stand on the shoulders of giants. Jozsef Kadlecsik June 25, 2015 IPSET(8)