.\" Automatically generated by Pandoc 3.1.3 .nh .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. .ie "\f[CB]x\f[]"x" \{\ . ftr V B . ftr VI BI . ftr VB B . ftr VBI BI .\} .el \{\ . ftr V CR . ftr VI CI . ftr VB CB . ftr VBI CBI .\} .TH "firehol-iptrap" "5" "Built 30 Mar 2024" "FireHOL Reference" "3.1.7" .hy .SH NAME .PP firehol-iptrap - dynamically put IP addresses in an ipset .SH SYNOPSIS .PP { iptrap | iptrap4 | iptrap6 } \f[I]ipset\f[R] \f[I]type\f[R] \f[I]seconds\f[R] [ timeout | counters ] [ method \f[B]method\f[R] ] [\f[I]rule-params\f[R]] [ except [\f[I]rule-params\f[R]] ]\&... .PP { ipuntrap | ipuntrap4 | ipuntrap6 } \f[I]ipset\f[R] \f[I]type\f[R] [ timeout | counters ] [ method \f[B]method\f[R] ] [\f[I]rule-params\f[R]] [ except [\f[I]rule-params\f[R]] ]\&... .SH DESCRIPTION .PP \f[V]iptrap\f[R] adds the IP addresses of the matching packets to \f[V]ipset\f[R]. .PP \f[V]ipuntrap\f[R] deletes the IP addresses of the matching packets from \f[V]ipset\f[R]. .PP Both helpers do not affect the flow of traffic. They do not \f[V]ACCEPT\f[R], \f[V]REJECT\f[R], \f[V]DROP\f[R] packets or affect the firewall in any way. .PP \f[V]ipset\f[R] is the name of the ipset to use. .PP \f[V]type\f[R] selects which of the IP addresses of the matching packets will be used (added or removed from the ipset). \f[V]type\f[R] can be \f[V]src\f[R], \f[V]dst\f[R], \f[V]src,dst\f[R], \f[V]dst,src\f[R], etc. If type is a pair, then the ipset must be an ipset of pairs too. .PP \f[V]seconds\f[R] is required by \f[V]iptrap\f[R] and gives the duration in seconds of the lifetime of each IP address that is added to \f[V]ipset\f[R]. Every matching packet will refresh this duration for the IP address in the ipset. The Linux kernel will automatically remove the IP from the ipset when this time expires. The user may monitor the remaining time for each IP, by running \f[V]ipset list NAME\f[R] (where \f[V]NAME\f[R] is the \f[V]ipset\f[R] parameter given in the \f[V]iptrap\f[R] command). .PP The seconds value \f[V]default\f[R] will not set any seconds. The ipset default will be used. .PP A seconds of \f[V]0\f[R] (zero), writes to the ipset permanently (this is a feature of the ipset command, not the ipset FireHOL helper). .PP The keywords \f[V]timeout\f[R] and \f[V]counters\f[R] are mutually exclusive. \f[V]timeout\f[R] is the default and means that each IP address every time is matched its timeout will be refreshed, while \f[V]counters\f[R] means that its packets and bytes counters will be refreshed. Unfortunately the kernel either re-add the IP in the ipset with the new timeout - but its counters will be lost, or just the counters will be updated, but the timeout will not be refreshed. .PP \f[V]method\f[R] is defines the storage method of the underlying ipset. It accepts all the types the ipset commands accepts. .PP \f[V]method\f[R] and \f[V]type\f[R] should match. For example if method is \f[V]hash:ip\f[R] then method should be either \f[V]src\f[R] or \f[V]dst\f[R]. If method is \f[V]hash:ip,ip\f[R] then method should be either \f[V]src,dst\f[R] or \f[V]dst,src\f[R]. If method is \f[V]hash:ip,port,ip\f[R] method should be \f[V]src,src,dst\f[R] or \f[V]src,dst,dst\f[R] or \f[V]dst,src,src\f[R] or \f[V]dst,dst,src\f[R]. For more information check the manual page of the ipset command. .PP The \f[I]rule-params\f[R] define a set of rule parameters to restrict the traffic that is matched to this helper. See firehol-params(5) for more details. .PP \f[V]except\f[R] \f[I]rule-params\f[R] are used to exclude traffic, i.e.\ traffic that normally is matched by the first set of \f[I]rule-params\f[R], will be excluded if matched by the second. .PP \f[V]iptrap\f[R] and \f[V]ipuntrap\f[R] are hooked on PREROUTING so it is only useful for incoming traffic. .PP \f[V]iptrap\f[R] and \f[V]ipuntrap\f[R] cannot setup both IPv4 and IPv6 traps with one call. The reason is that the \f[V]ipset\f[R] can either be IPv4 or IPv6. .PP Both helpers will create the \f[V]ipset\f[R] specified, if that ipset is not already created by other statements. When the ipset is created by the \f[V]iptrap\f[R] helper, the ipset will not be reset (emptied) when the firewall is restarted. .PP The ipset options used when these helpers create ipsets can be controlled with the variable IPTRAP_DEFAULT_IPSET_OPTIONS. .SH EXAMPLES .IP .nf \f[C] # Example: mini-IDS # add to the ipset \[ga]trap\[ga] for an hour (3600 seconds) all IPs from all packets # coming from eth0 and going to tcp/3306 (mysql). iptrap4 src trap 3600 inface eth0 proto tcp dport 3306 log \[dq]TRAPPED HTTP\[dq] # block them blacklist4 full inface eth0 log \[dq]BLOCKED\[dq] src ipset:trap except src ipset:whitelist # Example: ipuntrap ipuntrap4 src trap inface eth0 src ipset:trap proto tcp dport 80 log \[dq]UNTRAPPED HTTP\[dq] # Example: a knock # The user will be able to knock at tcp/12345 iptrap4 src knock1 30 inface eth0 proto tcp dport 12345 log \[dq]KNOCK STEP 1\[dq] # in 30 seconds knock at tcp/23456 iptrap4 src knock2 60 inface eth0 proto tcp dport 23456 src ipset:knock1 log \[dq]KNOCK STEP 2\[dq] # in 60 seconds knock at tcp/34566 iptrap4 src knock3 90 inface eth0 proto tcp dport 34567 src ipset:knock2 log \[dq]KNOCK STEP 3\[dq] # # and in 90 seconds ssh interface ... server ssh accept src ipset:knock3 \f[R] .fi .SH SEE ALSO .IP \[bu] 2 firehol(1) - FireHOL program .IP \[bu] 2 firehol.conf(5) - FireHOL configuration .IP \[bu] 2 FireHOL Website (http://firehol.org/) .IP \[bu] 2 FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf) .IP \[bu] 2 FireHOL Online Documentation (http://firehol.org/documentation/) .SH AUTHORS FireHOL Team.