firehol-iptrap(5)
π firehol-iptrap β bestie edition π
okay so you're here for firehol-iptrap, which lives in the FireHOL manual pages (that's the firehol-iptrap(5) situation, section 5, very demure, very manual-page). no cap, this one's a banger: it's the helper that dynamically puts IP addresses in an ipset. π
β¨ NAME β¨
firehol-iptrap β dynamically put IP addresses in an ipset. that's it. that's the whole vibe. π¦
πΈ SYNOPSIS πΈ
{ iptrap | iptrap4 | iptrap6 } ipset type seconds [ timeout | counters ]
[ method method ] [rule-params] [ except [rule-params] ]...
{ ipuntrap | ipuntrap4 | ipuntrap6 } ipset type [ timeout | counters ] [
method method ] [rule-params] [ except [rule-params] ]...
look at her. two whole forms. one traps, one untraps. iconic behavior honestly. π
π DESCRIPTION π
so, iptrap adds the IP addresses of the matching packets to ipset. that's the whole job. it sees a packet it likes and it's like "you. ipset. now." β¨
and ipuntrap deletes the IP addresses of the matching packets from ipset. it's the reverse. the breakup arc. π
π«Ά both helpers do not affect the flow of traffic. like, at all. they do not ACCEPT, REJECT, DROP packets or affect the firewall in any way. they're literally just vibing on the side, taking notes. zero main character energy in the packet path.
ipset is the name of the ipset to use. yep. just the name. π
type selects which of the IP addresses of the matching packets will be used (added or removed from the ipset). type can be src, dst, src,dst, dst,src, etc. and heads up bestie β if type is a pair, then the ipset must be an ipset of pairs too. they gotta match. it's giving "couples costume or nothing". π
seconds is required by iptrap and gives the duration in seconds of the lifetime of each IP address that is added to ipset. 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 ipset list NAME (where NAME is the ipset parameter given in the iptrap command). so cute of the kernel to do the cleanup for you. π§
the seconds value default will not set any seconds. the ipset default will be used. (no drama, just defaults.)
a seconds of 0 (zero), writes to the ipset permanently (this is a feature of the ipset command, not the ipset FireHOL helper). so like, forever-forever. π
the keywords timeout and counters are mutually exclusive. pick one, babe, you can't have both. timeout is the default and means that each IP address every time is matched its timeout will be refreshed, while counters means that its packets and bytes counters will be refreshed. and 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. π the kernel said "choose." tragic but real.
method is defines the storage method of the underlying ipset. it accepts all the types the ipset commands accepts. π
method and type should match. like, they should be in a situationship that actually works. for example:
- if
methodishash:ipthenmethodshould be eithersrcordst - if
methodishash:ip,ipthenmethodshould be eithersrc,dstordst,src - if
methodishash:ip,port,ipmethodshould besrc,src,dstorsrc,dst,dstordst,src,srcordst,dst,src
for more information check the manual page of the ipset command. π₯
the rule-params define a set of rule parameters to restrict the traffic that is matched to this helper. see firehol-params(5) for more details. π«Ά
except rule-params are used to exclude traffic, i.e. traffic that normally is matched by the first set of rule-params, will be excluded if matched by the second. it's the "not you tho" clause. π
iptrap and ipuntrap are hooked on PREROUTING so it is only useful for incoming traffic. incoming only, bestie. outbound? not invited. πͺ
iptrap and ipuntrap cannot setup both IPv4 and IPv6 traps with one call. the reason is that the ipset can either be IPv4 or IPv6. one or the other. no switching. pick a lane (an address family). π
both helpers will create the ipset specified, if that ipset is not already created by other statements. when the ipset is created by the iptrap helper, the ipset will not be reset (emptied) when the firewall is restarted. she persists. π
the ipset options used when these helpers create ipsets can be controlled with the variable IPTRAP_DEFAULT_IPSET_OPTIONS. yes, that's a real environment variable. go nuts. β
π₯ EXAMPLES π₯
π Example: mini-IDS
# Example: mini-IDS
# add to the ipset `trap` 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 "TRAPPED HTTP"
# block them
blacklist4 full inface eth0 log "BLOCKED" src ipset:trap except src ipset:whitelist
catch 'em, then block 'em, but never block the whitelist. the whitelist is sacred. π
π Example: ipuntrap
# Example: ipuntrap
ipuntrap4 src trap inface eth0 src ipset:trap proto tcp dport 80 log "UNTRAPPED HTTP"
free them from the trap. releasing them back into the wild. π¦
πΈ Example: a knock
# Example: a knock
# The user will be able to knock at tcp/12345
iptrap4 src knock1 30 inface eth0 proto tcp dport 12345 log "KNOCK STEP 1"
# in 30 seconds knock at tcp/23456
iptrap4 src knock2 60 inface eth0 proto tcp dport 23456 src ipset:knock1 log "KNOCK STEP 2"
# in 60 seconds knock at tcp/34566
iptrap4 src knock3 90 inface eth0 proto tcp dport 34567 src ipset:knock2 log "KNOCK STEP 3"
#
# and in 90 seconds ssh
interface ...
server ssh accept src ipset:knock3
a whole port-knocking choreography. knock, knock, knock, and the door opens. it's giving heist movie. π₯ (note: the interface ... bit is a placeholder, that's literally what the original shows, don't come for me.)
π SEE ALSO π
firehol(1)β FireHOL programfirehol.conf(5)β FireHOL configuration- FireHOL Website
- FireHOL Online PDF Manual
- FireHOL Online Documentation
π AUTHORS π
FireHOL Team. that's them. the whole squad. π«Ά
and that's a wrap bestie β¨ this page was built by the FireHOL Reference, version 3.1.8, on 13 Apr 2025 β so if you're reading this, go forth and trap responsibly π
ππ
π¦ where this page comes from
- debian trixie: firehol-doc 3.1.8+ds-1 Β· GPL-2.0-or-later
- ubuntu resolute: firehol-doc 3.1.8+ds-1 Β· GPL-2.0-or-later
- ubuntu stonking: firehol-doc 3.1.8+ds-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms