系统相关
首页 > 系统相关> > linux – 配置使用特定NIC的进程

linux – 配置使用特定NIC的进程

作者:互联网

我有两个NIC(一个以太网和一个来自移动设备的网络共享).我的以太网互联网连接是端口过滤的,所以我不能使用某些应用程序.所有应用程序都可以在我的移动网络共享上运行,但由于我只有有限的数据,我只希望某些选定的应用程序使用该网卡.

所以问题是:我怎样才能强制某些进程使用特定的NIC?

解决方法:

基本上你想要“监禁”你的进程并强制它绑定到特定的NIC.很多人使用LD_PRELOAD但LD_PRELOAD不控制进程使用的路由.它将使用第一条路线.一个可能的解决方案是在SuperUser https://superuser.com/questions/241178/how-to-use-different-network-interfaces-for-different-processes/241215#241215

ip netns可以做到这一点.

TL; DR:创建网络命名空间,将接口与它们关联,然后运行“ip netns exec NAME cmd …”

只检查你的发行版是否支持ip netns …(Backtrack 5r3不支持,而Kali支持;))

更多细节:

#create netns
ip netns add myNamespace
#link iface to netns
ip link set eth0 netns myNamespace
#set ip address in namespace
ip netns exec myNamespace ifconfig eth0 192.168.0.10/24 up
#set loopback (may be needed by process run in this namespace)
ip netns exec myNamespace ifconfig lo 127.0.0.1/8 up
#set route in namespace
ip netns exec myNamespace route add default gw 192.168.0.1
#force firefox to run inside namespace (using eth0 as outgoing interface and the route)
ip netns exec myNamespace firefox

标签:linux,networking,process,network-interface
来源: https://codeday.me/bug/20190814/1653606.html