1
curl
can use non-default network interface with its --interface
option theoretically. However, in practise it doesn't work.
I have 2 network interfaces eth0
and eth1
. Each one is connected to Internet via its own router and uses DHCP for autoconfiguration. Lets say eth0
IP is ip0
and eth1
IP is ip1
.
So, I set eth0
as default connection via /etc/sysconfig/network-scripts
and run following command:
curl --url "http://ip-api.com/json"
I get JSON reply where I see that actual external IP is ip0
. Now I set eth1
instead of eth0
as default interface, and the same command returns me ip1
.
Now I set eth0
as default IP again and run following command:
curl --url "http://ip-api.com/json" --interface "eth0"
No problems, it returns ip0
.
And finally:
curl --url "http://ip-api.com/json" --interface "eth1"
results in following error:
curl: (7) couldn't connect to host
As we can see from previous test (where eth1
was default interface), eth1
has not issues. It is very reliable wired connection actually, so the issue is not related to any network stability problems.
My routing table follows:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.85.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
192.168.182.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
169.254.0.0 0.0.0.0 255.255.0.0 U 1004 0 0 eth2
0.0.0.0 192.168.182.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.85.1 0.0.0.0 UG 1 0 0 eth1
Can anyone explain why curl doesn't work with non-default interface?
Please show you routing table – Gerald Schneider – 2017-06-23T06:53:47.267