Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SO_BINDTODEVICE with curl --interface or CURLOPT_INTERFACE

Running this command as non-root user:

curl --interface tun0 http://google.com -v

SO_BINDTODEVICE tun0 failed with errno 1: Operation not permitted; will do regular bind

setting curl_setopt($ch, CURLOPT_INTERFACE "tun0") in php doesn't work either. But,

ping -I tun0 google.com

works fine, so it's only an issue with curl. And it even works with curl for root, but it really should work for non-root users.

I have an openpvn interface tun0 but the same thing happens with lo interface.

This happens on multiple systems, so is the --interface option just broken in curl or should I use it some other way ? Should I enable something special for curl to be able to use the interface ?

like image 893
jab11 Avatar asked Apr 01 '26 09:04

jab11


1 Answers

I don't think you've interpreted the verbose message correctly.

The --interface option to curl asks it to bind the local end of the socket to a particular IP/network interface.

Binding a socket is done with a normal bind() call.

In addition to the bind() call, linux offers the SO_BINDTODEVICE setsockopt option that is a sort of better and more complete binding to an interface. This call however requires root access to work, which most libcurl using applications won't have and then it'll fail with the above mentioned text in the verbose output.

So, the local binding of the socket works even with that message present. It just didn't work down to the SO_BINDTODEVICE level.

like image 185
Daniel Stenberg Avatar answered Apr 03 '26 22:04

Daniel Stenberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!