切換選單
切換偏好設定選單
切換個人選單
尚未登入
若您做出任何編輯,會公開您的 IP 位址。

使用nftables為指定Linux用戶強制使用代理

出自md5.pw
於 2026年2月19日 (四) 07:02 由 Koud Wind留言 | 貢獻 所做的修訂

1. 準備

確保 nftables 已經安裝, 且本地有透明代理端口 (比如Xray的dokodemo-door), 這裡就不注重如何開設透明代理

nft --version

若沒有安裝, 以Debian13為例

apt update
apt install nftables
systemctl enable nftables

拷貝原有的nftables配置, 到一個好找的目錄里, 以 /main/nftables 為例, 再對原路徑進行鏈接

cp /etc/nftables.conf /main/nftables/
ln -f /main/nftables/nftables.conf /etc/nftables.conf

並準備好編輯 /main/nftables/nftables.conf

2. 配置nftables

查看用戶id

cat /etc/passwd

這裡假設我在10809端口開設了透明代理, 我需要10001001的用戶id所建立的tcp連接使用代理


請在合適位置添加或與其它的table進行合併

table inet proxy {

    chain output {
        type nat hook output priority 10;
        policy accept;

        meta skuid { 1000, 1001 } ip protocol tcp   dnat to 127.0.0.1:10809;
    }

}

4. 完成配置

保存後並重啟

systemctl restart nftables.service