September 8, 2016

How to use curl with a specific network interface

The goal is to direct curl's request to a specific interface, for example, tun0.

Assume tun0 has the IPv4 address of 192.168.15.2. Below is the command line:

mycurl --dns-ipv4-addr 192.168.15.2 --dns-interface tun0 --interface tun0 -4  www.yahoo.com

The default "curl" program in Debian/Ubuntu is not (as is Ubuntu 14.04) compiled with the lib-ares library, which is required for the above arguments to work. You will need to download the lib-ares library first (hosted by curl project), compile it, and then compile your own curl binary.  To configure curl to use your newly installed lib-ares lib, do this:

./configure --enable-ares=/usr/local/

"-4" argument is to tell curl to only use IPv4 IP. Otherwise it will wait for the IPv6 DNS resolving result, which for many sites may not be available and therefore causing curl to hang.

1 comment:

  1. Hi,
    Could you teach me how to Cross Compile PHP 5.5.2 to ARM,I tryed your post
    http://tiebing.blogspot.tw/2010/08/cross-compile-php-533-to-arm.html
    PHP 5.4.2 works fine in FriendlyARM mini2440, thanks a lot.
    But I added jpgraph, the speed is very slow. It takes 90 seconds to draw a bar-chart.
    I need use --enable-opcache in PHP5.5 to speed up.
    Since I tried add phpexpress,APC,xcache to PHP5.4 but fail.
    my e-mail : lithtlk@yahoo.com.tw

    Thank you very much!

    ReplyDelete