# Tables

Tables

OUTPUT

INPUT

POSTROUTING

PREROUTING

NAT

**MANGLE**

主要目的概念 :

Policy Route and QOS

涵蓋實作範圍 :

TOS（Type Of Service）、TTL（Time To Live）指以及為 packet 打 Mark

在 kernel 裡面是一個 module，裡面還有幾個 function 的 module :

mark match

\[!] –mark value\[/mask] 數據包的nfmark值與value進行匹配，其中mask的值為可選的

MARK target

–set-mark value 設置 packet 的nfmark值。

–and-mark value packet 的nfmark值和value進行按 AND 運算。

–or-mark value packet 的nfmark值和value進行按 OR 運算。

CONNMARK target

|                              |                                     |
| ---------------------------- | ----------------------------------- |
| -set-mark value\[/mask]      | 給 conntrack 打 mark                  |
| -save-mark \[--mask mask]    | 將 packet 裡的 mark save 到 conntrack 裡 |
| -restore-mark \[--mask mask] | 重新設置 packet 的 nfmark                |

CONNMARK 和 MARK的區別：

同樣是打標記，但 CONNMARK 是針對 conntrack 的，而 MARK 是針對單一 pakcet 的

這兩種機制一般都要和ip rule中的fwmark聯用，實現對滿足某一類條件的數據包的策略路由

1.對連接打了標記，只是標記了連接，沒有標記連接中的每個數據包

2.標記單個數據包，也不會對整條連接的標記有影響。二者是相對獨立的

關於 Routing Decision :

是以單一 packet 為單位的，或者說，在netfilter框架之外，並沒有 conntrack 的概念。或者說，ip命令只知道MARK, 而不知道CONNMARK是什麼，所以如果要改 routing decesion 要給所有要進行 ip rule 匹配的單一 packet 打上 mark 。

方法：

用MARK直接打

用CONNMARK –restore-mark把打在連接上的 conntrack 轉移到 packet 上。

原文網址：

<https://read01.com/zzn4.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fashaun.gitbook.io/linux-network/netfilter/iptables/tables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
