打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

使用nftables为指定Linux用户强制使用代理

来自md5.pw
Koud Wind留言 | 贡献2026年2月19日 (四) 07:01的版本 (创建页面,内容为“---- === 1. 准备 === 确保 nftables 已经安装, 且本地有透明代理端口 (比如Xray的<code>dokodemo-door</code>), 这里就不注重如何开设透明代理<syntaxhighlight> nft --version </syntaxhighlight>若没有安装, 以Debian13为例<syntaxhighlight>apt update apt install nftables systemctl enable nftables</syntaxhighlight>拷贝原有的nftables配置, 到一个好找的目录里, 以 <code>/main/nftables</code> 为例, 再对原路径进…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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