如何使用 iptables 或 IFB 按設備標記傳入流量?

如何使用 iptables 或 IFB 按設備標記傳入流量?

我正在嘗試使用 iptables 根據這些資料包到達的設備(而不是其原始 IP 位址或連接埠等)來標記傳入資料包,但還沒有找到使其工作的方法。

具體來說,我可以設定一個過濾器來計算每個傳入資料包(並且工作正常):

iptables -F -t mangle
iptables -A PREROUTING -t mangle -j MARK --set-mark 1
iptables -nvL

Chain PREROUTING (policy ACCEPT 185 packets, 41507 bytes)
 pkts bytes target     prot opt in     out     source               destination
  185 41507 MARK       all  --  *      *       0.0.0.0/0            0.0.0.0/0            MARK set 0x1

然而,僅捕獲來自 eth2 的資料包的過濾器似乎永遠不會被觸發(即使這正是所有流量的來源):

iptables -F -t mangle
iptables -A PREROUTING -t mangle -i eth2 -j MARK --set-mark 1
iptables -nvL

Chain PREROUTING (policy ACCEPT 101 packets, 19288 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MARK       all  --  eth2   *       0.0.0.0/0            0.0.0.0/0            MARK set 0x1

從線上 howtos 等來看,這種行為很可能是 iptables 運作方式的邏輯結果:為了解決這個問題,人們嘗試使用 IMQ(在 IMQ 被刪除之前):然後轉而使用 IFB。但那裡的文檔線索似乎變得冷冰冰的。

所以我的問題是:如果使用 IFB 是解決此問題的正確方法,那麼按裝置標記傳入流量的等效 IFB 方法會是什麼樣子?

或者,是否有一種方法可以將透過給定介面傳入的流量分類為一組不同領域之一?例如 eth0 -->realm_10、eth1-->realm_11 等。

相關內容