iptables-extensions.8 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649
  1. .TH iptables-extensions 8 "" "iptables 1.4.18" "iptables 1.4.18"
  2. .SH NAME
  3. iptables-extensions \(em list of extensions in the standard iptables distribution
  4. .SH SYNOPSIS
  5. \fBip6tables\fP [\fB\-m\fP \fIname\fP [\fImodule-options\fP...]]
  6. [\fB\-j\fP \fItarget-name\fP [\fItarget-options\fP...]
  7. .PP
  8. \fBiptables\fP [\fB\-m\fP \fIname\fP [\fImodule-options\fP...]]
  9. [\fB\-j\fP \fItarget-name\fP [\fItarget-options\fP...]
  10. .SH MATCH EXTENSIONS
  11. iptables can use extended packet matching modules
  12. with the \fB\-m\fP or \fB\-\-match\fP
  13. options, followed by the matching module name; after these, various
  14. extra command line options become available, depending on the specific
  15. module. You can specify multiple extended match modules in one line,
  16. and you can use the \fB\-h\fP or \fB\-\-help\fP
  17. options after the module has been specified to receive help specific
  18. to that module. The extended match modules are evaluated in the order
  19. they are specified in the rule.
  20. .PP
  21. If the \fB\-p\fP or \fB\-\-protocol\fP was specified and if and only if an
  22. unknown option is encountered, iptables will try load a match module of the
  23. same name as the protocol, to try making the option available.
  24. .\" @MATCH@
  25. .SS addrtype
  26. This module matches packets based on their
  27. .B address type.
  28. Address types are used within the kernel networking stack and categorize
  29. addresses into various groups. The exact definition of that group depends on the specific layer three protocol.
  30. .PP
  31. The following address types are possible:
  32. .TP
  33. .BI "UNSPEC"
  34. an unspecified address (i.e. 0.0.0.0)
  35. .TP
  36. .BI "UNICAST"
  37. an unicast address
  38. .TP
  39. .BI "LOCAL"
  40. a local address
  41. .TP
  42. .BI "BROADCAST"
  43. a broadcast address
  44. .TP
  45. .BI "ANYCAST"
  46. an anycast packet
  47. .TP
  48. .BI "MULTICAST"
  49. a multicast address
  50. .TP
  51. .BI "BLACKHOLE"
  52. a blackhole address
  53. .TP
  54. .BI "UNREACHABLE"
  55. an unreachable address
  56. .TP
  57. .BI "PROHIBIT"
  58. a prohibited address
  59. .TP
  60. .BI "THROW"
  61. FIXME
  62. .TP
  63. .BI "NAT"
  64. FIXME
  65. .TP
  66. .BI "XRESOLVE"
  67. .TP
  68. [\fB!\fP] \fB\-\-src\-type\fP \fItype\fP
  69. Matches if the source address is of given type
  70. .TP
  71. [\fB!\fP] \fB\-\-dst\-type\fP \fItype\fP
  72. Matches if the destination address is of given type
  73. .TP
  74. .BI "\-\-limit\-iface\-in"
  75. The address type checking can be limited to the interface the packet is coming
  76. in. This option is only valid in the
  77. .BR PREROUTING ,
  78. .B INPUT
  79. and
  80. .B FORWARD
  81. chains. It cannot be specified with the
  82. \fB\-\-limit\-iface\-out\fP
  83. option.
  84. .TP
  85. \fB\-\-limit\-iface\-out\fP
  86. The address type checking can be limited to the interface the packet is going
  87. out. This option is only valid in the
  88. .BR POSTROUTING ,
  89. .B OUTPUT
  90. and
  91. .B FORWARD
  92. chains. It cannot be specified with the
  93. \fB\-\-limit\-iface\-in\fP
  94. option.
  95. .SS ah (IPv6-specific)
  96. This module matches the parameters in Authentication header of IPsec packets.
  97. .TP
  98. [\fB!\fP] \fB\-\-ahspi\fP \fIspi\fP[\fB:\fP\fIspi\fP]
  99. Matches SPI.
  100. .TP
  101. [\fB!\fP] \fB\-\-ahlen\fP \fIlength\fP
  102. Total length of this header in octets.
  103. .TP
  104. \fB\-\-ahres\fP
  105. Matches if the reserved field is filled with zero.
  106. .SS ah (IPv4-specific)
  107. This module matches the SPIs in Authentication header of IPsec packets.
  108. .TP
  109. [\fB!\fP] \fB\-\-ahspi\fP \fIspi\fP[\fB:\fP\fIspi\fP]
  110. .SS cluster
  111. Allows you to deploy gateway and back-end load-sharing clusters without the
  112. need of load-balancers.
  113. .PP
  114. This match requires that all the nodes see the same packets. Thus, the cluster
  115. match decides if this node has to handle a packet given the following options:
  116. .TP
  117. \fB\-\-cluster\-total\-nodes\fP \fInum\fP
  118. Set number of total nodes in cluster.
  119. .TP
  120. [\fB!\fP] \fB\-\-cluster\-local\-node\fP \fInum\fP
  121. Set the local node number ID.
  122. .TP
  123. [\fB!\fP] \fB\-\-cluster\-local\-nodemask\fP \fImask\fP
  124. Set the local node number ID mask. You can use this option instead
  125. of \fB\-\-cluster\-local\-node\fP.
  126. .TP
  127. \fB\-\-cluster\-hash\-seed\fP \fIvalue\fP
  128. Set seed value of the Jenkins hash.
  129. .PP
  130. Example:
  131. .IP
  132. iptables \-A PREROUTING \-t mangle \-i eth1 \-m cluster
  133. \-\-cluster\-total\-nodes 2 \-\-cluster\-local\-node 1
  134. \-\-cluster\-hash\-seed 0xdeadbeef
  135. \-j MARK \-\-set-mark 0xffff
  136. .IP
  137. iptables \-A PREROUTING \-t mangle \-i eth2 \-m cluster
  138. \-\-cluster\-total\-nodes 2 \-\-cluster\-local\-node 1
  139. \-\-cluster\-hash\-seed 0xdeadbeef
  140. \-j MARK -\-set\-mark 0xffff
  141. .IP
  142. iptables \-A PREROUTING \-t mangle \-i eth1
  143. \-m mark ! \-\-mark 0xffff \-j DROP
  144. .IP
  145. iptables \-A PREROUTING \-t mangle \-i eth2
  146. \-m mark ! \-\-mark 0xffff \-j DROP
  147. .PP
  148. And the following commands to make all nodes see the same packets:
  149. .IP
  150. ip maddr add 01:00:5e:00:01:01 dev eth1
  151. .IP
  152. ip maddr add 01:00:5e:00:01:02 dev eth2
  153. .IP
  154. arptables \-A OUTPUT \-o eth1 \-\-h\-length 6
  155. \-j mangle \-\-mangle-mac-s 01:00:5e:00:01:01
  156. .IP
  157. arptables \-A INPUT \-i eth1 \-\-h-length 6
  158. \-\-destination-mac 01:00:5e:00:01:01
  159. \-j mangle \-\-mangle\-mac\-d 00:zz:yy:xx:5a:27
  160. .IP
  161. arptables \-A OUTPUT \-o eth2 \-\-h\-length 6
  162. \-j mangle \-\-mangle\-mac\-s 01:00:5e:00:01:02
  163. .IP
  164. arptables \-A INPUT \-i eth2 \-\-h\-length 6
  165. \-\-destination\-mac 01:00:5e:00:01:02
  166. \-j mangle \-\-mangle\-mac\-d 00:zz:yy:xx:5a:27
  167. .PP
  168. In the case of TCP connections, pickup facility has to be disabled
  169. to avoid marking TCP ACK packets coming in the reply direction as
  170. valid.
  171. .IP
  172. echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose
  173. .SS comment
  174. Allows you to add comments (up to 256 characters) to any rule.
  175. .TP
  176. \fB\-\-comment\fP \fIcomment\fP
  177. .TP
  178. Example:
  179. iptables \-A INPUT \-i eth1 \-m comment \-\-comment "my local LAN"
  180. .SS connbytes
  181. Match by how many bytes or packets a connection (or one of the two
  182. flows constituting the connection) has transferred so far, or by
  183. average bytes per packet.
  184. .PP
  185. The counters are 64-bit and are thus not expected to overflow ;)
  186. .PP
  187. The primary use is to detect long-lived downloads and mark them to be
  188. scheduled using a lower priority band in traffic control.
  189. .PP
  190. The transferred bytes per connection can also be viewed through
  191. `conntrack \-L` and accessed via ctnetlink.
  192. .PP
  193. NOTE that for connections which have no accounting information, the match will
  194. always return false. The "net.netfilter.nf_conntrack_acct" sysctl flag controls
  195. whether \fBnew\fP connections will be byte/packet counted. Existing connection
  196. flows will not be gaining/losing a/the accounting structure when be sysctl flag
  197. is flipped.
  198. .TP
  199. [\fB!\fP] \fB\-\-connbytes\fP \fIfrom\fP[\fB:\fP\fIto\fP]
  200. match packets from a connection whose packets/bytes/average packet
  201. size is more than FROM and less than TO bytes/packets. if TO is
  202. omitted only FROM check is done. "!" is used to match packets not
  203. falling in the range.
  204. .TP
  205. \fB\-\-connbytes\-dir\fP {\fBoriginal\fP|\fBreply\fP|\fBboth\fP}
  206. which packets to consider
  207. .TP
  208. \fB\-\-connbytes\-mode\fP {\fBpackets\fP|\fBbytes\fP|\fBavgpkt\fP}
  209. whether to check the amount of packets, number of bytes transferred or
  210. the average size (in bytes) of all packets received so far. Note that
  211. when "both" is used together with "avgpkt", and data is going (mainly)
  212. only in one direction (for example HTTP), the average packet size will
  213. be about half of the actual data packets.
  214. .TP
  215. Example:
  216. iptables .. \-m connbytes \-\-connbytes 10000:100000 \-\-connbytes\-dir both \-\-connbytes\-mode bytes ...
  217. .SS connlimit
  218. Allows you to restrict the number of parallel connections to a server per
  219. client IP address (or client address block).
  220. .TP
  221. \fB\-\-connlimit\-upto\fP \fIn\fP
  222. Match if the number of existing connections is below or equal \fIn\fP.
  223. .TP
  224. \fB\-\-connlimit\-above\fP \fIn\fP
  225. Match if the number of existing connections is above \fIn\fP.
  226. .TP
  227. \fB\-\-connlimit\-mask\fP \fIprefix_length\fP
  228. Group hosts using the prefix length. For IPv4, this must be a number between
  229. (including) 0 and 32. For IPv6, between 0 and 128. If not specified, the
  230. maximum prefix length for the applicable protocol is used.
  231. .TP
  232. \fB\-\-connlimit\-saddr\fP
  233. Apply the limit onto the source group. This is the default if
  234. \-\-connlimit\-daddr is not specified.
  235. .TP
  236. \fB\-\-connlimit\-daddr\fP
  237. Apply the limit onto the destination group.
  238. .PP
  239. Examples:
  240. .TP
  241. # allow 2 telnet connections per client host
  242. iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-above 2 \-j REJECT
  243. .TP
  244. # you can also match the other way around:
  245. iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-upto 2 \-j ACCEPT
  246. .TP
  247. # limit the number of parallel HTTP requests to 16 per class C sized \
  248. source network (24 bit netmask)
  249. iptables \-p tcp \-\-syn \-\-dport 80 \-m connlimit \-\-connlimit\-above 16
  250. \-\-connlimit\-mask 24 \-j REJECT
  251. .TP
  252. # limit the number of parallel HTTP requests to 16 for the link local network
  253. (ipv6)
  254. ip6tables \-p tcp \-\-syn \-\-dport 80 \-s fe80::/64 \-m connlimit \-\-connlimit\-above
  255. 16 \-\-connlimit\-mask 64 \-j REJECT
  256. .TP
  257. # Limit the number of connections to a particular host:
  258. ip6tables \-p tcp \-\-syn \-\-dport 49152:65535 \-d 2001:db8::1 \-m connlimit
  259. \-\-connlimit-above 100 \-j REJECT
  260. .SS connmark
  261. This module matches the netfilter mark field associated with a connection
  262. (which can be set using the \fBCONNMARK\fP target below).
  263. .TP
  264. [\fB!\fP] \fB\-\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  265. Matches packets in connections with the given mark value (if a mask is
  266. specified, this is logically ANDed with the mark before the comparison).
  267. .SS conntrack
  268. This module, when combined with connection tracking, allows access to the
  269. connection tracking state for this packet/connection.
  270. .TP
  271. [\fB!\fP] \fB\-\-ctstate\fP \fIstatelist\fP
  272. \fIstatelist\fP is a comma separated list of the connection states to match.
  273. Possible states are listed below.
  274. .TP
  275. [\fB!\fP] \fB\-\-ctproto\fP \fIl4proto\fP
  276. Layer-4 protocol to match (by number or name)
  277. .TP
  278. [\fB!\fP] \fB\-\-ctorigsrc\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  279. .TP
  280. [\fB!\fP] \fB\-\-ctorigdst\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  281. .TP
  282. [\fB!\fP] \fB\-\-ctreplsrc\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  283. .TP
  284. [\fB!\fP] \fB\-\-ctrepldst\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  285. Match against original/reply source/destination address
  286. .TP
  287. [\fB!\fP] \fB\-\-ctorigsrcport\fP \fIport\fP[\fB:\fP\fIport\fP]
  288. .TP
  289. [\fB!\fP] \fB\-\-ctorigdstport\fP \fIport\fP[\fB:\fP\fIport\fP]
  290. .TP
  291. [\fB!\fP] \fB\-\-ctreplsrcport\fP \fIport\fP[\fB:\fP\fIport\fP]
  292. .TP
  293. [\fB!\fP] \fB\-\-ctrepldstport\fP \fIport\fP[\fB:\fP\fIport\fP]
  294. Match against original/reply source/destination port (TCP/UDP/etc.) or GRE key.
  295. Matching against port ranges is only supported in kernel versions above 2.6.38.
  296. .TP
  297. [\fB!\fP] \fB\-\-ctstatus\fP \fIstatelist\fP
  298. \fIstatuslist\fP is a comma separated list of the connection statuses to match.
  299. Possible statuses are listed below.
  300. .TP
  301. [\fB!\fP] \fB\-\-ctexpire\fP \fItime\fP[\fB:\fP\fItime\fP]
  302. Match remaining lifetime in seconds against given value or range of values
  303. (inclusive)
  304. .TP
  305. \fB\-\-ctdir\fP {\fBORIGINAL\fP|\fBREPLY\fP}
  306. Match packets that are flowing in the specified direction. If this flag is not
  307. specified at all, matches packets in both directions.
  308. .PP
  309. States for \fB\-\-ctstate\fP:
  310. .TP
  311. \fBINVALID\fP
  312. The packet is associated with no known connection.
  313. .TP
  314. \fBNEW\fP
  315. The packet has started a new connection, or otherwise associated
  316. with a connection which has not seen packets in both directions.
  317. .TP
  318. \fBESTABLISHED\fP
  319. The packet is associated with a connection which has seen packets
  320. in both directions.
  321. .TP
  322. \fBRELATED\fP
  323. The packet is starting a new connection, but is associated with an
  324. existing connection, such as an FTP data transfer, or an ICMP error.
  325. .TP
  326. \fBUNTRACKED\fP
  327. The packet is not tracked at all, which happens if you explicitly untrack it
  328. by using \-j CT \-\-notrack in the raw table.
  329. .TP
  330. \fBSNAT\fP
  331. A virtual state, matching if the original source address differs from the reply
  332. destination.
  333. .TP
  334. \fBDNAT\fP
  335. A virtual state, matching if the original destination differs from the reply
  336. source.
  337. .PP
  338. Statuses for \fB\-\-ctstatus\fP:
  339. .TP
  340. \fBNONE\fP
  341. None of the below.
  342. .TP
  343. \fBEXPECTED\fP
  344. This is an expected connection (i.e. a conntrack helper set it up).
  345. .TP
  346. \fBSEEN_REPLY\fP
  347. Conntrack has seen packets in both directions.
  348. .TP
  349. \fBASSURED\fP
  350. Conntrack entry should never be early-expired.
  351. .TP
  352. \fBCONFIRMED\fP
  353. Connection is confirmed: originating packet has left box.
  354. .SS cpu
  355. .TP
  356. [\fB!\fP] \fB\-\-cpu\fP \fInumber\fP
  357. Match cpu handling this packet. cpus are numbered from 0 to NR_CPUS-1
  358. Can be used in combination with RPS (Remote Packet Steering) or
  359. multiqueue NICs to spread network traffic on different queues.
  360. .PP
  361. Example:
  362. .PP
  363. iptables \-t nat \-A PREROUTING \-p tcp \-\-dport 80 \-m cpu \-\-cpu 0
  364. \-j REDIRECT \-\-to\-port 8080
  365. .PP
  366. iptables \-t nat \-A PREROUTING \-p tcp \-\-dport 80 \-m cpu \-\-cpu 1
  367. \-j REDIRECT \-\-to\-port 8081
  368. .PP
  369. Available since Linux 2.6.36.
  370. .SS dccp
  371. .TP
  372. [\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP]
  373. .TP
  374. [\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP]
  375. .TP
  376. [\fB!\fP] \fB\-\-dccp\-types\fP \fImask\fP
  377. Match when the DCCP packet type is one of 'mask'. 'mask' is a comma-separated
  378. list of packet types. Packet types are:
  379. .BR "REQUEST RESPONSE DATA ACK DATAACK CLOSEREQ CLOSE RESET SYNC SYNCACK INVALID" .
  380. .TP
  381. [\fB!\fP] \fB\-\-dccp\-option\fP \fInumber\fP
  382. Match if DCCP option set.
  383. .SS devgroup
  384. Match device group of a packets incoming/outgoing interface.
  385. .TP
  386. [\fB!\fP] \fB\-\-src\-group\fP \fIname\fP
  387. Match device group of incoming device
  388. .TP
  389. [\fB!\fP] \fB\-\-dst\-group\fP \fIname\fP
  390. Match device group of outgoing device
  391. .SS dscp
  392. This module matches the 6 bit DSCP field within the TOS field in the
  393. IP header. DSCP has superseded TOS within the IETF.
  394. .TP
  395. [\fB!\fP] \fB\-\-dscp\fP \fIvalue\fP
  396. Match against a numeric (decimal or hex) value [0-63].
  397. .TP
  398. [\fB!\fP] \fB\-\-dscp\-class\fP \fIclass\fP
  399. Match the DiffServ class. This value may be any of the
  400. BE, EF, AFxx or CSx classes. It will then be converted
  401. into its according numeric value.
  402. .SS dst (IPv6-specific)
  403. This module matches the parameters in Destination Options header
  404. .TP
  405. [\fB!\fP] \fB\-\-dst\-len\fP \fIlength\fP
  406. Total length of this header in octets.
  407. .TP
  408. \fB\-\-dst\-opts\fP \fItype\fP[\fB:\fP\fIlength\fP][\fB,\fP\fItype\fP[\fB:\fP\fIlength\fP]...]
  409. numeric type of option and the length of the option data in octets.
  410. .SS ecn
  411. This allows you to match the ECN bits of the IPv4/IPv6 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168
  412. .TP
  413. [\fB!\fP] \fB\-\-ecn\-tcp\-cwr\fP
  414. This matches if the TCP ECN CWR (Congestion Window Received) bit is set.
  415. .TP
  416. [\fB!\fP] \fB\-\-ecn\-tcp\-ece\fP
  417. This matches if the TCP ECN ECE (ECN Echo) bit is set.
  418. .TP
  419. [\fB!\fP] \fB\-\-ecn\-ip\-ect\fP \fInum\fP
  420. This matches a particular IPv4/IPv6 ECT (ECN-Capable Transport). You have to specify
  421. a number between `0' and `3'.
  422. .SS esp
  423. This module matches the SPIs in ESP header of IPsec packets.
  424. .TP
  425. [\fB!\fP] \fB\-\-espspi\fP \fIspi\fP[\fB:\fP\fIspi\fP]
  426. .SS eui64 (IPv6-specific)
  427. This module matches the EUI-64 part of a stateless autoconfigured IPv6 address.
  428. It compares the EUI-64 derived from the source MAC address in Ethernet frame
  429. with the lower 64 bits of the IPv6 source address. But "Universal/Local"
  430. bit is not compared. This module doesn't match other link layer frame, and
  431. is only valid in the
  432. .BR PREROUTING ,
  433. .BR INPUT
  434. and
  435. .BR FORWARD
  436. chains.
  437. .SS frag (IPv6-specific)
  438. This module matches the parameters in Fragment header.
  439. .TP
  440. [\fB!\fP] \fB\-\-fragid\fP \fIid\fP[\fB:\fP\fIid\fP]
  441. Matches the given Identification or range of it.
  442. .TP
  443. [\fB!\fP] \fB\-\-fraglen\fP \fIlength\fP
  444. This option cannot be used with kernel version 2.6.10 or later. The length of
  445. Fragment header is static and this option doesn't make sense.
  446. .TP
  447. \fB\-\-fragres\fP
  448. Matches if the reserved fields are filled with zero.
  449. .TP
  450. \fB\-\-fragfirst\fP
  451. Matches on the first fragment.
  452. .TP
  453. \fB\-\-fragmore\fP
  454. Matches if there are more fragments.
  455. .TP
  456. \fB\-\-fraglast\fP
  457. Matches if this is the last fragment.
  458. .SS hashlimit
  459. \fBhashlimit\fP uses hash buckets to express a rate limiting match (like the
  460. \fBlimit\fP match) for a group of connections using a \fBsingle\fP iptables
  461. rule. Grouping can be done per-hostgroup (source and/or destination address)
  462. and/or per-port. It gives you the ability to express "\fIN\fP packets per time
  463. quantum per group" or "\fIN\fP bytes per seconds" (see below for some examples).
  464. .PP
  465. A hash limit option (\fB\-\-hashlimit\-upto\fP, \fB\-\-hashlimit\-above\fP) and
  466. \fB\-\-hashlimit\-name\fP are required.
  467. .TP
  468. \fB\-\-hashlimit\-upto\fP \fIamount\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP]
  469. Match if the rate is below or equal to \fIamount\fP/quantum. It is specified either as
  470. a number, with an optional time quantum suffix (the default is 3/hour), or as
  471. \fIamount\fPb/second (number of bytes per second).
  472. .TP
  473. \fB\-\-hashlimit\-above\fP \fIamount\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP]
  474. Match if the rate is above \fIamount\fP/quantum.
  475. .TP
  476. \fB\-\-hashlimit\-burst\fP \fIamount\fP
  477. Maximum initial number of packets to match: this number gets recharged by one
  478. every time the limit specified above is not reached, up to this number; the
  479. default is 5. When byte-based rate matching is requested, this option specifies
  480. the amount of bytes that can exceed the given rate. This option should be used
  481. with caution -- if the entry expires, the burst value is reset too.
  482. .TP
  483. \fB\-\-hashlimit\-mode\fP {\fBsrcip\fP|\fBsrcport\fP|\fBdstip\fP|\fBdstport\fP}\fB,\fP...
  484. A comma-separated list of objects to take into consideration. If no
  485. \-\-hashlimit\-mode option is given, hashlimit acts like limit, but at the
  486. expensive of doing the hash housekeeping.
  487. .TP
  488. \fB\-\-hashlimit\-srcmask\fP \fIprefix\fP
  489. When \-\-hashlimit\-mode srcip is used, all source addresses encountered will be
  490. grouped according to the given prefix length and the so-created subnet will be
  491. subject to hashlimit. \fIprefix\fP must be between (inclusive) 0 and 32. Note
  492. that \-\-hashlimit\-srcmask 0 is basically doing the same thing as not specifying
  493. srcip for \-\-hashlimit\-mode, but is technically more expensive.
  494. .TP
  495. \fB\-\-hashlimit\-dstmask\fP \fIprefix\fP
  496. Like \-\-hashlimit\-srcmask, but for destination addresses.
  497. .TP
  498. \fB\-\-hashlimit\-name\fP \fIfoo\fP
  499. The name for the /proc/net/ipt_hashlimit/foo entry.
  500. .TP
  501. \fB\-\-hashlimit\-htable\-size\fP \fIbuckets\fP
  502. The number of buckets of the hash table
  503. .TP
  504. \fB\-\-hashlimit\-htable\-max\fP \fIentries\fP
  505. Maximum entries in the hash.
  506. .TP
  507. \fB\-\-hashlimit\-htable\-expire\fP \fImsec\fP
  508. After how many milliseconds do hash entries expire.
  509. .TP
  510. \fB\-\-hashlimit\-htable\-gcinterval\fP \fImsec\fP
  511. How many milliseconds between garbage collection intervals.
  512. .PP
  513. Examples:
  514. .TP
  515. matching on source host
  516. "1000 packets per second for every host in 192.168.0.0/16" =>
  517. \-s 192.168.0.0/16 \-\-hashlimit\-mode srcip \-\-hashlimit\-upto 1000/sec
  518. .TP
  519. matching on source port
  520. "100 packets per second for every service of 192.168.1.1" =>
  521. \-s 192.168.1.1 \-\-hashlimit\-mode srcport \-\-hashlimit\-upto 100/sec
  522. .TP
  523. matching on subnet
  524. "10000 packets per minute for every /28 subnet (groups of 8 addresses)
  525. in 10.0.0.0/8" =>
  526. \-s 10.0.0.8 \-\-hashlimit\-mask 28 \-\-hashlimit\-upto 10000/min
  527. .TP
  528. matching bytes per second
  529. "flows exceeding 512kbyte/s" =>
  530. \-\-hashlimit-mode srcip,dstip,srcport,dstport \-\-hashlimit\-above 512kb/s
  531. .TP
  532. matching bytes per second
  533. "hosts that exceed 512kbyte/s, but permit up to 1Megabytes without matching"
  534. \-\-hashlimit-mode dstip \-\-hashlimit\-above 512kb/s \-\-hashlimit-burst 1mb
  535. .SS hbh (IPv6-specific)
  536. This module matches the parameters in Hop-by-Hop Options header
  537. .TP
  538. [\fB!\fP] \fB\-\-hbh\-len\fP \fIlength\fP
  539. Total length of this header in octets.
  540. .TP
  541. \fB\-\-hbh\-opts\fP \fItype\fP[\fB:\fP\fIlength\fP][\fB,\fP\fItype\fP[\fB:\fP\fIlength\fP]...]
  542. numeric type of option and the length of the option data in octets.
  543. .SS helper
  544. This module matches packets related to a specific conntrack-helper.
  545. .TP
  546. [\fB!\fP] \fB\-\-helper\fP \fIstring\fP
  547. Matches packets related to the specified conntrack-helper.
  548. .RS
  549. .PP
  550. string can be "ftp" for packets related to a ftp-session on default port.
  551. For other ports append \-portnr to the value, ie. "ftp\-2121".
  552. .PP
  553. Same rules apply for other conntrack-helpers.
  554. .RE
  555. .SS hl (IPv6-specific)
  556. This module matches the Hop Limit field in the IPv6 header.
  557. .TP
  558. [\fB!\fP] \fB\-\-hl\-eq\fP \fIvalue\fP
  559. Matches if Hop Limit equals \fIvalue\fP.
  560. .TP
  561. \fB\-\-hl\-lt\fP \fIvalue\fP
  562. Matches if Hop Limit is less than \fIvalue\fP.
  563. .TP
  564. \fB\-\-hl\-gt\fP \fIvalue\fP
  565. Matches if Hop Limit is greater than \fIvalue\fP.
  566. .SS icmp (IPv4-specific)
  567. This extension can be used if `\-\-protocol icmp' is specified. It
  568. provides the following option:
  569. .TP
  570. [\fB!\fP] \fB\-\-icmp\-type\fP {\fItype\fP[\fB/\fP\fIcode\fP]|\fItypename\fP}
  571. This allows specification of the ICMP type, which can be a numeric
  572. ICMP type, type/code pair, or one of the ICMP type names shown by the command
  573. .nf
  574. iptables \-p icmp \-h
  575. .fi
  576. .SS icmp6 (IPv6-specific)
  577. This extension can be used if `\-\-protocol ipv6\-icmp' or `\-\-protocol icmpv6' is
  578. specified. It provides the following option:
  579. .TP
  580. [\fB!\fP] \fB\-\-icmpv6\-type\fP \fItype\fP[\fB/\fP\fIcode\fP]|\fItypename\fP
  581. This allows specification of the ICMPv6 type, which can be a numeric
  582. ICMPv6
  583. .IR type ,
  584. .IR type
  585. and
  586. .IR code ,
  587. or one of the ICMPv6 type names shown by the command
  588. .nf
  589. ip6tables \-p ipv6\-icmp \-h
  590. .fi
  591. .SS iprange
  592. This matches on a given arbitrary range of IP addresses.
  593. .TP
  594. [\fB!\fP] \fB\-\-src\-range\fP \fIfrom\fP[\fB\-\fP\fIto\fP]
  595. Match source IP in the specified range.
  596. .TP
  597. [\fB!\fP] \fB\-\-dst\-range\fP \fIfrom\fP[\fB\-\fP\fIto\fP]
  598. Match destination IP in the specified range.
  599. .SS ipv6header (IPv6-specific)
  600. This module matches IPv6 extension headers and/or upper layer header.
  601. .TP
  602. \fB\-\-soft\fP
  603. Matches if the packet includes \fBany\fP of the headers specified with
  604. \fB\-\-header\fP.
  605. .TP
  606. [\fB!\fP] \fB\-\-header\fP \fIheader\fP[\fB,\fP\fIheader\fP...]
  607. Matches the packet which EXACTLY includes all specified headers. The headers
  608. encapsulated with ESP header are out of scope.
  609. Possible \fIheader\fP types can be:
  610. .TP
  611. \fBhop\fP|\fBhop\-by\-hop\fP
  612. Hop-by-Hop Options header
  613. .TP
  614. \fBdst\fP
  615. Destination Options header
  616. .TP
  617. \fBroute\fP
  618. Routing header
  619. .TP
  620. \fBfrag\fP
  621. Fragment header
  622. .TP
  623. \fBauth\fP
  624. Authentication header
  625. .TP
  626. \fBesp\fP
  627. Encapsulating Security Payload header
  628. .TP
  629. \fBnone\fP
  630. No Next header which matches 59 in the 'Next Header field' of IPv6 header or
  631. any IPv6 extension headers
  632. .TP
  633. \fBproto\fP
  634. which matches any upper layer protocol header. A protocol name from
  635. /etc/protocols and numeric value also allowed. The number 255 is equivalent to
  636. \fBproto\fP.
  637. .SS ipvs
  638. Match IPVS connection properties.
  639. .TP
  640. [\fB!\fP] \fB\-\-ipvs\fP
  641. packet belongs to an IPVS connection
  642. .TP
  643. Any of the following options implies \-\-ipvs (even negated)
  644. .TP
  645. [\fB!\fP] \fB\-\-vproto\fP \fIprotocol\fP
  646. VIP protocol to match; by number or name, e.g. "tcp"
  647. .TP
  648. [\fB!\fP] \fB\-\-vaddr\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  649. VIP address to match
  650. .TP
  651. [\fB!\fP] \fB\-\-vport\fP \fIport\fP
  652. VIP port to match; by number or name, e.g. "http"
  653. .TP
  654. \fB\-\-vdir\fP {\fBORIGINAL\fP|\fBREPLY\fP}
  655. flow direction of packet
  656. .TP
  657. [\fB!\fP] \fB\-\-vmethod\fP {\fBGATE\fP|\fBIPIP\fP|\fBMASQ\fP}
  658. IPVS forwarding method used
  659. .TP
  660. [\fB!\fP] \fB\-\-vportctl\fP \fIport\fP
  661. VIP port of the controlling connection to match, e.g. 21 for FTP
  662. .SS length
  663. This module matches the length of the layer-3 payload (e.g. layer-4 packet)
  664. of a packet against a specific value
  665. or range of values.
  666. .TP
  667. [\fB!\fP] \fB\-\-length\fP \fIlength\fP[\fB:\fP\fIlength\fP]
  668. .SS limit
  669. This module matches at a limited rate using a token bucket filter.
  670. A rule using this extension will match until this limit is reached.
  671. It can be used in combination with the
  672. .B LOG
  673. target to give limited logging, for example.
  674. .PP
  675. xt_limit has no negation support - you will have to use \-m hashlimit !
  676. \-\-hashlimit \fIrate\fP in this case whilst omitting \-\-hashlimit\-mode.
  677. .TP
  678. \fB\-\-limit\fP \fIrate\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP]
  679. Maximum average matching rate: specified as a number, with an optional
  680. `/second', `/minute', `/hour', or `/day' suffix; the default is
  681. 3/hour.
  682. .TP
  683. \fB\-\-limit\-burst\fP \fInumber\fP
  684. Maximum initial number of packets to match: this number gets
  685. recharged by one every time the limit specified above is not reached,
  686. up to this number; the default is 5.
  687. .SS mac
  688. .TP
  689. [\fB!\fP] \fB\-\-mac\-source\fP \fIaddress\fP
  690. Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
  691. Note that this only makes sense for packets coming from an Ethernet device
  692. and entering the
  693. .BR PREROUTING ,
  694. .B FORWARD
  695. or
  696. .B INPUT
  697. chains.
  698. .SS mark
  699. This module matches the netfilter mark field associated with a packet
  700. (which can be set using the
  701. .B MARK
  702. target below).
  703. .TP
  704. [\fB!\fP] \fB\-\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  705. Matches packets with the given unsigned mark value (if a \fImask\fP is
  706. specified, this is logically ANDed with the \fImask\fP before the
  707. comparison).
  708. .SS mh (IPv6-specific)
  709. This extension is loaded if `\-\-protocol ipv6\-mh' or `\-\-protocol mh' is
  710. specified. It provides the following option:
  711. .TP
  712. [\fB!\fP] \fB\-\-mh\-type\fP \fItype\fP[\fB:\fP\fItype\fP]
  713. This allows specification of the Mobility Header(MH) type, which can be
  714. a numeric MH
  715. .IR type ,
  716. .IR type
  717. or one of the MH type names shown by the command
  718. .nf
  719. ip6tables \-p ipv6\-mh \-h
  720. .fi
  721. .SS multiport
  722. This module matches a set of source or destination ports. Up to 15
  723. ports can be specified. A port range (port:port) counts as two
  724. ports. It can only be used in conjunction with
  725. \fB\-p tcp\fP
  726. or
  727. \fB\-p udp\fP.
  728. .TP
  729. [\fB!\fP] \fB\-\-source\-ports\fP,\fB\-\-sports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]...
  730. Match if the source port is one of the given ports. The flag
  731. \fB\-\-sports\fP
  732. is a convenient alias for this option. Multiple ports or port ranges are
  733. separated using a comma, and a port range is specified using a colon.
  734. \fB53,1024:65535\fP would therefore match ports 53 and all from 1024 through
  735. 65535.
  736. .TP
  737. [\fB!\fP] \fB\-\-destination\-ports\fP,\fB\-\-dports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]...
  738. Match if the destination port is one of the given ports. The flag
  739. \fB\-\-dports\fP
  740. is a convenient alias for this option.
  741. .TP
  742. [\fB!\fP] \fB\-\-ports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]...
  743. Match if either the source or destination ports are equal to one of
  744. the given ports.
  745. .SS nfacct
  746. The nfacct match provides the extended accounting infrastructure for iptables.
  747. You have to use this match together with the standalone user-space utility
  748. .B nfacct(8)
  749. .PP
  750. The only option available for this match is the following:
  751. .TP
  752. \fB\-\-nfacct\-name\fP \fIname\fP
  753. This allows you to specify the existing object name that will be use for
  754. accounting the traffic that this rule-set is matching.
  755. .PP
  756. To use this extension, you have to create an accounting object:
  757. .IP
  758. nfacct add http\-traffic
  759. .PP
  760. Then, you have to attach it to the accounting object via iptables:
  761. .IP
  762. iptables \-I INPUT \-p tcp \-\-sport 80 \-m nfacct \-\-nfacct\-name http\-traffic
  763. .IP
  764. iptables \-I OUTPUT \-p tcp \-\-dport 80 \-m nfacct \-\-nfacct\-name http\-traffic
  765. .PP
  766. Then, you can check for the amount of traffic that the rules match:
  767. .IP
  768. nfacct get http\-traffic
  769. .IP
  770. { pkts = 00000000000000000156, bytes = 00000000000000151786 } = http-traffic;
  771. .PP
  772. You can obtain
  773. .B nfacct(8)
  774. from http://www.netfilter.org or, alternatively, from the git.netfilter.org
  775. repository.
  776. .SS osf
  777. The osf module does passive operating system fingerprinting. This modules
  778. compares some data (Window Size, MSS, options and their order, TTL, DF,
  779. and others) from packets with the SYN bit set.
  780. .TP
  781. [\fB!\fP] \fB\-\-genre\fP \fIstring\fP
  782. Match an operating system genre by using a passive fingerprinting.
  783. .TP
  784. \fB\-\-ttl\fP \fIlevel\fP
  785. Do additional TTL checks on the packet to determine the operating system.
  786. \fIlevel\fP can be one of the following values:
  787. .IP \(bu 4
  788. 0 - True IP address and fingerprint TTL comparison. This generally works for
  789. LANs.
  790. .IP \(bu 4
  791. 1 - Check if the IP header's TTL is less than the fingerprint one. Works for
  792. globally-routable addresses.
  793. .IP \(bu 4
  794. 2 - Do not compare the TTL at all.
  795. .TP
  796. \fB\-\-log\fP \fIlevel\fP
  797. Log determined genres into dmesg even if they do not match the desired one.
  798. \fIlevel\fP can be one of the following values:
  799. .IP \(bu 4
  800. 0 - Log all matched or unknown signatures
  801. .IP \(bu 4
  802. 1 - Log only the first one
  803. .IP \(bu 4
  804. 2 - Log all known matched signatures
  805. .PP
  806. You may find something like this in syslog:
  807. .PP
  808. Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 ->
  809. 11.22.33.44:139 hops=3 Linux [2.5-2.6:] : 1.2.3.4:42624 -> 1.2.3.5:22 hops=4
  810. .PP
  811. OS fingerprints are loadable using the \fBnfnl_osf\fP program. To load
  812. fingerprints from a file, use:
  813. .PP
  814. \fBnfnl_osf -f /usr/share/xtables/pf.os\fP
  815. .PP
  816. To remove them again,
  817. .PP
  818. \fBnfnl_osf -f /usr/share/xtables/pf.os -d\fP
  819. .PP
  820. The fingerprint database can be downlaoded from
  821. http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os .
  822. .SS owner
  823. This module attempts to match various characteristics of the packet creator,
  824. for locally generated packets. This match is only valid in the OUTPUT and
  825. POSTROUTING chains. Forwarded packets do not have any socket associated with
  826. them. Packets from kernel threads do have a socket, but usually no owner.
  827. .TP
  828. [\fB!\fP] \fB\-\-uid\-owner\fP \fIusername\fP
  829. .TP
  830. [\fB!\fP] \fB\-\-uid\-owner\fP \fIuserid\fP[\fB\-\fP\fIuserid\fP]
  831. Matches if the packet socket's file structure (if it has one) is owned by the
  832. given user. You may also specify a numerical UID, or an UID range.
  833. .TP
  834. [\fB!\fP] \fB\-\-gid\-owner\fP \fIgroupname\fP
  835. .TP
  836. [\fB!\fP] \fB\-\-gid\-owner\fP \fIgroupid\fP[\fB\-\fP\fIgroupid\fP]
  837. Matches if the packet socket's file structure is owned by the given group.
  838. You may also specify a numerical GID, or a GID range.
  839. .TP
  840. [\fB!\fP] \fB\-\-socket\-exists\fP
  841. Matches if the packet is associated with a socket.
  842. .SS physdev
  843. This module matches on the bridge port input and output devices enslaved
  844. to a bridge device. This module is a part of the infrastructure that enables
  845. a transparent bridging IP firewall and is only useful for kernel versions
  846. above version 2.5.44.
  847. .TP
  848. [\fB!\fP] \fB\-\-physdev\-in\fP \fIname\fP
  849. Name of a bridge port via which a packet is received (only for
  850. packets entering the
  851. .BR INPUT ,
  852. .B FORWARD
  853. and
  854. .B PREROUTING
  855. chains). If the interface name ends in a "+", then any
  856. interface which begins with this name will match. If the packet didn't arrive
  857. through a bridge device, this packet won't match this option, unless '!' is used.
  858. .TP
  859. [\fB!\fP] \fB\-\-physdev\-out\fP \fIname\fP
  860. Name of a bridge port via which a packet is going to be sent (for packets
  861. entering the
  862. .BR FORWARD ,
  863. .B OUTPUT
  864. and
  865. .B POSTROUTING
  866. chains). If the interface name ends in a "+", then any
  867. interface which begins with this name will match. Note that in the
  868. .BR nat " and " mangle
  869. .B OUTPUT
  870. chains one cannot match on the bridge output port, however one can in the
  871. .B "filter OUTPUT"
  872. chain. If the packet won't leave by a bridge device or if it is yet unknown what
  873. the output device will be, then the packet won't match this option,
  874. unless '!' is used.
  875. .TP
  876. [\fB!\fP] \fB\-\-physdev\-is\-in\fP
  877. Matches if the packet has entered through a bridge interface.
  878. .TP
  879. [\fB!\fP] \fB\-\-physdev\-is\-out\fP
  880. Matches if the packet will leave through a bridge interface.
  881. .TP
  882. [\fB!\fP] \fB\-\-physdev\-is\-bridged\fP
  883. Matches if the packet is being bridged and therefore is not being routed.
  884. This is only useful in the FORWARD and POSTROUTING chains.
  885. .SS pkttype
  886. This module matches the link-layer packet type.
  887. .TP
  888. [\fB!\fP] \fB\-\-pkt\-type\fP {\fBunicast\fP|\fBbroadcast\fP|\fBmulticast\fP}
  889. .SS policy
  890. This modules matches the policy used by IPsec for handling a packet.
  891. .TP
  892. \fB\-\-dir\fP {\fBin\fP|\fBout\fP}
  893. Used to select whether to match the policy used for decapsulation or the
  894. policy that will be used for encapsulation.
  895. .B in
  896. is valid in the
  897. .B PREROUTING, INPUT and FORWARD
  898. chains,
  899. .B out
  900. is valid in the
  901. .B POSTROUTING, OUTPUT and FORWARD
  902. chains.
  903. .TP
  904. \fB\-\-pol\fP {\fBnone\fP|\fBipsec\fP}
  905. Matches if the packet is subject to IPsec processing. \fB\-\-pol none\fP
  906. cannot be combined with \fB\-\-strict\fP.
  907. .TP
  908. \fB\-\-strict\fP
  909. Selects whether to match the exact policy or match if any rule of
  910. the policy matches the given policy.
  911. .PP
  912. For each policy element that is to be described, one can use one or more of
  913. the following options. When \fB\-\-strict\fP is in effect, at least one must be
  914. used per element.
  915. .TP
  916. [\fB!\fP] \fB\-\-reqid\fP \fIid\fP
  917. Matches the reqid of the policy rule. The reqid can be specified with
  918. .B setkey(8)
  919. using
  920. .B unique:id
  921. as level.
  922. .TP
  923. [\fB!\fP] \fB\-\-spi\fP \fIspi\fP
  924. Matches the SPI of the SA.
  925. .TP
  926. [\fB!\fP] \fB\-\-proto\fP {\fBah\fP|\fBesp\fP|\fBipcomp\fP}
  927. Matches the encapsulation protocol.
  928. .TP
  929. [\fB!\fP] \fB\-\-mode\fP {\fBtunnel\fP|\fBtransport\fP}
  930. Matches the encapsulation mode.
  931. .TP
  932. [\fB!\fP] \fB\-\-tunnel\-src\fP \fIaddr\fP[\fB/\fP\fImask\fP]
  933. Matches the source end-point address of a tunnel mode SA.
  934. Only valid with \fB\-\-mode tunnel\fP.
  935. .TP
  936. [\fB!\fP] \fB\-\-tunnel\-dst\fP \fIaddr\fP[\fB/\fP\fImask\fP]
  937. Matches the destination end-point address of a tunnel mode SA.
  938. Only valid with \fB\-\-mode tunnel\fP.
  939. .TP
  940. \fB\-\-next\fP
  941. Start the next element in the policy specification. Can only be used with
  942. \fB\-\-strict\fP.
  943. .SS quota
  944. Implements network quotas by decrementing a byte counter with each
  945. packet. The condition matches until the byte counter reaches zero. Behavior
  946. is reversed with negation (i.e. the condition does not match until the
  947. byte counter reaches zero).
  948. .TP
  949. [\fB!\fP] \fB\-\-quota\fP \fIbytes\fP
  950. The quota in bytes.
  951. .SS rateest
  952. The rate estimator can match on estimated rates as collected by the RATEEST
  953. target. It supports matching on absolute bps/pps values, comparing two rate
  954. estimators and matching on the difference between two rate estimators.
  955. .PP
  956. For a better understanding of the available options, these are all possible
  957. combinations:
  958. .\" * Absolute:
  959. .IP \(bu 4
  960. \fBrateest\fP \fIoperator\fP \fBrateest-bps\fP
  961. .IP \(bu 4
  962. \fBrateest\fP \fIoperator\fP \fBrateest-pps\fP
  963. .\" * Absolute + Delta:
  964. .IP \(bu 4
  965. (\fBrateest\fP minus \fBrateest-bps1\fP) \fIoperator\fP \fBrateest-bps2\fP
  966. .IP \(bu 4
  967. (\fBrateest\fP minus \fBrateest-pps1\fP) \fIoperator\fP \fBrateest-pps2\fP
  968. .\" * Relative:
  969. .IP \(bu 4
  970. \fBrateest1\fP \fIoperator\fP \fBrateest2\fP \fBrateest-bps\fP(without rate!)
  971. .IP \(bu 4
  972. \fBrateest1\fP \fIoperator\fP \fBrateest2\fP \fBrateest-pps\fP(without rate!)
  973. .\" * Relative + Delta:
  974. .IP \(bu 4
  975. (\fBrateest1\fP minus \fBrateest-bps1\fP) \fIoperator\fP
  976. (\fBrateest2\fP minus \fBrateest-bps2\fP)
  977. .IP \(bu 4
  978. (\fBrateest1\fP minus \fBrateest-pps1\fP) \fIoperator\fP
  979. (\fBrateest2\fP minus \fBrateest-pps2\fP)
  980. .TP
  981. \fB\-\-rateest\-delta\fP
  982. For each estimator (either absolute or relative mode), calculate the difference
  983. between the estimator-determined flow rate and the static value chosen with the
  984. BPS/PPS options. If the flow rate is higher than the specified BPS/PPS, 0 will
  985. be used instead of a negative value. In other words, "max(0, rateest#_rate -
  986. rateest#_bps)" is used.
  987. .TP
  988. [\fB!\fP] \fB\-\-rateest\-lt\fP
  989. Match if rate is less than given rate/estimator.
  990. .TP
  991. [\fB!\fP] \fB\-\-rateest\-gt\fP
  992. Match if rate is greater than given rate/estimator.
  993. .TP
  994. [\fB!\fP] \fB\-\-rateest\-eq\fP
  995. Match if rate is equal to given rate/estimator.
  996. .PP
  997. In the so-called "absolute mode", only one rate estimator is used and compared
  998. against a static value, while in "relative mode", two rate estimators are
  999. compared against another.
  1000. .TP
  1001. \fB\-\-rateest\fP \fIname\fP
  1002. Name of the one rate estimator for absolute mode.
  1003. .TP
  1004. \fB\-\-rateest1\fP \fIname\fP
  1005. .TP
  1006. \fB\-\-rateest2\fP \fIname\fP
  1007. The names of the two rate estimators for relative mode.
  1008. .TP
  1009. \fB\-\-rateest\-bps\fP [\fIvalue\fP]
  1010. .TP
  1011. \fB\-\-rateest\-pps\fP [\fIvalue\fP]
  1012. .TP
  1013. \fB\-\-rateest\-bps1\fP [\fIvalue\fP]
  1014. .TP
  1015. \fB\-\-rateest\-bps2\fP [\fIvalue\fP]
  1016. .TP
  1017. \fB\-\-rateest\-pps1\fP [\fIvalue\fP]
  1018. .TP
  1019. \fB\-\-rateest\-pps2\fP [\fIvalue\fP]
  1020. Compare the estimator(s) by bytes or packets per second, and compare against
  1021. the chosen value. See the above bullet list for which option is to be used in
  1022. which case. A unit suffix may be used - available ones are: bit, [kmgt]bit,
  1023. [KMGT]ibit, Bps, [KMGT]Bps, [KMGT]iBps.
  1024. .PP
  1025. Example: This is what can be used to route outgoing data connections from an
  1026. FTP server over two lines based on the available bandwidth at the time the data
  1027. connection was started:
  1028. .PP
  1029. # Estimate outgoing rates
  1030. .PP
  1031. iptables \-t mangle \-A POSTROUTING \-o eth0 \-j RATEEST \-\-rateest\-name eth0
  1032. \-\-rateest\-interval 250ms \-\-rateest\-ewma 0.5s
  1033. .PP
  1034. iptables \-t mangle \-A POSTROUTING \-o ppp0 \-j RATEEST \-\-rateest\-name ppp0
  1035. \-\-rateest\-interval 250ms \-\-rateest\-ewma 0.5s
  1036. .PP
  1037. # Mark based on available bandwidth
  1038. .PP
  1039. iptables \-t mangle \-A balance \-m conntrack \-\-ctstate NEW \-m helper \-\-helper ftp
  1040. \-m rateest \-\-rateest\-delta \-\-rateest1 eth0 \-\-rateest\-bps1 2.5mbit \-\-rateest\-gt
  1041. \-\-rateest2 ppp0 \-\-rateest\-bps2 2mbit \-j CONNMARK \-\-set\-mark 1
  1042. .PP
  1043. iptables \-t mangle \-A balance \-m conntrack \-\-ctstate NEW \-m helper \-\-helper ftp
  1044. \-m rateest \-\-rateest\-delta \-\-rateest1 ppp0 \-\-rateest\-bps1 2mbit \-\-rateest\-gt
  1045. \-\-rateest2 eth0 \-\-rateest\-bps2 2.5mbit \-j CONNMARK \-\-set\-mark 2
  1046. .PP
  1047. iptables \-t mangle \-A balance \-j CONNMARK \-\-restore\-mark
  1048. .SS realm (IPv4-specific)
  1049. This matches the routing realm. Routing realms are used in complex routing
  1050. setups involving dynamic routing protocols like BGP.
  1051. .TP
  1052. [\fB!\fP] \fB\-\-realm\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  1053. Matches a given realm number (and optionally mask). If not a number, value
  1054. can be a named realm from /etc/iproute2/rt_realms (mask can not be used in
  1055. that case).
  1056. .SS recent
  1057. Allows you to dynamically create a list of IP addresses and then match against
  1058. that list in a few different ways.
  1059. .PP
  1060. For example, you can create a "badguy" list out of people attempting to connect
  1061. to port 139 on your firewall and then DROP all future packets from them without
  1062. considering them.
  1063. .PP
  1064. \fB\-\-set\fP, \fB\-\-rcheck\fP, \fB\-\-update\fP and \fB\-\-remove\fP are
  1065. mutually exclusive.
  1066. .TP
  1067. \fB\-\-name\fP \fIname\fP
  1068. Specify the list to use for the commands. If no name is given then
  1069. \fBDEFAULT\fP will be used.
  1070. .TP
  1071. [\fB!\fP] \fB\-\-set\fP
  1072. This will add the source address of the packet to the list. If the source
  1073. address is already in the list, this will update the existing entry. This will
  1074. always return success (or failure if \fB!\fP is passed in).
  1075. .TP
  1076. \fB\-\-rsource\fP
  1077. Match/save the source address of each packet in the recent list table. This
  1078. is the default.
  1079. .TP
  1080. \fB\-\-rdest\fP
  1081. Match/save the destination address of each packet in the recent list table.
  1082. .TP
  1083. \fB\-\-mask\fPnetmask
  1084. Netmask that will be applied to this recent list.
  1085. .TP
  1086. [\fB!\fP] \fB\-\-rcheck\fP
  1087. Check if the source address of the packet is currently in the list.
  1088. .TP
  1089. [\fB!\fP] \fB\-\-update\fP
  1090. Like \fB\-\-rcheck\fP, except it will update the "last seen" timestamp if it
  1091. matches.
  1092. .TP
  1093. [\fB!\fP] \fB\-\-remove\fP
  1094. Check if the source address of the packet is currently in the list and if so
  1095. that address will be removed from the list and the rule will return true. If
  1096. the address is not found, false is returned.
  1097. .TP
  1098. \fB\-\-seconds\fP \fIseconds\fP
  1099. This option must be used in conjunction with one of \fB\-\-rcheck\fP or
  1100. \fB\-\-update\fP. When used, this will narrow the match to only happen when the
  1101. address is in the list and was seen within the last given number of seconds.
  1102. .TP
  1103. \fB\-\-reap\fP
  1104. This option can only be used in conjunction with \fB\-\-seconds\fP.
  1105. When used, this will cause entries older than the last given number of seconds
  1106. to be purged.
  1107. .TP
  1108. \fB\-\-hitcount\fP \fIhits\fP
  1109. This option must be used in conjunction with one of \fB\-\-rcheck\fP or
  1110. \fB\-\-update\fP. When used, this will narrow the match to only happen when the
  1111. address is in the list and packets had been received greater than or equal to
  1112. the given value. This option may be used along with \fB\-\-seconds\fP to create
  1113. an even narrower match requiring a certain number of hits within a specific
  1114. time frame. The maximum value for the hitcount parameter is given by the
  1115. "ip_pkt_list_tot" parameter of the xt_recent kernel module. Exceeding this
  1116. value on the command line will cause the rule to be rejected.
  1117. .TP
  1118. \fB\-\-rttl\fP
  1119. This option may only be used in conjunction with one of \fB\-\-rcheck\fP or
  1120. \fB\-\-update\fP. When used, this will narrow the match to only happen when the
  1121. address is in the list and the TTL of the current packet matches that of the
  1122. packet which hit the \fB\-\-set\fP rule. This may be useful if you have problems
  1123. with people faking their source address in order to DoS you via this module by
  1124. disallowing others access to your site by sending bogus packets to you.
  1125. .PP
  1126. Examples:
  1127. .IP
  1128. iptables \-A FORWARD \-m recent \-\-name badguy \-\-rcheck \-\-seconds 60 \-j DROP
  1129. .IP
  1130. iptables \-A FORWARD \-p tcp \-i eth0 \-\-dport 139 \-m recent \-\-name badguy \-\-set \-j DROP
  1131. .PP
  1132. Steve's ipt_recent website (http://snowman.net/projects/ipt_recent/) also has
  1133. some examples of usage.
  1134. .PP
  1135. \fB/proc/net/xt_recent/*\fP are the current lists of addresses and information
  1136. about each entry of each list.
  1137. .PP
  1138. Each file in \fB/proc/net/xt_recent/\fP can be read from to see the current
  1139. list or written two using the following commands to modify the list:
  1140. .TP
  1141. \fBecho +\fP\fIaddr\fP\fB >/proc/net/xt_recent/DEFAULT\fP
  1142. to add \fIaddr\fP to the DEFAULT list
  1143. .TP
  1144. \fBecho \-\fP\fIaddr\fP\fB >/proc/net/xt_recent/DEFAULT\fP
  1145. to remove \fIaddr\fP from the DEFAULT list
  1146. .TP
  1147. \fBecho / >/proc/net/xt_recent/DEFAULT\fP
  1148. to flush the DEFAULT list (remove all entries).
  1149. .PP
  1150. The module itself accepts parameters, defaults shown:
  1151. .TP
  1152. \fBip_list_tot\fP=\fI100\fP
  1153. Number of addresses remembered per table.
  1154. .TP
  1155. \fBip_pkt_list_tot\fP=\fI20\fP
  1156. Number of packets per address remembered.
  1157. .TP
  1158. \fBip_list_hash_size\fP=\fI0\fP
  1159. Hash table size. 0 means to calculate it based on ip_list_tot, default: 512.
  1160. .TP
  1161. \fBip_list_perms\fP=\fI0644\fP
  1162. Permissions for /proc/net/xt_recent/* files.
  1163. .TP
  1164. \fBip_list_uid\fP=\fI0\fP
  1165. Numerical UID for ownership of /proc/net/xt_recent/* files.
  1166. .TP
  1167. \fBip_list_gid\fP=\fI0\fP
  1168. Numerical GID for ownership of /proc/net/xt_recent/* files.
  1169. .SS rpfilter
  1170. Performs a reverse path filter test on a packet.
  1171. If a reply to the packet would be sent via the same interface
  1172. that the packet arrived on, the packet will match.
  1173. Note that, unlike the in-kernel rp_filter, packets protected
  1174. by IPSec are not treated specially. Combine this match with
  1175. the policy match if you want this.
  1176. Also, packets arriving via the loopback interface are always permitted.
  1177. This match can only be used in the PREROUTING chain of the raw or mangle table.
  1178. .TP
  1179. \fB\-\-loose\fP
  1180. Used to specifiy that the reverse path filter test should match
  1181. even if the selected output device is not the expected one.
  1182. .TP
  1183. \fB\-\-validmark\fP
  1184. Also use the packets' nfmark value when performing the reverse path route lookup.
  1185. .TP
  1186. \fB\-\-accept\-local\fP
  1187. This will permit packets arriving from the network with a source address that is also
  1188. assigned to the local machine.
  1189. .TP
  1190. \fB\-\-invert\fP
  1191. This will invert the sense of the match. Instead of matching packets that passed the
  1192. reverse path filter test, match those that have failed it.
  1193. .PP
  1194. Example to log and drop packets failing the reverse path filter test:
  1195. iptables \-t raw \-N RPFILTER
  1196. iptables \-t raw \-A RPFILTER \-m rpfilter \-j RETURN
  1197. iptables \-t raw \-A RPFILTER \-m limit \-\-limit 10/minute \-j NFLOG \-\-nflog\-prefix "rpfilter drop"
  1198. iptables \-t raw \-A RPFILTER \-j DROP
  1199. iptables \-t raw \-A PREROUTING \-j RPFILTER
  1200. Example to drop failed packets, without logging:
  1201. iptables \-t raw \-A RPFILTER \-m rpfilter \-\-invert \-j DROP
  1202. .SS rt (IPv6-specific)
  1203. Match on IPv6 routing header
  1204. .TP
  1205. [\fB!\fP] \fB\-\-rt\-type\fP \fItype\fP
  1206. Match the type (numeric).
  1207. .TP
  1208. [\fB!\fP] \fB\-\-rt\-segsleft\fP \fInum\fP[\fB:\fP\fInum\fP]
  1209. Match the `segments left' field (range).
  1210. .TP
  1211. [\fB!\fP] \fB\-\-rt\-len\fP \fIlength\fP
  1212. Match the length of this header.
  1213. .TP
  1214. \fB\-\-rt\-0\-res\fP
  1215. Match the reserved field, too (type=0)
  1216. .TP
  1217. \fB\-\-rt\-0\-addrs\fP \fIaddr\fP[\fB,\fP\fIaddr\fP...]
  1218. Match type=0 addresses (list).
  1219. .TP
  1220. \fB\-\-rt\-0\-not\-strict\fP
  1221. List of type=0 addresses is not a strict list.
  1222. .SS sctp
  1223. .TP
  1224. [\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1225. .TP
  1226. [\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1227. .TP
  1228. [\fB!\fP] \fB\-\-chunk\-types\fP {\fBall\fP|\fBany\fP|\fBonly\fP} \fIchunktype\fP[\fB:\fP\fIflags\fP] [...]
  1229. The flag letter in upper case indicates that the flag is to match if set,
  1230. in the lower case indicates to match if unset.
  1231. Chunk types: DATA INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE ASCONF ASCONF_ACK FORWARD_TSN
  1232. chunk type available flags
  1233. .br
  1234. DATA I U B E i u b e
  1235. .br
  1236. ABORT T t
  1237. .br
  1238. SHUTDOWN_COMPLETE T t
  1239. (lowercase means flag should be "off", uppercase means "on")
  1240. .P
  1241. Examples:
  1242. iptables \-A INPUT \-p sctp \-\-dport 80 \-j DROP
  1243. iptables \-A INPUT \-p sctp \-\-chunk\-types any DATA,INIT \-j DROP
  1244. iptables \-A INPUT \-p sctp \-\-chunk\-types any DATA:Be \-j ACCEPT
  1245. .SS set
  1246. This module matches IP sets which can be defined by ipset(8).
  1247. .TP
  1248. [\fB!\fP] \fB\-\-match\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP]...
  1249. where flags are the comma separated list of
  1250. .BR "src"
  1251. and/or
  1252. .BR "dst"
  1253. specifications and there can be no more than six of them. Hence the command
  1254. .IP
  1255. iptables \-A FORWARD \-m set \-\-match\-set test src,dst
  1256. .IP
  1257. will match packets, for which (if the set type is ipportmap) the source
  1258. address and destination port pair can be found in the specified set. If
  1259. the set type of the specified set is single dimension (for example ipmap),
  1260. then the command will match packets for which the source address can be
  1261. found in the specified set.
  1262. .TP
  1263. \fB\-\-return\-\-nomatch\fP
  1264. If the \fB\-\-return\-\-nomatch\fP option is specified and the set type
  1265. supports the \fBnomatch\fP flag, then the matching is reversed: a match
  1266. with an element flagged with \fBnomatch\fP returns \fBtrue\fP, while a
  1267. match with a plain element returns \fBfalse\fP.
  1268. .PP
  1269. The option \fB\-\-match\-set\fP can be replaced by \fB\-\-set\fP if that does
  1270. not clash with an option of other extensions.
  1271. .PP
  1272. Use of -m set requires that ipset kernel support is provided, which, for
  1273. standard kernels, is the case since Linux 2.6.39.
  1274. .SS socket
  1275. This matches if an open socket can be found by doing a socket lookup on the
  1276. packet.
  1277. .TP
  1278. \fB\-\-transparent\fP
  1279. Ignore non-transparent sockets.
  1280. .SS state
  1281. The "state" extension is a subset of the "conntrack" module.
  1282. "state" allows access to the connection tracking state for this packet.
  1283. .TP
  1284. [\fB!\fP] \fB\-\-state\fP \fIstate\fP
  1285. Where state is a comma separated list of the connection states to match. Only a
  1286. subset of the states unterstood by "conntrack" are recognized: \fBINVALID\fP,
  1287. \fBESTABLISHED\fP, \fBNEW\fP, \fBRELATED\fP or \fBUNTRACKED\fP. For their
  1288. description, see the "conntrack" heading in this manpage.
  1289. .SS statistic
  1290. This module matches packets based on some statistic condition.
  1291. It supports two distinct modes settable with the
  1292. \fB\-\-mode\fP
  1293. option.
  1294. .PP
  1295. Supported options:
  1296. .TP
  1297. \fB\-\-mode\fP \fImode\fP
  1298. Set the matching mode of the matching rule, supported modes are
  1299. .B random
  1300. and
  1301. .B nth.
  1302. .TP
  1303. [\fB!\fP] \fB\-\-probability\fP \fIp\fP
  1304. Set the probability for a packet to be randomly matched. It only works with the
  1305. \fBrandom\fP mode. \fIp\fP must be within 0.0 and 1.0. The supported
  1306. granularity is in 1/2147483648th increments.
  1307. .TP
  1308. [\fB!\fP] \fB\-\-every\fP \fIn\fP
  1309. Match one packet every nth packet. It works only with the
  1310. .B nth
  1311. mode (see also the
  1312. \fB\-\-packet\fP
  1313. option).
  1314. .TP
  1315. \fB\-\-packet\fP \fIp\fP
  1316. Set the initial counter value (0 <= p <= n\-1, default 0) for the
  1317. .B nth
  1318. mode.
  1319. .SS string
  1320. This modules matches a given string by using some pattern matching strategy. It requires a linux kernel >= 2.6.14.
  1321. .TP
  1322. \fB\-\-algo\fP {\fBbm\fP|\fBkmp\fP}
  1323. Select the pattern matching strategy. (bm = Boyer-Moore, kmp = Knuth-Pratt-Morris)
  1324. .TP
  1325. \fB\-\-from\fP \fIoffset\fP
  1326. Set the offset from which it starts looking for any matching. If not passed, default is 0.
  1327. .TP
  1328. \fB\-\-to\fP \fIoffset\fP
  1329. Set the offset up to which should be scanned. That is, byte \fIoffset\fP-1
  1330. (counting from 0) is the last one that is scanned.
  1331. If not passed, default is the packet size.
  1332. .TP
  1333. [\fB!\fP] \fB\-\-string\fP \fIpattern\fP
  1334. Matches the given pattern.
  1335. .TP
  1336. [\fB!\fP] \fB\-\-hex\-string\fP \fIpattern\fP
  1337. Matches the given pattern in hex notation.
  1338. .SS tcp
  1339. These extensions can be used if `\-\-protocol tcp' is specified. It
  1340. provides the following options:
  1341. .TP
  1342. [\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1343. Source port or port range specification. This can either be a service
  1344. name or a port number. An inclusive range can also be specified,
  1345. using the format \fIfirst\fP\fB:\fP\fIlast\fP.
  1346. If the first port is omitted, "0" is assumed; if the last is omitted,
  1347. "65535" is assumed.
  1348. If the first port is greater than the second one they will be swapped.
  1349. The flag
  1350. \fB\-\-sport\fP
  1351. is a convenient alias for this option.
  1352. .TP
  1353. [\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1354. Destination port or port range specification. The flag
  1355. \fB\-\-dport\fP
  1356. is a convenient alias for this option.
  1357. .TP
  1358. [\fB!\fP] \fB\-\-tcp\-flags\fP \fImask\fP \fIcomp\fP
  1359. Match when the TCP flags are as specified. The first argument \fImask\fP is the
  1360. flags which we should examine, written as a comma-separated list, and
  1361. the second argument \fIcomp\fP is a comma-separated list of flags which must be
  1362. set. Flags are:
  1363. .BR "SYN ACK FIN RST URG PSH ALL NONE" .
  1364. Hence the command
  1365. .nf
  1366. iptables \-A FORWARD \-p tcp \-\-tcp\-flags SYN,ACK,FIN,RST SYN
  1367. .fi
  1368. will only match packets with the SYN flag set, and the ACK, FIN and
  1369. RST flags unset.
  1370. .TP
  1371. [\fB!\fP] \fB\-\-syn\fP
  1372. Only match TCP packets with the SYN bit set and the ACK,RST and FIN bits
  1373. cleared. Such packets are used to request TCP connection initiation;
  1374. for example, blocking such packets coming in an interface will prevent
  1375. incoming TCP connections, but outgoing TCP connections will be
  1376. unaffected.
  1377. It is equivalent to \fB\-\-tcp\-flags SYN,RST,ACK,FIN SYN\fP.
  1378. If the "!" flag precedes the "\-\-syn", the sense of the
  1379. option is inverted.
  1380. .TP
  1381. [\fB!\fP] \fB\-\-tcp\-option\fP \fInumber\fP
  1382. Match if TCP option set.
  1383. .SS tcpmss
  1384. This matches the TCP MSS (maximum segment size) field of the TCP header. You can only use this on TCP SYN or SYN/ACK packets, since the MSS is only negotiated during the TCP handshake at connection startup time.
  1385. .TP
  1386. [\fB!\fP] \fB\-\-mss\fP \fIvalue\fP[\fB:\fP\fIvalue\fP]
  1387. Match a given TCP MSS value or range.
  1388. .SS time
  1389. This matches if the packet arrival time/date is within a given range. All
  1390. options are optional, but are ANDed when specified. All times are interpreted
  1391. as UTC by default.
  1392. .TP
  1393. \fB\-\-datestart\fP \fIYYYY\fP[\fB\-\fP\fIMM\fP[\fB\-\fP\fIDD\fP[\fBT\fP\fIhh\fP[\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]]]]]
  1394. .TP
  1395. \fB\-\-datestop\fP \fIYYYY\fP[\fB\-\fP\fIMM\fP[\fB\-\fP\fIDD\fP[\fBT\fP\fIhh\fP[\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]]]]]
  1396. Only match during the given time, which must be in ISO 8601 "T" notation.
  1397. The possible time range is 1970-01-01T00:00:00 to 2038-01-19T04:17:07.
  1398. .IP
  1399. If \-\-datestart or \-\-datestop are not specified, it will default to 1970-01-01
  1400. and 2038-01-19, respectively.
  1401. .TP
  1402. \fB\-\-timestart\fP \fIhh\fP\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]
  1403. .TP
  1404. \fB\-\-timestop\fP \fIhh\fP\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]
  1405. Only match during the given daytime. The possible time range is 00:00:00 to
  1406. 23:59:59. Leading zeroes are allowed (e.g. "06:03") and correctly interpreted
  1407. as base-10.
  1408. .TP
  1409. [\fB!\fP] \fB\-\-monthdays\fP \fIday\fP[\fB,\fP\fIday\fP...]
  1410. Only match on the given days of the month. Possible values are \fB1\fP
  1411. to \fB31\fP. Note that specifying \fB31\fP will of course not match
  1412. on months which do not have a 31st day; the same goes for 28- or 29-day
  1413. February.
  1414. .TP
  1415. [\fB!\fP] \fB\-\-weekdays\fP \fIday\fP[\fB,\fP\fIday\fP...]
  1416. Only match on the given weekdays. Possible values are \fBMon\fP, \fBTue\fP,
  1417. \fBWed\fP, \fBThu\fP, \fBFri\fP, \fBSat\fP, \fBSun\fP, or values from \fB1\fP
  1418. to \fB7\fP, respectively. You may also use two-character variants (\fBMo\fP,
  1419. \fBTu\fP, etc.).
  1420. .TP
  1421. \fB\-\-contiguous\fP
  1422. When \fB\-\-timestop\fP is smaller than \fB\-\-timestart\fP value, match
  1423. this as a single time period instead distinct intervals. See EXAMPLES.
  1424. .TP
  1425. \fB\-\-kerneltz\fP
  1426. Use the kernel timezone instead of UTC to determine whether a packet meets the
  1427. time regulations.
  1428. .PP
  1429. About kernel timezones: Linux keeps the system time in UTC, and always does so.
  1430. On boot, system time is initialized from a referential time source. Where this
  1431. time source has no timezone information, such as the x86 CMOS RTC, UTC will be
  1432. assumed. If the time source is however not in UTC, userspace should provide the
  1433. correct system time and timezone to the kernel once it has the information.
  1434. .PP
  1435. Local time is a feature on top of the (timezone independent) system time. Each
  1436. process has its own idea of local time, specified via the TZ environment
  1437. variable. The kernel also has its own timezone offset variable. The TZ
  1438. userspace environment variable specifies how the UTC-based system time is
  1439. displayed, e.g. when you run date(1), or what you see on your desktop clock.
  1440. The TZ string may resolve to different offsets at different dates, which is
  1441. what enables the automatic time-jumping in userspace. when DST changes. The
  1442. kernel's timezone offset variable is used when it has to convert between
  1443. non-UTC sources, such as FAT filesystems, to UTC (since the latter is what the
  1444. rest of the system uses).
  1445. .PP
  1446. The caveat with the kernel timezone is that Linux distributions may ignore to
  1447. set the kernel timezone, and instead only set the system time. Even if a
  1448. particular distribution does set the timezone at boot, it is usually does not
  1449. keep the kernel timezone offset - which is what changes on DST - up to date.
  1450. ntpd will not touch the kernel timezone, so running it will not resolve the
  1451. issue. As such, one may encounter a timezone that is always +0000, or one that
  1452. is wrong half of the time of the year. As such, \fBusing \-\-kerneltz is highly
  1453. discouraged.\fP
  1454. .PP
  1455. EXAMPLES. To match on weekends, use:
  1456. .IP
  1457. \-m time \-\-weekdays Sa,Su
  1458. .PP
  1459. Or, to match (once) on a national holiday block:
  1460. .IP
  1461. \-m time \-\-datestart 2007\-12\-24 \-\-datestop 2007\-12\-27
  1462. .PP
  1463. Since the stop time is actually inclusive, you would need the following stop
  1464. time to not match the first second of the new day:
  1465. .IP
  1466. \-m time \-\-datestart 2007\-01\-01T17:00 \-\-datestop 2007\-01\-01T23:59:59
  1467. .PP
  1468. During lunch hour:
  1469. .IP
  1470. \-m time \-\-timestart 12:30 \-\-timestop 13:30
  1471. .PP
  1472. The fourth Friday in the month:
  1473. .IP
  1474. \-m time \-\-weekdays Fr \-\-monthdays 22,23,24,25,26,27,28
  1475. .PP
  1476. (Note that this exploits a certain mathematical property. It is not possible to
  1477. say "fourth Thursday OR fourth Friday" in one rule. It is possible with
  1478. multiple rules, though.)
  1479. .PP
  1480. Matching across days might not do what is expected. For instance,
  1481. .IP
  1482. \-m time \-\-weekdays Mo \-\-timestart 23:00 \-\-timestop 01:00
  1483. Will match Monday, for one hour from midnight to 1 a.m., and then
  1484. again for another hour from 23:00 onwards. If this is unwanted, e.g. if you
  1485. would like 'match for two hours from Montay 23:00 onwards' you need to also specify
  1486. the \-\-contiguous option in the example above.
  1487. .SS tos
  1488. This module matches the 8-bit Type of Service field in the IPv4 header (i.e.
  1489. including the "Precedence" bits) or the (also 8-bit) Priority field in the IPv6
  1490. header.
  1491. .TP
  1492. [\fB!\fP] \fB\-\-tos\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  1493. Matches packets with the given TOS mark value. If a mask is specified, it is
  1494. logically ANDed with the TOS mark before the comparison.
  1495. .TP
  1496. [\fB!\fP] \fB\-\-tos\fP \fIsymbol\fP
  1497. You can specify a symbolic name when using the tos match for IPv4. The list of
  1498. recognized TOS names can be obtained by calling iptables with \fB\-m tos \-h\fP.
  1499. Note that this implies a mask of 0x3F, i.e. all but the ECN bits.
  1500. .SS ttl (IPv4-specific)
  1501. This module matches the time to live field in the IP header.
  1502. .TP
  1503. [\fB!\fP] \fB\-\-ttl\-eq\fP \fIttl\fP
  1504. Matches the given TTL value.
  1505. .TP
  1506. \fB\-\-ttl\-gt\fP \fIttl\fP
  1507. Matches if TTL is greater than the given TTL value.
  1508. .TP
  1509. \fB\-\-ttl\-lt\fP \fIttl\fP
  1510. Matches if TTL is less than the given TTL value.
  1511. .SS u32
  1512. U32 tests whether quantities of up to 4 bytes extracted from a packet have
  1513. specified values. The specification of what to extract is general enough to
  1514. find data at given offsets from tcp headers or payloads.
  1515. .TP
  1516. [\fB!\fP] \fB\-\-u32\fP \fItests\fP
  1517. The argument amounts to a program in a small language described below.
  1518. .IP
  1519. tests := location "=" value | tests "&&" location "=" value
  1520. .IP
  1521. value := range | value "," range
  1522. .IP
  1523. range := number | number ":" number
  1524. .PP
  1525. a single number, \fIn\fP, is interpreted the same as \fIn:n\fP. \fIn:m\fP is
  1526. interpreted as the range of numbers \fB>=n\fP and \fB<=m\fP.
  1527. .IP "" 4
  1528. location := number | location operator number
  1529. .IP "" 4
  1530. operator := "&" | "<<" | ">>" | "@"
  1531. .PP
  1532. The operators \fB&\fP, \fB<<\fP, \fB>>\fP and \fB&&\fP mean the same as in C.
  1533. The \fB=\fP is really a set membership operator and the value syntax describes
  1534. a set. The \fB@\fP operator is what allows moving to the next header and is
  1535. described further below.
  1536. .PP
  1537. There are currently some artificial implementation limits on the size of the
  1538. tests:
  1539. .IP " *"
  1540. no more than 10 of "\fB=\fP" (and 9 "\fB&&\fP"s) in the u32 argument
  1541. .IP " *"
  1542. no more than 10 ranges (and 9 commas) per value
  1543. .IP " *"
  1544. no more than 10 numbers (and 9 operators) per location
  1545. .PP
  1546. To describe the meaning of location, imagine the following machine that
  1547. interprets it. There are three registers:
  1548. .IP
  1549. A is of type \fBchar *\fP, initially the address of the IP header
  1550. .IP
  1551. B and C are unsigned 32 bit integers, initially zero
  1552. .PP
  1553. The instructions are:
  1554. .IP
  1555. number B = number;
  1556. .IP
  1557. C = (*(A+B)<<24) + (*(A+B+1)<<16) + (*(A+B+2)<<8) + *(A+B+3)
  1558. .IP
  1559. &number C = C & number
  1560. .IP
  1561. << number C = C << number
  1562. .IP
  1563. >> number C = C >> number
  1564. .IP
  1565. @number A = A + C; then do the instruction number
  1566. .PP
  1567. Any access of memory outside [skb\->data,skb\->end] causes the match to fail.
  1568. Otherwise the result of the computation is the final value of C.
  1569. .PP
  1570. Whitespace is allowed but not required in the tests. However, the characters
  1571. that do occur there are likely to require shell quoting, so it is a good idea
  1572. to enclose the arguments in quotes.
  1573. .PP
  1574. Example:
  1575. .IP
  1576. match IP packets with total length >= 256
  1577. .IP
  1578. The IP header contains a total length field in bytes 2-3.
  1579. .IP
  1580. \-\-u32 "\fB0 & 0xFFFF = 0x100:0xFFFF\fP"
  1581. .IP
  1582. read bytes 0-3
  1583. .IP
  1584. AND that with 0xFFFF (giving bytes 2-3), and test whether that is in the range
  1585. [0x100:0xFFFF]
  1586. .PP
  1587. Example: (more realistic, hence more complicated)
  1588. .IP
  1589. match ICMP packets with icmp type 0
  1590. .IP
  1591. First test that it is an ICMP packet, true iff byte 9 (protocol) = 1
  1592. .IP
  1593. \-\-u32 "\fB6 & 0xFF = 1 &&\fP ...
  1594. .IP
  1595. read bytes 6-9, use \fB&\fP to throw away bytes 6-8 and compare the result to
  1596. 1. Next test that it is not a fragment. (If so, it might be part of such a
  1597. packet but we cannot always tell.) N.B.: This test is generally needed if you
  1598. want to match anything beyond the IP header. The last 6 bits of byte 6 and all
  1599. of byte 7 are 0 iff this is a complete packet (not a fragment). Alternatively,
  1600. you can allow first fragments by only testing the last 5 bits of byte 6.
  1601. .IP
  1602. ... \fB4 & 0x3FFF = 0 &&\fP ...
  1603. .IP
  1604. Last test: the first byte past the IP header (the type) is 0. This is where we
  1605. have to use the @syntax. The length of the IP header (IHL) in 32 bit words is
  1606. stored in the right half of byte 0 of the IP header itself.
  1607. .IP
  1608. ... \fB0 >> 22 & 0x3C @ 0 >> 24 = 0\fP"
  1609. .IP
  1610. The first 0 means read bytes 0-3, \fB>>22\fP means shift that 22 bits to the
  1611. right. Shifting 24 bits would give the first byte, so only 22 bits is four
  1612. times that plus a few more bits. \fB&3C\fP then eliminates the two extra bits
  1613. on the right and the first four bits of the first byte. For instance, if IHL=5,
  1614. then the IP header is 20 (4 x 5) bytes long. In this case, bytes 0-1 are (in
  1615. binary) xxxx0101 yyzzzzzz, \fB>>22\fP gives the 10 bit value xxxx0101yy and
  1616. \fB&3C\fP gives 010100. \fB@\fP means to use this number as a new offset into
  1617. the packet, and read four bytes starting from there. This is the first 4 bytes
  1618. of the ICMP payload, of which byte 0 is the ICMP type. Therefore, we simply
  1619. shift the value 24 to the right to throw out all but the first byte and compare
  1620. the result with 0.
  1621. .PP
  1622. Example:
  1623. .IP
  1624. TCP payload bytes 8-12 is any of 1, 2, 5 or 8
  1625. .IP
  1626. First we test that the packet is a tcp packet (similar to ICMP).
  1627. .IP
  1628. \-\-u32 "\fB6 & 0xFF = 6 &&\fP ...
  1629. .IP
  1630. Next, test that it is not a fragment (same as above).
  1631. .IP
  1632. ... \fB0 >> 22 & 0x3C @ 12 >> 26 & 0x3C @ 8 = 1,2,5,8\fP"
  1633. .IP
  1634. \fB0>>22&3C\fP as above computes the number of bytes in the IP header. \fB@\fP
  1635. makes this the new offset into the packet, which is the start of the TCP
  1636. header. The length of the TCP header (again in 32 bit words) is the left half
  1637. of byte 12 of the TCP header. The \fB12>>26&3C\fP computes this length in bytes
  1638. (similar to the IP header before). "@" makes this the new offset, which is the
  1639. start of the TCP payload. Finally, 8 reads bytes 8-12 of the payload and
  1640. \fB=\fP checks whether the result is any of 1, 2, 5 or 8.
  1641. .SS udp
  1642. These extensions can be used if `\-\-protocol udp' is specified. It
  1643. provides the following options:
  1644. .TP
  1645. [\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1646. Source port or port range specification.
  1647. See the description of the
  1648. \fB\-\-source\-port\fP
  1649. option of the TCP extension for details.
  1650. .TP
  1651. [\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP]
  1652. Destination port or port range specification.
  1653. See the description of the
  1654. \fB\-\-destination\-port\fP
  1655. option of the TCP extension for details.
  1656. .SS unclean (IPv4-specific)
  1657. This module takes no options, but attempts to match packets which seem
  1658. malformed or unusual. This is regarded as experimental.
  1659. .SH TARGET EXTENSIONS
  1660. iptables can use extended target modules: the following are included
  1661. in the standard distribution.
  1662. .\" @TARGET@
  1663. .SS AUDIT
  1664. This target allows to create audit records for packets hitting the target.
  1665. It can be used to record accepted, dropped, and rejected packets. See
  1666. auditd(8) for additional details.
  1667. .TP
  1668. \fB\-\-type\fP {\fBaccept\fP|\fBdrop\fP|\fBreject\fP}
  1669. Set type of audit record.
  1670. .PP
  1671. Example:
  1672. .IP
  1673. iptables \-N AUDIT_DROP
  1674. .IP
  1675. iptables \-A AUDIT_DROP \-j AUDIT \-\-type drop
  1676. .IP
  1677. iptables \-A AUDIT_DROP \-j DROP
  1678. .SS CHECKSUM
  1679. This target allows to selectively work around broken/old applications.
  1680. It can only be used in the mangle table.
  1681. .TP
  1682. \fB\-\-checksum\-fill\fP
  1683. Compute and fill in the checksum in a packet that lacks a checksum.
  1684. This is particularly useful, if you need to work around old applications
  1685. such as dhcp clients, that do not work well with checksum offloads,
  1686. but don't want to disable checksum offload in your device.
  1687. .SS CLASSIFY
  1688. This module allows you to set the skb\->priority value (and thus classify the packet into a specific CBQ class).
  1689. .TP
  1690. \fB\-\-set\-class\fP \fImajor\fP\fB:\fP\fIminor\fP
  1691. Set the major and minor class value. The values are always interpreted as
  1692. hexadecimal even if no 0x prefix is given.
  1693. .SS CLUSTERIP (IPv4-specific)
  1694. This module allows you to configure a simple cluster of nodes that share
  1695. a certain IP and MAC address without an explicit load balancer in front of
  1696. them. Connections are statically distributed between the nodes in this
  1697. cluster.
  1698. .TP
  1699. \fB\-\-new\fP
  1700. Create a new ClusterIP. You always have to set this on the first rule
  1701. for a given ClusterIP.
  1702. .TP
  1703. \fB\-\-hashmode\fP \fImode\fP
  1704. Specify the hashing mode. Has to be one of
  1705. \fBsourceip\fP, \fBsourceip\-sourceport\fP, \fBsourceip\-sourceport\-destport\fP.
  1706. .TP
  1707. \fB\-\-clustermac\fP \fImac\fP
  1708. Specify the ClusterIP MAC address. Has to be a link\-layer multicast address
  1709. .TP
  1710. \fB\-\-total\-nodes\fP \fInum\fP
  1711. Number of total nodes within this cluster.
  1712. .TP
  1713. \fB\-\-local\-node\fP \fInum\fP
  1714. Local node number within this cluster.
  1715. .TP
  1716. \fB\-\-hash\-init\fP \fIrnd\fP
  1717. Specify the random seed used for hash initialization.
  1718. .SS CONNMARK
  1719. This module sets the netfilter mark value associated with a connection. The
  1720. mark is 32 bits wide.
  1721. .TP
  1722. \fB\-\-set\-xmark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  1723. Zero out the bits given by \fImask\fP and XOR \fIvalue\fP into the ctmark.
  1724. .TP
  1725. \fB\-\-save\-mark\fP [\fB\-\-nfmask\fP \fInfmask\fP] [\fB\-\-ctmask\fP \fIctmask\fP]
  1726. Copy the packet mark (nfmark) to the connection mark (ctmark) using the given
  1727. masks. The new nfmark value is determined as follows:
  1728. .IP
  1729. ctmark = (ctmark & ~ctmask) ^ (nfmark & nfmask)
  1730. .IP
  1731. i.e. \fIctmask\fP defines what bits to clear and \fInfmask\fP what bits of the
  1732. nfmark to XOR into the ctmark. \fIctmask\fP and \fInfmask\fP default to
  1733. 0xFFFFFFFF.
  1734. .TP
  1735. \fB\-\-restore\-mark\fP [\fB\-\-nfmask\fP \fInfmask\fP] [\fB\-\-ctmask\fP \fIctmask\fP]
  1736. Copy the connection mark (ctmark) to the packet mark (nfmark) using the given
  1737. masks. The new ctmark value is determined as follows:
  1738. .IP
  1739. nfmark = (nfmark & ~\fInfmask\fP) ^ (ctmark & \fIctmask\fP);
  1740. .IP
  1741. i.e. \fInfmask\fP defines what bits to clear and \fIctmask\fP what bits of the
  1742. ctmark to XOR into the nfmark. \fIctmask\fP and \fInfmask\fP default to
  1743. 0xFFFFFFFF.
  1744. .IP
  1745. \fB\-\-restore\-mark\fP is only valid in the \fBmangle\fP table.
  1746. .PP
  1747. The following mnemonics are available for \fB\-\-set\-xmark\fP:
  1748. .TP
  1749. \fB\-\-and\-mark\fP \fIbits\fP
  1750. Binary AND the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark
  1751. 0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP.)
  1752. .TP
  1753. \fB\-\-or\-mark\fP \fIbits\fP
  1754. Binary OR the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP
  1755. \fIbits\fP\fB/\fP\fIbits\fP.)
  1756. .TP
  1757. \fB\-\-xor\-mark\fP \fIbits\fP
  1758. Binary XOR the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP
  1759. \fIbits\fP\fB/0\fP.)
  1760. .TP
  1761. \fB\-\-set\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  1762. Set the connection mark. If a mask is specified then only those bits set in the
  1763. mask are modified.
  1764. .TP
  1765. \fB\-\-save\-mark\fP [\fB\-\-mask\fP \fImask\fP]
  1766. Copy the nfmark to the ctmark. If a mask is specified, only those bits are
  1767. copied.
  1768. .TP
  1769. \fB\-\-restore\-mark\fP [\fB\-\-mask\fP \fImask\fP]
  1770. Copy the ctmark to the nfmark. If a mask is specified, only those bits are
  1771. copied. This is only valid in the \fBmangle\fP table.
  1772. .SS CONNSECMARK
  1773. This module copies security markings from packets to connections
  1774. (if unlabeled), and from connections back to packets (also only
  1775. if unlabeled). Typically used in conjunction with SECMARK, it is
  1776. valid in the
  1777. .B security
  1778. table (for backwards compatibility with older kernels, it is also
  1779. valid in the
  1780. .B mangle
  1781. table).
  1782. .TP
  1783. \fB\-\-save\fP
  1784. If the packet has a security marking, copy it to the connection
  1785. if the connection is not marked.
  1786. .TP
  1787. \fB\-\-restore\fP
  1788. If the packet does not have a security marking, and the connection
  1789. does, copy the security marking from the connection to the packet.
  1790. .SS CT
  1791. The CT target allows to set parameters for a packet or its associated
  1792. connection. The target attaches a "template" connection tracking entry to
  1793. the packet, which is then used by the conntrack core when initializing
  1794. a new ct entry. This target is thus only valid in the "raw" table.
  1795. .TP
  1796. \fB\-\-notrack\fP
  1797. Disables connection tracking for this packet.
  1798. .TP
  1799. \fB\-\-helper\fP \fIname\fP
  1800. Use the helper identified by \fIname\fP for the connection. This is more
  1801. flexible than loading the conntrack helper modules with preset ports.
  1802. .TP
  1803. \fB\-\-ctevents\fP \fIevent\fP[\fB,\fP...]
  1804. Only generate the specified conntrack events for this connection. Possible
  1805. event types are: \fBnew\fP, \fBrelated\fP, \fBdestroy\fP, \fBreply\fP,
  1806. \fBassured\fP, \fBprotoinfo\fP, \fBhelper\fP, \fBmark\fP (this refers to
  1807. the ctmark, not nfmark), \fBnatseqinfo\fP, \fBsecmark\fP (ctsecmark).
  1808. .TP
  1809. \fB\-\-expevents\fP \fIevent\fP[\fB,\fP...]
  1810. Only generate the specified expectation events for this connection.
  1811. Possible event types are: \fBnew\fP.
  1812. .TP
  1813. \fB\-\-zone\fP \fIid\fP
  1814. Assign this packet to zone \fIid\fP and only have lookups done in that zone.
  1815. By default, packets have zone 0.
  1816. .TP
  1817. \fB\-\-timeout\fP \fIname\fP
  1818. Use the timeout policy identified by \fIname\fP for the connection. This is
  1819. provides more flexible timeout policy definition than global timeout values
  1820. available at /proc/sys/net/netfilter/nf_conntrack_*_timeout_*.
  1821. .SS DNAT (IPv4-specific)
  1822. This target is only valid in the
  1823. .B nat
  1824. table, in the
  1825. .B PREROUTING
  1826. and
  1827. .B OUTPUT
  1828. chains, and user-defined chains which are only called from those
  1829. chains. It specifies that the destination address of the packet
  1830. should be modified (and all future packets in this connection will
  1831. also be mangled), and rules should cease being examined. It takes one
  1832. type of option:
  1833. .TP
  1834. \fB\-\-to\-destination\fP [\fIipaddr\fP[\fB\-\fP\fIipaddr\fP]][\fB:\fP\fIport\fP[\fB\-\fP\fIport\fP]]
  1835. which can specify a single new destination IP address, an inclusive
  1836. range of IP addresses, and optionally, a port range (which is only
  1837. valid if the rule also specifies
  1838. \fB\-p tcp\fP
  1839. or
  1840. \fB\-p udp\fP).
  1841. If no port range is specified, then the destination port will never be
  1842. modified. If no IP address is specified then only the destination port
  1843. will be modified.
  1844. In Kernels up to 2.6.10 you can add several \-\-to\-destination options. For
  1845. those kernels, if you specify more than one destination address, either via an
  1846. address range or multiple \-\-to\-destination options, a simple round-robin (one
  1847. after another in cycle) load balancing takes place between these addresses.
  1848. Later Kernels (>= 2.6.11-rc1) don't have the ability to NAT to multiple ranges
  1849. anymore.
  1850. .TP
  1851. \fB\-\-random\fP
  1852. If option
  1853. \fB\-\-random\fP
  1854. is used then port mapping will be randomized (kernel >= 2.6.22).
  1855. .TP
  1856. \fB\-\-persistent\fP
  1857. Gives a client the same source-/destination-address for each connection.
  1858. This supersedes the SAME target. Support for persistent mappings is available
  1859. from 2.6.29-rc2.
  1860. .SS DSCP
  1861. This target allows to alter the value of the DSCP bits within the TOS
  1862. header of the IPv4 packet. As this manipulates a packet, it can only
  1863. be used in the mangle table.
  1864. .TP
  1865. \fB\-\-set\-dscp\fP \fIvalue\fP
  1866. Set the DSCP field to a numerical value (can be decimal or hex)
  1867. .TP
  1868. \fB\-\-set\-dscp\-class\fP \fIclass\fP
  1869. Set the DSCP field to a DiffServ class.
  1870. .SS ECN (IPv4-specific)
  1871. This target allows to selectively work around known ECN blackholes.
  1872. It can only be used in the mangle table.
  1873. .TP
  1874. \fB\-\-ecn\-tcp\-remove\fP
  1875. Remove all ECN bits from the TCP header. Of course, it can only be used
  1876. in conjunction with
  1877. \fB\-p tcp\fP.
  1878. .SS HL (IPv6-specific)
  1879. This is used to modify the Hop Limit field in IPv6 header. The Hop Limit field
  1880. is similar to what is known as TTL value in IPv4. Setting or incrementing the
  1881. Hop Limit field can potentially be very dangerous, so it should be avoided at
  1882. any cost. This target is only valid in
  1883. .B mangle
  1884. table.
  1885. .PP
  1886. .B Don't ever set or increment the value on packets that leave your local network!
  1887. .TP
  1888. \fB\-\-hl\-set\fP \fIvalue\fP
  1889. Set the Hop Limit to `value'.
  1890. .TP
  1891. \fB\-\-hl\-dec\fP \fIvalue\fP
  1892. Decrement the Hop Limit `value' times.
  1893. .TP
  1894. \fB\-\-hl\-inc\fP \fIvalue\fP
  1895. Increment the Hop Limit `value' times.
  1896. .SS HMARK
  1897. Like MARK, i.e. set the fwmark, but the mark is calculated from hashing
  1898. packet selector at choice. You have also to specify the mark range and,
  1899. optionally, the offset to start from. ICMP error messages are inspected
  1900. and used to calculate the hashing.
  1901. .PP
  1902. Existing options are:
  1903. .TP
  1904. \fB\-\-hmark\-tuple\fP tuple\fI\fP
  1905. Possible tuple members are:
  1906. .B src
  1907. meaning source address (IPv4, IPv6 address),
  1908. .B dst
  1909. meaning destination address (IPv4, IPv6 address),
  1910. .B sport
  1911. meaning source port (TCP, UDP, UDPlite, SCTP, DCCP),
  1912. .B dport
  1913. meaning destination port (TCP, UDP, UDPlite, SCTP, DCCP),
  1914. .B spi
  1915. meaning Security Parameter Index (AH, ESP), and
  1916. .B ct
  1917. meaning the usage of the conntrack tuple instead of the packet selectors.
  1918. .TP
  1919. \fB\-\-hmark\-mod\fP \fIvalue (must be > 0)\fP
  1920. Modulus for hash calculation (to limit the range of possible marks)
  1921. .TP
  1922. \fB\-\-hmark\-offset\fP \fIvalue\fP
  1923. Offset to start marks from.
  1924. .TP
  1925. For advanced usage, instead of using \-\-hmark\-tuple, you can specify custom
  1926. prefixes and masks:
  1927. .TP
  1928. \fB\-\-hmark\-src\-prefix\fP \fIcidr\fP
  1929. The source address mask in CIDR notation.
  1930. .TP
  1931. \fB\-\-hmark\-dst\-prefix\fP \fIcidr\fP
  1932. The destination address mask in CIDR notation.
  1933. .TP
  1934. \fB\-\-hmark\-sport\-mask\fP \fIvalue\fP
  1935. A 16 bit source port mask in hexadecimal.
  1936. .TP
  1937. \fB\-\-hmark\-dport\-mask\fP \fIvalue\fP
  1938. A 16 bit destination port mask in hexadecimal.
  1939. .TP
  1940. \fB\-\-hmark\-spi\-mask\fP \fIvalue\fP
  1941. A 32 bit field with spi mask.
  1942. .TP
  1943. \fB\-\-hmark\-proto\-mask\fP \fIvalue\fP
  1944. An 8 bit field with layer 4 protocol number.
  1945. .TP
  1946. \fB\-\-hmark\-rnd\fP \fIvalue\fP
  1947. A 32 bit random custom value to feed hash calculation.
  1948. .PP
  1949. \fIExamples:\fP
  1950. .PP
  1951. iptables \-t mangle \-A PREROUTING \-m conntrack \-\-ctstate NEW
  1952. \-j HMARK \-\-hmark-tuple ct,src,dst,proto \-\-hmark-offset 10000
  1953. \-\-hmark\-mod 10 \-\-hmark\-rnd 0xfeedcafe
  1954. .PP
  1955. iptables \-t mangle \-A PREROUTING -j HMARK \-\-hmark\-offset 10000
  1956. \-\-hmark-tuple src,dst,proto \-\-hmark-mod 10 \-\-hmark\-rnd 0xdeafbeef
  1957. .SS IDLETIMER
  1958. This target can be used to identify when interfaces have been idle for a
  1959. certain period of time. Timers are identified by labels and are created when
  1960. a rule is set with a new label. The rules also take a timeout value (in
  1961. seconds) as an option. If more than one rule uses the same timer label, the
  1962. timer will be restarted whenever any of the rules get a hit. One entry for
  1963. each timer is created in sysfs. This attribute contains the timer remaining
  1964. for the timer to expire. The attributes are located under the xt_idletimer
  1965. class:
  1966. .PP
  1967. /sys/class/xt_idletimer/timers/<label>
  1968. .PP
  1969. When the timer expires, the target module sends a sysfs notification to the
  1970. userspace, which can then decide what to do (eg. disconnect to save power).
  1971. .TP
  1972. \fB\-\-timeout\fP \fIamount\fP
  1973. This is the time in seconds that will trigger the notification.
  1974. .TP
  1975. \fB\-\-label\fP \fIstring\fP
  1976. This is a unique identifier for the timer. The maximum length for the
  1977. label string is 27 characters.
  1978. .SS LED
  1979. This creates an LED-trigger that can then be attached to system indicator
  1980. lights, to blink or illuminate them when certain packets pass through the
  1981. system. One example might be to light up an LED for a few minutes every time
  1982. an SSH connection is made to the local machine. The following options control
  1983. the trigger behavior:
  1984. .TP
  1985. \fB\-\-led\-trigger\-id\fP \fIname\fP
  1986. This is the name given to the LED trigger. The actual name of the trigger
  1987. will be prefixed with "netfilter-".
  1988. .TP
  1989. \fB\-\-led-delay\fP \fIms\fP
  1990. This indicates how long (in milliseconds) the LED should be left illuminated
  1991. when a packet arrives before being switched off again. The default is 0
  1992. (blink as fast as possible.) The special value \fIinf\fP can be given to
  1993. leave the LED on permanently once activated. (In this case the trigger will
  1994. need to be manually detached and reattached to the LED device to switch it
  1995. off again.)
  1996. .TP
  1997. \fB\-\-led\-always\-blink\fP
  1998. Always make the LED blink on packet arrival, even if the LED is already on.
  1999. This allows notification of new packets even with long delay values (which
  2000. otherwise would result in a silent prolonging of the delay time.)
  2001. .TP
  2002. Example:
  2003. .TP
  2004. Create an LED trigger for incoming SSH traffic:
  2005. iptables \-A INPUT \-p tcp \-\-dport 22 \-j LED \-\-led\-trigger\-id ssh
  2006. .TP
  2007. Then attach the new trigger to an LED:
  2008. echo netfilter\-ssh >/sys/class/leds/\fIledname\fP/trigger
  2009. .SS LOG (IPv6-specific)
  2010. Turn on kernel logging of matching packets. When this option is set
  2011. for a rule, the Linux kernel will print some information on all
  2012. matching packets (like most IPv6 IPv6-header fields) via the kernel log
  2013. (where it can be read with
  2014. .I dmesg
  2015. or
  2016. .IR syslogd (8)).
  2017. This is a "non-terminating target", i.e. rule traversal continues at
  2018. the next rule. So if you want to LOG the packets you refuse, use two
  2019. separate rules with the same matching criteria, first using target LOG
  2020. then DROP (or REJECT).
  2021. .TP
  2022. \fB\-\-log\-level\fP \fIlevel\fP
  2023. Level of logging, which can be (system-specific) numeric or a mnemonic.
  2024. Possible values are (in decreasing order of priority): \fBemerg\fP,
  2025. \fBalert\fP, \fBcrit\fP, \fBerror\fP, \fBwarning\fP, \fBnotice\fP, \fBinfo\fP
  2026. or \fBdebug\fP.
  2027. .TP
  2028. \fB\-\-log\-prefix\fP \fIprefix\fP
  2029. Prefix log messages with the specified prefix; up to 29 letters long,
  2030. and useful for distinguishing messages in the logs.
  2031. .TP
  2032. \fB\-\-log\-tcp\-sequence\fP
  2033. Log TCP sequence numbers. This is a security risk if the log is
  2034. readable by users.
  2035. .TP
  2036. \fB\-\-log\-tcp\-options\fP
  2037. Log options from the TCP packet header.
  2038. .TP
  2039. \fB\-\-log\-ip\-options\fP
  2040. Log options from the IPv6 packet header.
  2041. .TP
  2042. \fB\-\-log\-uid\fP
  2043. Log the userid of the process which generated the packet.
  2044. .SS LOG (IPv4-specific)
  2045. Turn on kernel logging of matching packets. When this option is set
  2046. for a rule, the Linux kernel will print some information on all
  2047. matching packets (like most IP header fields) via the kernel log
  2048. (where it can be read with
  2049. .I dmesg
  2050. or
  2051. .IR syslogd (8)).
  2052. This is a "non-terminating target", i.e. rule traversal continues at
  2053. the next rule. So if you want to LOG the packets you refuse, use two
  2054. separate rules with the same matching criteria, first using target LOG
  2055. then DROP (or REJECT).
  2056. .TP
  2057. \fB\-\-log\-level\fP \fIlevel\fP
  2058. Level of logging, which can be (system-specific) numeric or a mnemonic.
  2059. Possible values are (in decreasing order of priority): \fBemerg\fP,
  2060. \fBalert\fP, \fBcrit\fP, \fBerror\fP, \fBwarning\fP, \fBnotice\fP, \fBinfo\fP
  2061. or \fBdebug\fP.
  2062. .TP
  2063. \fB\-\-log\-prefix\fP \fIprefix\fP
  2064. Prefix log messages with the specified prefix; up to 29 letters long,
  2065. and useful for distinguishing messages in the logs.
  2066. .TP
  2067. \fB\-\-log\-tcp\-sequence\fP
  2068. Log TCP sequence numbers. This is a security risk if the log is
  2069. readable by users.
  2070. .TP
  2071. \fB\-\-log\-tcp\-options\fP
  2072. Log options from the TCP packet header.
  2073. .TP
  2074. \fB\-\-log\-ip\-options\fP
  2075. Log options from the IP packet header.
  2076. .TP
  2077. \fB\-\-log\-uid\fP
  2078. Log the userid of the process which generated the packet.
  2079. .SS MARK
  2080. This target is used to set the Netfilter mark value associated with the packet.
  2081. It can, for example, be used in conjunction with routing based on fwmark (needs
  2082. iproute2). If you plan on doing so, note that the mark needs to be set in the
  2083. PREROUTING chain of the mangle table to affect routing.
  2084. The mark field is 32 bits wide.
  2085. .TP
  2086. \fB\-\-set\-xmark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  2087. Zeroes out the bits given by \fImask\fP and XORs \fIvalue\fP into the packet
  2088. mark ("nfmark"). If \fImask\fP is omitted, 0xFFFFFFFF is assumed.
  2089. .TP
  2090. \fB\-\-set\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  2091. Zeroes out the bits given by \fImask\fP and ORs \fIvalue\fP into the packet
  2092. mark. If \fImask\fP is omitted, 0xFFFFFFFF is assumed.
  2093. .PP
  2094. The following mnemonics are available:
  2095. .TP
  2096. \fB\-\-and\-mark\fP \fIbits\fP
  2097. Binary AND the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark
  2098. 0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP.)
  2099. .TP
  2100. \fB\-\-or\-mark\fP \fIbits\fP
  2101. Binary OR the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP
  2102. \fIbits\fP\fB/\fP\fIbits\fP.)
  2103. .TP
  2104. \fB\-\-xor\-mark\fP \fIbits\fP
  2105. Binary XOR the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP
  2106. \fIbits\fP\fB/0\fP.)
  2107. .SS MASQUERADE (IPv6-specific)
  2108. This target is only valid in the
  2109. .B nat
  2110. table, in the
  2111. .B POSTROUTING
  2112. chain. It should only be used with dynamically assigned IPv6 (dialup)
  2113. connections: if you have a static IP address, you should use the SNAT
  2114. target. Masquerading is equivalent to specifying a mapping to the IP
  2115. address of the interface the packet is going out, but also has the
  2116. effect that connections are
  2117. .I forgotten
  2118. when the interface goes down. This is the correct behavior when the
  2119. next dialup is unlikely to have the same interface address (and hence
  2120. any established connections are lost anyway).
  2121. .TP
  2122. \fB\-\-to\-ports\fP \fIport\fP[\fB\-\fP\fIport\fP]
  2123. This specifies a range of source ports to use, overriding the default
  2124. .B SNAT
  2125. source port-selection heuristics (see above). This is only valid
  2126. if the rule also specifies
  2127. \fB\-p tcp\fP
  2128. or
  2129. \fB\-p udp\fP.
  2130. .TP
  2131. \fB\-\-random\fP
  2132. Randomize source port mapping
  2133. If option
  2134. \fB\-\-random\fP
  2135. is used then port mapping will be randomized.
  2136. .RS
  2137. .PP
  2138. .SS MASQUERADE (IPv4-specific)
  2139. This target is only valid in the
  2140. .B nat
  2141. table, in the
  2142. .B POSTROUTING
  2143. chain. It should only be used with dynamically assigned IP (dialup)
  2144. connections: if you have a static IP address, you should use the SNAT
  2145. target. Masquerading is equivalent to specifying a mapping to the IP
  2146. address of the interface the packet is going out, but also has the
  2147. effect that connections are
  2148. .I forgotten
  2149. when the interface goes down. This is the correct behavior when the
  2150. next dialup is unlikely to have the same interface address (and hence
  2151. any established connections are lost anyway).
  2152. .TP
  2153. \fB\-\-to\-ports\fP \fIport\fP[\fB\-\fP\fIport\fP]
  2154. This specifies a range of source ports to use, overriding the default
  2155. .B SNAT
  2156. source port-selection heuristics (see above). This is only valid
  2157. if the rule also specifies
  2158. \fB\-p tcp\fP
  2159. or
  2160. \fB\-p udp\fP.
  2161. .TP
  2162. \fB\-\-random\fP
  2163. Randomize source port mapping
  2164. If option
  2165. \fB\-\-random\fP
  2166. is used then port mapping will be randomized (kernel >= 2.6.21).
  2167. .RS
  2168. .PP
  2169. .SS MIRROR (IPv4-specific)
  2170. This is an experimental demonstration target which inverts the source
  2171. and destination fields in the IP header and retransmits the packet.
  2172. It is only valid in the
  2173. .BR INPUT ,
  2174. .B FORWARD
  2175. and
  2176. .B PREROUTING
  2177. chains, and user-defined chains which are only called from those
  2178. chains. Note that the outgoing packets are
  2179. .B NOT
  2180. seen by any packet filtering chains, connection tracking or NAT, to
  2181. avoid loops and other problems.
  2182. .SS NETMAP (IPv4-specific)
  2183. This target allows you to statically map a whole network of addresses onto
  2184. another network of addresses. It can only be used from rules in the
  2185. .B nat
  2186. table.
  2187. .TP
  2188. \fB\-\-to\fP \fIaddress\fP[\fB/\fP\fImask\fP]
  2189. Network address to map to. The resulting address will be constructed in the
  2190. following way: All 'one' bits in the mask are filled in from the new `address'.
  2191. All bits that are zero in the mask are filled in from the original address.
  2192. .SS NFLOG
  2193. This target provides logging of matching packets. When this target is
  2194. set for a rule, the Linux kernel will pass the packet to the loaded
  2195. logging backend to log the packet. This is usually used in combination
  2196. with nfnetlink_log as logging backend, which will multicast the packet
  2197. through a
  2198. .IR netlink
  2199. socket to the specified multicast group. One or more userspace processes
  2200. may subscribe to the group to receive the packets. Like LOG, this is a
  2201. non-terminating target, i.e. rule traversal continues at the next rule.
  2202. .TP
  2203. \fB\-\-nflog\-group\fP \fInlgroup\fP
  2204. The netlink group (0 - 2^16\-1) to which packets are (only applicable for
  2205. nfnetlink_log). The default value is 0.
  2206. .TP
  2207. \fB\-\-nflog\-prefix\fP \fIprefix\fP
  2208. A prefix string to include in the log message, up to 64 characters
  2209. long, useful for distinguishing messages in the logs.
  2210. .TP
  2211. \fB\-\-nflog\-range\fP \fIsize\fP
  2212. The number of bytes to be copied to userspace (only applicable for
  2213. nfnetlink_log). nfnetlink_log instances may specify their own
  2214. range, this option overrides it.
  2215. .TP
  2216. \fB\-\-nflog\-threshold\fP \fIsize\fP
  2217. Number of packets to queue inside the kernel before sending them
  2218. to userspace (only applicable for nfnetlink_log). Higher values
  2219. result in less overhead per packet, but increase delay until the
  2220. packets reach userspace. The default value is 1.
  2221. .BR
  2222. .SS NFQUEUE
  2223. This target is an extension of the QUEUE target. As opposed to QUEUE, it allows
  2224. you to put a packet into any specific queue, identified by its 16-bit queue
  2225. number.
  2226. It can only be used with Kernel versions 2.6.14 or later, since it requires
  2227. the
  2228. .B
  2229. nfnetlink_queue
  2230. kernel support. The \fBqueue-balance\fP option was added in Linux 2.6.31,
  2231. \fBqueue-bypass\fP in 2.6.39.
  2232. .TP
  2233. \fB\-\-queue\-num\fP \fIvalue\fP
  2234. This specifies the QUEUE number to use. Valid queue numbers are 0 to 65535. The default value is 0.
  2235. .PP
  2236. .TP
  2237. \fB\-\-queue\-balance\fP \fIvalue\fP\fB:\fP\fIvalue\fP
  2238. This specifies a range of queues to use. Packets are then balanced across the given queues.
  2239. This is useful for multicore systems: start multiple instances of the userspace program on
  2240. queues x, x+1, .. x+n and use "\-\-queue\-balance \fIx\fP\fB:\fP\fIx+n\fP".
  2241. Packets belonging to the same connection are put into the same nfqueue.
  2242. .PP
  2243. .TP
  2244. \fB\-\-queue\-bypass\fP
  2245. By default, if no userspace program is listening on an NFQUEUE, then all packets that are to be queued
  2246. are dropped. When this option is used, the NFQUEUE rule is silently bypassed instead. The packet
  2247. will move on to the next rule.
  2248. .SS NOTRACK
  2249. This target disables connection tracking for all packets matching that rule.
  2250. It is obsoleted by \-j CT \-\-notrack. Like CT, NOTRACK can only be used in
  2251. the \fBraw\fP table.
  2252. .SS RATEEST
  2253. The RATEEST target collects statistics, performs rate estimation calculation
  2254. and saves the results for later evaluation using the \fBrateest\fP match.
  2255. .TP
  2256. \fB\-\-rateest\-name\fP \fIname\fP
  2257. Count matched packets into the pool referred to by \fIname\fP, which is freely
  2258. choosable.
  2259. .TP
  2260. \fB\-\-rateest\-interval\fP \fIamount\fP{\fBs\fP|\fBms\fP|\fBus\fP}
  2261. Rate measurement interval, in seconds, milliseconds or microseconds.
  2262. .TP
  2263. \fB\-\-rateest\-ewmalog\fP \fIvalue\fP
  2264. Rate measurement averaging time constant.
  2265. .SS REDIRECT (IPv4-specific)
  2266. This target is only valid in the
  2267. .B nat
  2268. table, in the
  2269. .B PREROUTING
  2270. and
  2271. .B OUTPUT
  2272. chains, and user-defined chains which are only called from those
  2273. chains. It redirects the packet to the machine itself by changing the
  2274. destination IP to the primary address of the incoming interface
  2275. (locally-generated packets are mapped to the 127.0.0.1 address).
  2276. .TP
  2277. \fB\-\-to\-ports\fP \fIport\fP[\fB\-\fP\fIport\fP]
  2278. This specifies a destination port or range of ports to use: without
  2279. this, the destination port is never altered. This is only valid
  2280. if the rule also specifies
  2281. \fB\-p tcp\fP
  2282. or
  2283. \fB\-p udp\fP.
  2284. .TP
  2285. \fB\-\-random\fP
  2286. If option
  2287. \fB\-\-random\fP
  2288. is used then port mapping will be randomized (kernel >= 2.6.22).
  2289. .RS
  2290. .PP
  2291. .SS REJECT (IPv6-specific)
  2292. This is used to send back an error packet in response to the matched
  2293. packet: otherwise it is equivalent to
  2294. .B DROP
  2295. so it is a terminating TARGET, ending rule traversal.
  2296. This target is only valid in the
  2297. .BR INPUT ,
  2298. .B FORWARD
  2299. and
  2300. .B OUTPUT
  2301. chains, and user-defined chains which are only called from those
  2302. chains. The following option controls the nature of the error packet
  2303. returned:
  2304. .TP
  2305. \fB\-\-reject\-with\fP \fItype\fP
  2306. The type given can be
  2307. \fBicmp6\-no\-route\fP,
  2308. \fBno\-route\fP,
  2309. \fBicmp6\-adm\-prohibited\fP,
  2310. \fBadm\-prohibited\fP,
  2311. \fBicmp6\-addr\-unreachable\fP,
  2312. \fBaddr\-unreach\fP,
  2313. \fBicmp6\-port\-unreachable\fP or
  2314. \fBport\-unreach\fP
  2315. which return the appropriate ICMPv6 error message (\fBport\-unreach\fP is
  2316. the default). Finally, the option
  2317. \fBtcp\-reset\fP
  2318. can be used on rules which only match the TCP protocol: this causes a
  2319. TCP RST packet to be sent back. This is mainly useful for blocking
  2320. .I ident
  2321. (113/tcp) probes which frequently occur when sending mail to broken mail
  2322. hosts (which won't accept your mail otherwise).
  2323. \fBtcp\-reset\fP
  2324. can only be used with kernel versions 2.6.14 or later.
  2325. .SS REJECT (IPv4-specific)
  2326. This is used to send back an error packet in response to the matched
  2327. packet: otherwise it is equivalent to
  2328. .B DROP
  2329. so it is a terminating TARGET, ending rule traversal.
  2330. This target is only valid in the
  2331. .BR INPUT ,
  2332. .B FORWARD
  2333. and
  2334. .B OUTPUT
  2335. chains, and user-defined chains which are only called from those
  2336. chains. The following option controls the nature of the error packet
  2337. returned:
  2338. .TP
  2339. \fB\-\-reject\-with\fP \fItype\fP
  2340. The type given can be
  2341. \fBicmp\-net\-unreachable\fP,
  2342. \fBicmp\-host\-unreachable\fP,
  2343. \fBicmp\-port\-unreachable\fP,
  2344. \fBicmp\-proto\-unreachable\fP,
  2345. \fBicmp\-net\-prohibited\fP,
  2346. \fBicmp\-host\-prohibited\fP or
  2347. \fBicmp\-admin\-prohibited\fP (*)
  2348. which return the appropriate ICMP error message (\fBport\-unreachable\fP is
  2349. the default). The option
  2350. \fBtcp\-reset\fP
  2351. can be used on rules which only match the TCP protocol: this causes a
  2352. TCP RST packet to be sent back. This is mainly useful for blocking
  2353. .I ident
  2354. (113/tcp) probes which frequently occur when sending mail to broken mail
  2355. hosts (which won't accept your mail otherwise).
  2356. .PP
  2357. (*) Using icmp\-admin\-prohibited with kernels that do not support it will result in a plain DROP instead of REJECT
  2358. .SS SAME (IPv4-specific)
  2359. Similar to SNAT/DNAT depending on chain: it takes a range of addresses
  2360. (`\-\-to 1.2.3.4\-1.2.3.7') and gives a client the same
  2361. source-/destination-address for each connection.
  2362. .PP
  2363. N.B.: The DNAT target's \fB\-\-persistent\fP option replaced the SAME target.
  2364. .TP
  2365. \fB\-\-to\fP \fIipaddr\fP[\fB\-\fP\fIipaddr\fP]
  2366. Addresses to map source to. May be specified more than once for
  2367. multiple ranges.
  2368. .TP
  2369. \fB\-\-nodst\fP
  2370. Don't use the destination-ip in the calculations when selecting the
  2371. new source-ip
  2372. .TP
  2373. \fB\-\-random\fP
  2374. Port mapping will be forcibly randomized to avoid attacks based on
  2375. port prediction (kernel >= 2.6.21).
  2376. .SS SECMARK
  2377. This is used to set the security mark value associated with the
  2378. packet for use by security subsystems such as SELinux. It is
  2379. valid in the
  2380. .B security
  2381. table (for backwards compatibility with older kernels, it is also
  2382. valid in the
  2383. .B mangle
  2384. table). The mark is 32 bits wide.
  2385. .TP
  2386. \fB\-\-selctx\fP \fIsecurity_context\fP
  2387. .SS SET
  2388. This module adds and/or deletes entries from IP sets which can be defined
  2389. by ipset(8).
  2390. .TP
  2391. \fB\-\-add\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP...]
  2392. add the address(es)/port(s) of the packet to the set
  2393. .TP
  2394. \fB\-\-del\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP...]
  2395. delete the address(es)/port(s) of the packet from the set
  2396. .IP
  2397. where \fIflag\fP(s) are
  2398. .BR "src"
  2399. and/or
  2400. .BR "dst"
  2401. specifications and there can be no more than six of them.
  2402. .TP
  2403. \fB\-\-timeout\fP \fIvalue\fP
  2404. when adding an entry, the timeout value to use instead of the default
  2405. one from the set definition
  2406. .TP
  2407. \fB\-\-exist\fP
  2408. when adding an entry if it already exists, reset the timeout value
  2409. to the specified one or to the default from the set definition
  2410. .PP
  2411. Use of -j SET requires that ipset kernel support is provided, which, for
  2412. standard kernels, is the case since Linux 2.6.39.
  2413. .SS SNAT (IPv4-specific)
  2414. This target is only valid in the
  2415. .B nat
  2416. table, in the
  2417. .B POSTROUTING
  2418. chain. It specifies that the source address of the packet should be
  2419. modified (and all future packets in this connection will also be
  2420. mangled), and rules should cease being examined. It takes one type
  2421. of option:
  2422. .TP
  2423. \fB\-\-to\-source\fP [\fIipaddr\fP[\fB\-\fP\fIipaddr\fP]][\fB:\fP\fIport\fP[\fB\-\fP\fIport\fP]]
  2424. which can specify a single new source IP address, an inclusive range
  2425. of IP addresses, and optionally, a port range (which is only valid if
  2426. the rule also specifies
  2427. \fB\-p tcp\fP
  2428. or
  2429. \fB\-p udp\fP).
  2430. If no port range is specified, then source ports below 512 will be
  2431. mapped to other ports below 512: those between 512 and 1023 inclusive
  2432. will be mapped to ports below 1024, and other ports will be mapped to
  2433. 1024 or above. Where possible, no port alteration will occur.
  2434. In Kernels up to 2.6.10, you can add several \-\-to\-source options. For those
  2435. kernels, if you specify more than one source address, either via an address
  2436. range or multiple \-\-to\-source options, a simple round-robin (one after another
  2437. in cycle) takes place between these addresses.
  2438. Later Kernels (>= 2.6.11-rc1) don't have the ability to NAT to multiple ranges
  2439. anymore.
  2440. .TP
  2441. \fB\-\-random\fP
  2442. If option
  2443. \fB\-\-random\fP
  2444. is used then port mapping will be randomized (kernel >= 2.6.21).
  2445. .TP
  2446. \fB\-\-persistent\fP
  2447. Gives a client the same source-/destination-address for each connection.
  2448. This supersedes the SAME target. Support for persistent mappings is available
  2449. from 2.6.29-rc2.
  2450. .SS TCPMSS
  2451. This target allows to alter the MSS value of TCP SYN packets, to control
  2452. the maximum size for that connection (usually limiting it to your
  2453. outgoing interface's MTU minus 40 for IPv4 or 60 for IPv6, respectively).
  2454. Of course, it can only be used
  2455. in conjunction with
  2456. \fB\-p tcp\fP.
  2457. .PP
  2458. This target is used to overcome criminally braindead ISPs or servers
  2459. which block "ICMP Fragmentation Needed" or "ICMPv6 Packet Too Big"
  2460. packets. The symptoms of this
  2461. problem are that everything works fine from your Linux
  2462. firewall/router, but machines behind it can never exchange large
  2463. packets:
  2464. .IP 1. 4
  2465. Web browsers connect, then hang with no data received.
  2466. .IP 2. 4
  2467. Small mail works fine, but large emails hang.
  2468. .IP 3. 4
  2469. ssh works fine, but scp hangs after initial handshaking.
  2470. .PP
  2471. Workaround: activate this option and add a rule to your firewall
  2472. configuration like:
  2473. .IP
  2474. iptables \-t mangle \-A FORWARD \-p tcp \-\-tcp\-flags SYN,RST SYN
  2475. \-j TCPMSS \-\-clamp\-mss\-to\-pmtu
  2476. .TP
  2477. \fB\-\-set\-mss\fP \fIvalue\fP
  2478. Explicitly sets MSS option to specified value. If the MSS of the packet is
  2479. already lower than \fIvalue\fP, it will \fBnot\fP be increased (from Linux
  2480. 2.6.25 onwards) to avoid more problems with hosts relying on a proper MSS.
  2481. .TP
  2482. \fB\-\-clamp\-mss\-to\-pmtu\fP
  2483. Automatically clamp MSS value to (path_MTU \- 40 for IPv4; \-60 for IPv6).
  2484. This may not function as desired where asymmetric routes with differing
  2485. path MTU exist \(em the kernel uses the path MTU which it would use to send
  2486. packets from itself to the source and destination IP addresses. Prior to
  2487. Linux 2.6.25, only the path MTU to the destination IP address was
  2488. considered by this option; subsequent kernels also consider the path MTU
  2489. to the source IP address.
  2490. .PP
  2491. These options are mutually exclusive.
  2492. .SS TCPOPTSTRIP
  2493. This target will strip TCP options off a TCP packet. (It will actually replace
  2494. them by NO-OPs.) As such, you will need to add the \fB\-p tcp\fP parameters.
  2495. .TP
  2496. \fB\-\-strip\-options\fP \fIoption\fP[\fB,\fP\fIoption\fP...]
  2497. Strip the given option(s). The options may be specified by TCP option number or
  2498. by symbolic name. The list of recognized options can be obtained by calling
  2499. iptables with \fB\-j TCPOPTSTRIP \-h\fP.
  2500. .SS TEE
  2501. The \fBTEE\fP target will clone a packet and redirect this clone to another
  2502. machine on the \fBlocal\fP network segment. In other words, the nexthop
  2503. must be the target, or you will have to configure the nexthop to forward it
  2504. further if so desired.
  2505. .TP
  2506. \fB\-\-gateway\fP \fIipaddr\fP
  2507. Send the cloned packet to the host reachable at the given IP address.
  2508. Use of 0.0.0.0 (for IPv4 packets) or :: (IPv6) is invalid.
  2509. .PP
  2510. To forward all incoming traffic on eth0 to an Network Layer logging box:
  2511. .PP
  2512. \-t mangle \-A PREROUTING \-i eth0 \-j TEE \-\-gateway 2001:db8::1
  2513. .SS TOS
  2514. This module sets the Type of Service field in the IPv4 header (including the
  2515. "precedence" bits) or the Priority field in the IPv6 header. Note that TOS
  2516. shares the same bits as DSCP and ECN. The TOS target is only valid in the
  2517. \fBmangle\fP table.
  2518. .TP
  2519. \fB\-\-set\-tos\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  2520. Zeroes out the bits given by \fImask\fP (see NOTE below) and XORs \fIvalue\fP
  2521. into the TOS/Priority field. If \fImask\fP is omitted, 0xFF is assumed.
  2522. .TP
  2523. \fB\-\-set\-tos\fP \fIsymbol\fP
  2524. You can specify a symbolic name when using the TOS target for IPv4. It implies
  2525. a mask of 0xFF (see NOTE below). The list of recognized TOS names can be
  2526. obtained by calling iptables with \fB\-j TOS \-h\fP.
  2527. .PP
  2528. The following mnemonics are available:
  2529. .TP
  2530. \fB\-\-and\-tos\fP \fIbits\fP
  2531. Binary AND the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos
  2532. 0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP.
  2533. See NOTE below.)
  2534. .TP
  2535. \fB\-\-or\-tos\fP \fIbits\fP
  2536. Binary OR the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos\fP
  2537. \fIbits\fP\fB/\fP\fIbits\fP. See NOTE below.)
  2538. .TP
  2539. \fB\-\-xor\-tos\fP \fIbits\fP
  2540. Binary XOR the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos\fP
  2541. \fIbits\fP\fB/0\fP. See NOTE below.)
  2542. .PP
  2543. NOTE: In Linux kernels up to and including 2.6.38, with the exception of
  2544. longterm releases 2.6.32 (>=.42), 2.6.33 (>=.15), and 2.6.35 (>=.14), there is
  2545. a bug whereby IPv6 TOS mangling does not behave as documented and differs from
  2546. the IPv4 version. The TOS mask indicates the bits one wants to zero out, so it
  2547. needs to be inverted before applying it to the original TOS field. However, the
  2548. aformentioned kernels forgo the inversion which breaks --set-tos and its
  2549. mnemonics.
  2550. .SS TPROXY
  2551. This target is only valid in the \fBmangle\fP table, in the \fBPREROUTING\fP
  2552. chain and user-defined chains which are only called from this chain. It
  2553. redirects the packet to a local socket without changing the packet header in
  2554. any way. It can also change the mark value which can then be used in advanced
  2555. routing rules.
  2556. It takes three options:
  2557. .TP
  2558. \fB\-\-on\-port\fP \fIport\fP
  2559. This specifies a destination port to use. It is a required option, 0 means the
  2560. new destination port is the same as the original. This is only valid if the
  2561. rule also specifies \fB\-p tcp\fP or \fB\-p udp\fP.
  2562. .TP
  2563. \fB\-\-on\-ip\fP \fIaddress\fP
  2564. This specifies a destination address to use. By default the address is the IP
  2565. address of the incoming interface. This is only valid if the rule also
  2566. specifies \fB\-p tcp\fP or \fB\-p udp\fP.
  2567. .TP
  2568. \fB\-\-tproxy\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP]
  2569. Marks packets with the given value/mask. The fwmark value set here can be used
  2570. by advanced routing. (Required for transparent proxying to work: otherwise
  2571. these packets will get forwarded, which is probably not what you want.)
  2572. .SS TRACE
  2573. This target marks packets so that the kernel will log every rule which match
  2574. the packets as those traverse the tables, chains, rules.
  2575. .PP
  2576. A logging backend, such as ip(6)t_LOG or nfnetlink_log, must be loaded for this
  2577. to be visible.
  2578. The packets are logged with the string prefix:
  2579. "TRACE: tablename:chainname:type:rulenum " where type can be "rule" for
  2580. plain rule, "return" for implicit rule at the end of a user defined chain
  2581. and "policy" for the policy of the built in chains.
  2582. .br
  2583. It can only be used in the
  2584. .BR raw
  2585. table.
  2586. .SS TTL (IPv4-specific)
  2587. This is used to modify the IPv4 TTL header field. The TTL field determines
  2588. how many hops (routers) a packet can traverse until it's time to live is
  2589. exceeded.
  2590. .PP
  2591. Setting or incrementing the TTL field can potentially be very dangerous,
  2592. so it should be avoided at any cost. This target is only valid in
  2593. .B mangle
  2594. table.
  2595. .PP
  2596. .B Don't ever set or increment the value on packets that leave your local network!
  2597. .TP
  2598. \fB\-\-ttl\-set\fP \fIvalue\fP
  2599. Set the TTL value to `value'.
  2600. .TP
  2601. \fB\-\-ttl\-dec\fP \fIvalue\fP
  2602. Decrement the TTL value `value' times.
  2603. .TP
  2604. \fB\-\-ttl\-inc\fP \fIvalue\fP
  2605. Increment the TTL value `value' times.
  2606. .SS ULOG (IPv4-specific)
  2607. This target provides userspace logging of matching packets. When this
  2608. target is set for a rule, the Linux kernel will multicast this packet
  2609. through a
  2610. .IR netlink
  2611. socket. One or more userspace processes may then subscribe to various
  2612. multicast groups and receive the packets.
  2613. Like LOG, this is a "non-terminating target", i.e. rule traversal
  2614. continues at the next rule.
  2615. .TP
  2616. \fB\-\-ulog\-nlgroup\fP \fInlgroup\fP
  2617. This specifies the netlink group (1-32) to which the packet is sent.
  2618. Default value is 1.
  2619. .TP
  2620. \fB\-\-ulog\-prefix\fP \fIprefix\fP
  2621. Prefix log messages with the specified prefix; up to 32 characters
  2622. long, and useful for distinguishing messages in the logs.
  2623. .TP
  2624. \fB\-\-ulog\-cprange\fP \fIsize\fP
  2625. Number of bytes to be copied to userspace. A value of 0 always copies
  2626. the entire packet, regardless of its size. Default is 0.
  2627. .TP
  2628. \fB\-\-ulog\-qthreshold\fP \fIsize\fP
  2629. Number of packet to queue inside kernel. Setting this value to, e.g. 10
  2630. accumulates ten packets inside the kernel and transmits them as one
  2631. netlink multipart message to userspace. Default is 1 (for backwards
  2632. compatibility).
  2633. .br