
我正在透過以下方式將規則從 iptable 遷移到 nftable從 iptable 遷移到 nftable
我現在有幾個 IP 和連接埠阻止規則以及基於字串的 iptable 規則,但是透過使用內建的 iptable 轉換規則,我可以將規則從 iptable 轉換為 nftable,但 iptable 中基於字串的規則翻譯後在nftables 中進行註釋。下面是翻譯後的nftable規則
add rule ip filter INPUT tcp dport 1024-65535 counter accept
add rule ip filter INPUT udp dport 1024-65535 counter accept
65535 -j DROP
# -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j DROP
# -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j DROP
# -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j DROP
add rule ip filter INPUT icmp type echo-reply ct state new,related,established counter accept
add rule ip filter INPUT icmp type echo-request ct state new,related,established counter accept
add rule ip filter INPUT icmp type destination-unreachable ct state new,related,established counter accept
add rule ip filter INPUT icmp type time-exceeded ct state new,related,established counter accept
需要有關如何將基於字串的 iptable 規則轉換為 nftable 規則的幫助,以及如果它像上面那樣失敗,我應該參考哪個日誌。
答案1
有目前沒有 nftables 中的等價物, 這細繩match 目前位於不支援的擴充清單中。所有這些不受支援的擴展(可能還有一些受支援的擴展)都不會被轉換為nftables因為它們使用了一個不能只用nftables字節碼(嘗試nft -a --debug=netlink list ruleset
查看字節碼)也不是在核心中作為本機實現的nftables模組,因此翻譯工具甚至不會嘗試。
如果您了解有關協議的更多資訊並且可以期望在以下位置找到該字串固定的資料包中的位置有解決方法可以使用原始負載表達式與那裡的例子。
否則你可以混合nftables和iptables(包括iptables-nft) 規則,只要您在中使用不同的表格名稱nftables不與iptables-nft(可能正在使用)。目前還沒有逐步淘汰的計劃iptables(至少iptables-nft實現,完全能夠使用各種 xtables 模組,例如細繩)。
這裡選擇了表格t
,所以不會與表格衝突filter
。nftables取得其輸入鏈(任意稱為c_in
以優先權 10iptables掛在相同位置的 INPUT 鏈以其固定優先級 0 優先。iptables' 或者nftables') 先運行。表之間刪除/接受規則並不重要。真正重要的情況是像這裡那樣分割規則時(但對於這種特定情況,順序沒有什麼特別的,所以沒關係),以及更改規則或具有副作用的規則:在nftables 放或一個iptables伴侶IP集然後丟棄資料包與先丟棄資料包(然後什麼也不丟棄)不同。
nft add table ip t
nft add chain ip t c_in '{ type filter hook input priority 10; policy accept; }'
nft add rule ip t c_in tcp dport 1024-65535 counter accept
nft add rule ip t c_in udp dport 1024-65535 counter accept
nft add rule ip t c_in icmp type echo-reply ct state new,related,established counter accept
nft add rule ip t c_in icmp type echo-request ct state new,related,established counter accept
nft add rule ip t c_in icmp type destination-unreachable ct state new,related,established counter accept
nft add rule ip t c_in icmp type time-exceeded ct state new,related,established counter accept
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j DROP
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j DROP
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j DROP
抱歉,我不知道該怎麼辦:
65535 -j DROP
這看起來像是該工具的拼字錯誤或翻譯錯誤。
當兩個世界之間需要互動時,可以透過使用來傳遞“訊息”分數。在這種情況下,優先順序很重要。例如,如果放置操作只能在nftables出於規則管理的原因,可以使用它來代替,請記住iptables' 過濾器/輸入的優先權高於nftables't c_in 這裡:
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string abc.exe --algo bm --to 65535 -j MARK --set-mark 0xdead
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string def.exe --algo bm --to 65535 -j MARK --set-mark 0xdead
iptables -t filter -A INPUT -p udp -m udp --dport 234 -m string --string hij.exe --algo bm --to 65535 -j MARK --set-mark 0xdead
並插入這個nftables規則之前的短路...established...
規則在該地方細繩規則最初是:
nft add ip t c_in meta mark 0xdead drop