NodeJS "http" localAddress 无法在多个网络接口上使用同一子网

NodeJS "http" localAddress not working with same subnet on multiple network interfaces

我在使用 2 个硬件以太网接口的嵌入式系统 (Ubuntu 14.04) 上工作,它们都有一个 Link-本地地址别名,如您在此处看到的(使用 ip a ):

eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 3000
    link/ether 00:1e:2d:00:40:6d brd ff:ff:ff:ff:ff:ff
    inet 10.251.25.206/24 brd 10.251.25.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet 169.254.11.1/16 scope global eth1
       valid_lft forever preferred_lft forever
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc htb qlen 3000
    link/ether 00:1e:2d:00:40:6c brd ff:ff:ff:ff:ff:ff
    inet 192.43.182.23/20 brd 192.43.191.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 169.254.10.1/16 scope global eth0
       valid_lft forever preferred_lft forever

一些摄像头连接在两个接口上,每个都有一个link-本地地址,我需要向所有摄像头发送http请求,但我使用官方发送http请求时遇到问题http NodeJS 模块到这些相机(实际上我也尝试过 request module,但它不起作用)。 request 函数的选项 localAddress 允许使用正确的 interface/address,但是,当两个接口具有相同的子网时它不起作用(此处为 link-local) .

假设我的系统没有 link-本地别名,并且我们在每个接口上连接了 1 个摄像头:

现在让我们按照以下步骤操作:

出现的错误是EHOSTUNREACH。

我做错了什么吗?那是一个错误吗?是 Linux/IP 的限制吗?我怎样才能在不使用 delete/create 别名的情况下向两个 eth 发送请求?

使用 tcpdump 我可以看到谁有没有得到答复的请求:

08:54:31.236974 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28
08:54:32.283507 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28
08:54:33.307486 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28
08:55:02.383014 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28
08:55:03.387588 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28
08:55:04.411586 ARP, Request who-has 169.254.11.50 tell 169.254.11.1, length 28

但是 ping -I eth0 169.254.10.50ping -I eth1 169.254.11.50 同时使用网络接口中设置的两个别名。

谢谢

我找到了通过修改路由使其工作的方法 tables/rules。

以下是我为使其工作所做的工作:

  • 首先我添加了2个tables lla_eth0lla_eth1('lla'代表link-本地地址):
# echo -e "1\tlla_eth0" >> /etc/iproute2/rt_tables
# echo -e "2\tlla_eth1" >> /etc/iproute2/rt_tables

请注意,数字“1”和“2”是 table 的 ID,它们应该是唯一的,在我的例子中没有使用它们。

  • 然后在每个 table 上,我想将网络 169.254.0.0/16 中的每个目标地址路由到它们相应的接口:
# ip route add 169.254.0.0/16 dev eth0 table lla_eth0
# ip route add 169.254.0.0/16 dev eth1 table lla_eth1
  • 最后,我设置了 2 条规则,每次使用源 169.254.10.1 时我们使用 table lla_eth0,类似地使用 169.254.11.1 和 lla_eth1 :
# ip rule add from 169.254.10.1 table lla_eth0
# ip rule add from 169.254.11.1 table lla_eth1