小编Vit*_*lii的帖子

为什么在 CentOS 6 中,curl 不能与非默认网络接口一起使用?

curl理论上可以使用非默认网络接口及其--interface选项。然而,在实践中却行不通。我有 2 个网络接口eth0eth1. 每台设备都通过自己的路由器连接到互联网,并使用 DHCP 进行自动配置。可以说eth0IP 是ip0eth1IP 是ip1。因此,我eth0通过设置为默认连接/etc/sysconfig/network-scripts并运行以下命令:

curl --url "http://ip-api.com/json"
Run Code Online (Sandbox Code Playgroud)

我收到 JSON 回复,其中我看到实际的外部 IP 是ip0。现在我将其设置eth1eth0默认界面,并且相同的命令返回 me ip1

现在我eth0再次设置为默认 IP 并运行以下命令:

curl --url "http://ip-api.com/json" --interface "eth0"
Run Code Online (Sandbox Code Playgroud)

没问题,它返回ip0

最后:

curl --url "http://ip-api.com/json" --interface "eth1"
Run Code Online (Sandbox Code Playgroud)

导致以下错误:

卷曲:(7)无法连接到主机

正如我们从之前的测试中看到的(eth1默认界面在哪里),eth1没有问题。实际上,这是非常可靠的有线连接,因此该问题与任何网络稳定性问题无关。

我的路由表如下:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric …
Run Code Online (Sandbox Code Playgroud)

linux centos routing curl

3
推荐指数
1
解决办法
3792
查看次数

标签 统计

centos ×1

curl ×1

linux ×1

routing ×1