可以利用iptables让某用户使用指定IP出口: 先建立用户 比如建立 user1 user2 user3三个用户。 然后执行 cat /etc/passwd #查看用户ID。
假设 user1<=>501 user2<=>502 user3<=>503
那么执行以下命令
- iptables -t mangle -A OUTPUT -m owner --uid-owner 501 -j MARK --set-mark 501
- iptables -t nat -A POSTROUTING -m mark --mark 501 -j SNAT --to-source [IP1]
- iptables -t mangle -A OUTPUT -m owner --uid-owner 502 -j MARK --set-mark 502
- iptables -t nat -A POSTROUTING -m mark --mark 502 -j SNAT --to-source [IP2]
- iptables -t mangle -A OUTPUT -m owner --uid-owner 503 -j MARK --set-mark 503
- iptables -t nat -A POSTROUTING -m mark --mark 503 -j SNAT --to-source [IP3]
复制代码
================== 正确格式: iptables -t mangle -A OUTPUT -m owner --uid-owner 501 -j MARK --set-mark 501 iptables -t nat -A POSTROUTING -m mark --mark 501 -j SNAT --to-source 127.0.0.1
|
Comments NOTHING