CURLOPT_INTERFACE(3)
π CURLOPT_INTERFACE(3) β aka "pick your outgoing vibe" β¨
okay bestie, so this one's from the libcurl Library Functions Manual and it's literally about choosing which network interface your traffic leaves from. it's giving "main character picks her own exit" energy π
β¨ NAME β¨
CURLOPT_INTERFACE β the source interface for your outgoing traffic π¦
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERFACE, char *interface);
β¨ DESCRIPTION β¨
so you pass in a char pointer as the parameter, and it sets the interface name to use as the outgoing network interface. easy!! the name can be an interface name, an IP address, or a hostname. and if you're feeling picky and want to be explicit about which of those you mean, there are these special prefixes you can slap on the front:
if!<name>β interface name πhost!<name>β IP address or hostname πΈifhost!<interface>!<host>β interface name and IP address or hostname together π«Ά
β οΈ if you specifyif!orifhost!but the parameter doesn't match an existing interface, you getCURLE_INTERFACE_FAILEDback from whichever libcurl function you used to actually do the transfer. sad but true π
ok so important thing: libcurl does not support using network interface names for this option on Windows. ngl, that's just how it is π
and we strongly advise against specifying the interface with a hostname, because it makes libcurl do a blocking name resolve call to get the IP address. also β that name resolve operation does not use DNS-over-HTTPS even if CURLOPT_DOH_URL(3) is set. so like, yeah, don't do that π
good news though: the application does not have to keep the string around after setting this option. set it and forget it, slay β¨
also if you use this option multiple times, the last set string overrides the previous ones. and setting it to NULL disables its use again. periodt π
β¨ DEFAULT β¨
NULL, which means: use whatever the TCP stack finds suitable π
β¨ PROTOCOLS β¨
this functionality affects all supported protocols, no cap π
β¨ EXAMPLE β¨
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
curl_easy_setopt(curl, CURLOPT_INTERFACE, "eth0");
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
β¨ HISTORY β¨
- the
if!andhost!syntax was added in 7.24.0 π - the
ifhost!syntax was added in 8.9.0 π¦
β¨ AVAILABILITY β¨
added in curl 7.3 π
β¨ RETURN VALUE β¨
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK β
β non-zero means an error occurred π, see libcurl-errors(3).
β¨ SEE ALSO β¨
k that's the whole thing bestie, go pick your interface and thrive ππ β this lil page is from libcurl, dated 2026-10-12, mwah π«Ά
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms