使用nftables为指定Linux用户强制使用代理:修订间差异
来自md5.pw
更多语言
更多操作
创建页面,内容为“---- === 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个用户的2个中间版本) | |||
| 第12行: | 第12行: | ||
查看用户id<syntaxhighlight> | 查看用户id<syntaxhighlight> | ||
cat /etc/passwd | cat /etc/passwd | ||
</syntaxhighlight>这里假设我在<code>10809</code>端口开设 | </syntaxhighlight>这里假设我在<code>10809</code>端口开设了Xray的<code>dokodemo-door</code>, 需要将<code>1000</code>与<code>1001</code>的用户id所建立的tcp连接使用代理 | ||
请在合适位置添加或与其它的table进行合并<syntaxhighlight line="1"> | 请在合适位置添加或与其它的table进行合并<syntaxhighlight line="1"> | ||
| 第25行: | 第26行: | ||
} | } | ||
</syntaxhighlight>保存后并重启<syntaxhighlight> | |||
systemctl restart nftables.service | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === 3. 配置sysctl === | ||
保存后并 | <code>sysctl</code> 中需要配置IP转发, 新建一个<code>forward.conf</code>并进行编辑<syntaxhighlight line="1"> | ||
net.ipv4.ip_forward = 1 | |||
net.ipv6.conf.all.forwarding = 1 | |||
</syntaxhighlight>保存好后链接过去, 并让其生效<syntaxhighlight> | |||
ln -f /main/nftables/forward.conf /etc/sysctl.d/ | |||
sysctl --system | |||
</syntaxhighlight> | |||
=== 4. 测试 === | |||
<syntaxhighlight> | |||
su 1000或1001用户名 | |||
curl https://ipinfo.io/ip | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:500 常见应用指南 — Application Guides]] | |||
2026年2月19日 (四) 08:11的最新版本
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端口开设了Xray的dokodemo-door, 需要将1000与1001的用户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;
}
}保存后并重启
systemctl restart nftables.service3. 配置sysctl
sysctl 中需要配置IP转发, 新建一个forward.conf并进行编辑
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1保存好后链接过去, 并让其生效
ln -f /main/nftables/forward.conf /etc/sysctl.d/
sysctl --system4. 测试
su 1000或1001用户名
curl https://ipinfo.io/ip