ip routing nerouting
Vitezslav Samel
vitezslav na samel.cz
Čtvrtek Září 24 08:34:44 CEST 2026
Ahoj,
On Wed, Sep 23, 2026 at 15:03:27 +0000, Pavel Just wrote:
> Mám hosta se dvěma rozhraními eth0 a eth1.
> Eth0 má adresu a.b.c.2/24, eth1 má x.y.z.2/24.
>
> Potřebuji, aby komunikace, která přišla přes rozhraní eth0
> se do eth0 zase vrátila a obdobně pro eth1.
> Prostě jako dva nezávislí hosti.
>
> Vyrobil jsem si dvě routovací tabulky, každá s defaultroute
> na bránu v příslušné síti. tedy něco typu
> route add default via a.b.c.1 dev eth0 table 7
> route add default via x.y.z.1 dev eth1 table 8
>
> Pak jsem vytvořil pravidla
> ip rule add fwmark 7 table 7 prio 70
> ip rule add fwmark 8 table 8 prio 80
>
> A k tomu nft ruleset
> table inet mangling {
> chain prerouting {
> type filter hook prerouting priority mangle; policy accept;
> iifname "eth0" ct mark set 0x7
> iifname "eth0" meta mark set 0x7
> iifname "eth1" ct mark set 0x8
> iifname "eth1" meta mark set 0x8
> }
> chain output {
> type filter hook output priority mangle; policy accept;
> ct mark 0x8 meta mark set 0x8
> ct mark 0x7 meta mark set 0x7
> }
> }
>
> Routovací tabulky 70 a 80 se mi neuplatní. Vždy se uplatní až v mém případě tabulka main.
> Když si dám do "chain prerouting" a "chain output" počitadla, která spínají
> na ct mark = 7,8 nebo meta mark = 7,8, tak se inkrementují dle očekávání.
> Ale ip rule je nevidí. Jádro je verze 6.12.
> Co jsem prosím přehlédl ?
Možná jsi přehlédl toto z man nft:
----------------------------------------
CONNTRACK STATEMENT
The conntrack statement can be used to set the conntrack mark and con‐
ntrack labels.
ct {mark | event | label | zone} set value
The ct statement sets meta data associated with a connection. The zone id
has to be assigned before a conntrack lookup takes place, i.e. this has to
be done in prerouting and possibly output (if locally generated packets
need to be placed in a distinct zone), with a hook priority of raw (-300).
Unlike iptables, where the helper assignment happens in the raw table, the
helper needs to be assigned after a conntrack entry has been found, i.e.
it will not work when used with hook priorities equal or before -200.
----------------------------------------
Takže ta mangling pravidla z nftables musí mít prioritu před -200
(priorita mangle je -150).
V.
Další informace o konferenci Linux