能否限定某个应用程序的出局流量走某一个网卡?

2016-09-28 11:58:14 +08:00
 ioiioi

有个应用程序的配置文件中未提供 outbound interface 的选项,那还有没有可能在 linux 中限定该应用程序 outbound interface ?

3017 次点击
所在节点    Linux
8 条回复
facat
2016-09-28 12:26:52 +08:00
配置 iptables
ls2110609
2016-09-28 12:28:59 +08:00
python 可以
LukeXuan
2016-09-28 12:34:17 +08:00
记得 iptables 可以按照用户 id 配置
jimzhong
2016-09-28 12:54:55 +08:00
思路应该是用特定的用户运行这个程序,然后在 iptables 里面打 mark ,再用 ip rule 加一个专用的路由表
chinawrj
2016-09-28 13:19:39 +08:00
iptables -t mangle -I OUTPUT -m owner --uid-owner 1000 -j MARK --set-mark 0x88

ip rule add fwmark 0x88 table 250
ip route add default via 192.168.1.1 dev eth0 table 250


核心策略都在这里。更多具体问题可以南京现场支持。PS:我是业余爱好者,不收费:)
csdreamdong
2016-09-28 13:32:58 +08:00
ip netns *** exec ****
创建两个 namespace ,分别把两个 eth 加进去。

namespace 大法好
ioiioi
2016-09-29 22:46:39 +08:00
@jimzhong @chinawrj @csdreamdong
抱歉,在帖子的正文中描述的不是很清楚。实际上我想运行的进程是一个叫 tincd 的 mesh vpn 。

我有两台网关,这两台网关通过 keepalived 来实现 HA , vip 将在两台网关中浮动。
当 vip 在网关 1 上时, tincd 将自动启动,并且监听该 vip ,并且出局的 source ip 也必须为该 vip 。

由于是在 keepalived 中,所以 vip 跟物理网卡上的 ip 是同一个网段。
ioiioi
2016-09-29 22:47:35 +08:00
@chinawrj
谢谢,但我不在南京,仍然送 10 个铜币,谢了!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/309475

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX