linux - connman:一次自动连接到多个以太网接口(interface)

标签 linux networking dhcp connman

非常简单的用例:我有两个以太网接口(interface),都应该使用 DHCP 连接。默认路由是哪一条并不重要,因为它只是一种专用的概念验证设置。但是,热插拔必须适用于两个接口(interface)(其中之一是 CDC-NCM 连接)。

connman 1.17 似乎只尝试与其中一个接口(interface)建立连接。如果我拔掉此连接,则会在第二个接口(interface)上启动 DHCP,并且一切都会继续工作。我总是可以通过手动使用“connmanctl connect”来连接第二个接口(interface)。但是……

…有没有办法配置 connman 通过 DHCP 自动连接到两个网络?

最佳答案

is there any way to configure connman to connect AUTOMATICALLY to both networks via DHCP?

默认情况下,大多数 DHCP 服务器都配置为向客户端发出默认路由。如果你得到两个默认路由,Linux 网络堆栈就不可能正常工作。

由于您希望两个网络上的 DHCP 客户端都能正常工作,因此您能做的最好的事情也许就是扫描系统路由表并删除默认路由之一。

通常您会使用 netstat -rn 来查找重复的默认值...

[mpenning@tsunami micro]$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.1.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
172.16.2.0      0.0.0.0         255.255.255.0   U         0 0          0 eth1
239.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 eth0
0.0.0.0         172.16.1.1      0.0.0.0         UG        0 0          0 eth0 <--
0.0.0.0         172.16.2.1      0.0.0.0         UG        0 0          0 eth1 <--
[mpenning@tsunami micro]$

然后删除其中一个...

[mpenning@tsunami micro]$ sudo route del default dev eth1
[mpenning@tsunami micro]$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.1.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
172.16.2.0      0.0.0.0         255.255.255.0   U         0 0          0 eth1
239.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 eth0
0.0.0.0         172.16.1.1      0.0.0.0         UG        0 0          0 eth0
[mpenning@tsunami micro]$

编写一个 shell 脚本来检查这个问题并不难。然而,更好的解决方案是在其中一个网络上获取静态地址,这样您就不必管理 DHCP 问题。

关于linux - connman:一次自动连接到多个以太网接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20327541/

相关文章:

linux - 如何阻止直接访问我在 Apache 中的自定义 404 页面?

java - 在Linux中添加JDK运行IDEA

linux - 将多个输入通过管道传输到 Ghostscript

objective-c - 如何使用 AFNetworking 设置超时

CentOS 7.2 无法启动dhcpd

java - Linux 中的 Sqlite java.lang.UnsatisfiedLinkError

linux - Docker 网络接口(interface)未释放到主机 namespace

networking - 为什么WebRTC需要ICE协议(protocol)才能运行?

vagrant - 有没有办法使用 Virtualbox 由 DHCP 分配的 VagrantFile 中的 IP 地址?

macos - Mac OS X 中的 DHCP 设置