![Curl --interface 问题](https://linux22.com/image/994900/Curl%20--interface%20%E9%97%AE%E9%A2%98.png)
我尝试为 curl 指定无线接口,但有些事情无法正常工作。
当局域网电缆断开时,它可以按预期工作。当局域网电缆插入时,连接超时。
参见下面的日志,首次尝试插入局域网电缆。
user@user-Latitude-E6410:~/Downloads/ATS$ sudo curl http://speedtest4.ziggo.nl/testfile_20G.bin -o /dev/null --retry 0 --limit-rate 500000 --speed-limit 3000 --speed-time 2 --connect-timeout 5 --interface wlp2s0 --verbose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 212.54.52.11...
* Local Interface wlp2s0 is ip 192.168.2.73 using address family 2
* Local port: 0
* Connected to speedtest4.ziggo.nl (212.54.52.11) port 80 (#0)
> GET /testfile_20G.bin HTTP/1.1
> Host: speedtest4.ziggo.nl
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 20 Oct 2016 20:57:28 GMT
< Server: Apache
< Last-Modified: Tue, 10 Mar 2015 13:29:21 GMT
< ETag: "500000000-510ef23751ccf"
< Accept-Ranges: bytes
< Content-Length: 21474836480
< Content-Type: application/octet-stream
<
^{ [4018 bytes data]
0 20.0G 0 16.1M 0 0 487k 0 11:56:28 0:00:33 11:55:55 488k^C
user@user-Latitude-E6410:~/Downloads/ATS$ sudo curl http://speedtest4.ziggo.nl/testfile_20G.bin -o /dev/null --retry 0 --limit-rate 500000 --speed-limit 3000 --speed-time 2 --connect-timeout 5 --interface wlp2s0 --verbose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 212.54.52.11...
* Local Interface wlp2s0 is ip 192.168.2.73 using address family 2
* Local port: 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0* Connection timed out after 5001 milliseconds
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
* Closing connection 0
curl: (28) Connection timed out after 5001 milliseconds
答案1
您可能需要使用--dns-interface
。
来自手册页:
--dns-interface <interface>
Tell curl to send outgoing DNS requests through <interface>. This option is a counterpart to --interface (which does not affect DNS).
The supplied string must be an interface name (not an address).