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 Below is the command line:

mycurl --dns-ipv4-addr --dns-interface tun0 --interface tun0 -4

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
    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 :

    Thank you very much!