| 1 |
# prerouting, postrouting, forward, input, output |
| 2 |
|
| 3 |
These sections are used to specify packet mangle rules. Mangle rules are |
| 4 |
processed before normal zone-zone filtering rules. |
| 5 |
|
| 6 |
* `prerouting` is for all incoming packets |
| 7 |
* `postrouting` is for all outgoing packets |
| 8 |
* `forward` is for all forwarded packets (for example `internal-public`) |
| 9 |
* `input` is for all packets targetted to `localhost` (`public-localhost`) |
| 10 |
* `output` is for all locally generated packets (`localhost-public`) |
| 11 |
|
| 12 |
Normally these sections are used to [set](../rule/matcher.md#mark_set) packet mark value |
| 13 |
or [MSS clamping](../rule/misc.md#mss). |
| 14 |
|
| 15 |
Example: |
| 16 |
|
| 17 |
``` |
| 18 |
prerouting { |
| 19 |
# Do nothing if mark is already set |
| 20 |
mark_match -0x0000/0xff00 accept |
| 21 |
|
| 22 |
# Set default mark 0x100 to packet |
| 23 |
mark_set 0x100/0xff00 |
| 24 |
|
| 25 |
# Change mark to 0x200 if it is coming from eth2 |
| 26 |
iifname eth2 mark_set 0x200/0xff00 |
| 27 |
|
| 28 |
# Use mark 0x300 for SSH traffic from eth2 |
| 29 |
iifname eth2 ssh mark_set 0x300/0xff00 |
| 30 |
} |
| 31 |
``` |
| 32 |
|
| 33 |
Chain type and hook priority can also be specified. Example: |
| 34 |
|
| 35 |
``` |
| 36 |
prerouting filter raw { |
| 37 |
... |
| 38 |
} |
| 39 |
|
| 40 |
postrouting nat srcnat + 20 { |
| 41 |
... |
| 42 |
} |
| 43 |
``` |
| 44 |
|
| 45 |
These sections are special. Rule `drop` or `reject` will drop/reject packet |
| 46 |
immediately. Default rule is `accept`, which will continue processing to |
| 47 |
other special sections, zone-zone section and again to other special |
| 48 |
sections. All of them have to accept the packet. See |
| 49 |
[packet flow in Netfilter](https://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg) |
| 50 |
for detailed section processing order. |