You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Does not use bind to local address for outgoing connections #6476
I have several IPv4 / IPv6 addresses on a host and I wish to use a specific one. So I set up the bind so it would use that. It seems to be using that for the bind() in the listen socket but not for the outgoing connections.
I've tried settings externalip. That only seems to change the "localaddresses" returned by getnetworkinfo. I'm guessing that's mostly useful for NAT.
Right, there is no option to specify binding for outgoing connections.
I'd be OK with a per-network (IPv4/IPv6) setting that specifies this.
Be aware that enforcing this at application level is, in practice, impossible to make watertight - e.g. impossible for DNS lookups. So if this is for security or privacy reasons I'd strongly recommend to do this at the OS level (eg by giving a certain user only access to certain network interface).
@phatkiller: The issue is still open that's a sign that nobody has implemented it right now. We don't have a timeframe for features. Bitcoin-Core is an open source project, it will only be implemented if someone invests time to implement a such feature (which mostly is a sign that someone requires that feature).
What is required is to bind the socket to the -bind address prior to connecting to the remote site, not the usual way this would be done. I've looked at the code in net.cpp and netbase.cpp and boost appears to be in use and the location of the -bind ip constant is not obvious to me. I'm not skilled with c++. Here's a rough outline of what needs to be done but I don't have the skill to do it in the cpp environment. Perhaps someone else will pick up this thread.
Found this doing research on the issue.
No error checking.
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
// Bind to a specific network interface (and optionally a specific local port)
struct sockaddr_in localaddr;
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = inet_addr("192.168.1.100");
localaddr.sin_port = 0; // Any local port will do
bind(sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr));
This can't be fixed through a routing table because it's not about return packets for incoming connections but for packets that are for connections initiated by the process itself, which if not bindable to a specific IP (as per this request) will just use the hosts' default IP (which may not be the IP where incoming packets arrive). So not that unusual of a request, I had to dockerize and apply some iptables magic to make this work right on a node with multiple IPs within the same subnet.
Well, I still interested in it. It is a logical thing to do in general.
I think people uses some workarounds for this when they need this, but have native behavior is right thing to do.
Also, as the score is set by address, having multiple outgoing addresses means that the score of your node will be all over the place depending on which address other nodes know you by. I think it's reasonable to add an option to set the outgoing ipv6 address.
Activity
laanwj commentedon Jul 27, 2015
Right, there is no option to specify binding for outgoing connections.
I'd be OK with a per-network (IPv4/IPv6) setting that specifies this.
Be aware that enforcing this at application level is, in practice, impossible to make watertight - e.g. impossible for DNS lookups. So if this is for security or privacy reasons I'd strongly recommend to do this at the OS level (eg by giving a certain user only access to certain network interface).
kroeckx commentedon Jul 31, 2015
I don't care about things like DNS, I would just like the bitcoin traffic itself to go over the addresses I select.
sipa commentedon Jul 31, 2015
phatkiller commentedon May 2, 2016
Has this been implemented ? If not is there a timeframe for it ?
jonasschnelli commentedon May 2, 2016
@phatkiller: The issue is still open that's a sign that nobody has implemented it right now. We don't have a timeframe for features. Bitcoin-Core is an open source project, it will only be implemented if someone invests time to implement a such feature (which mostly is a sign that someone requires that feature).
laanwj commentedon May 4, 2016
If you need this, you need to make sure it gets implemented yourself. This is not a place to get free (as in beer) development resources.
mrobinton commentedon Oct 2, 2019
What is required is to bind the socket to the -bind address prior to connecting to the remote site, not the usual way this would be done. I've looked at the code in net.cpp and netbase.cpp and boost appears to be in use and the location of the -bind ip constant is not obvious to me. I'm not skilled with c++. Here's a rough outline of what needs to be done but I don't have the skill to do it in the cpp environment. Perhaps someone else will pick up this thread.
Found this doing research on the issue.
No error checking.
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
// Bind to a specific network interface (and optionally a specific local port)
struct sockaddr_in localaddr;
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = inet_addr("192.168.1.100");
localaddr.sin_port = 0; // Any local port will do
bind(sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr));
ryanofsky commentedon Oct 3, 2019
This seems like an unusual request. Do you need bitcoin to use different outgoing IP address than other applications on the system? Or to connect from a different IP address than it it listens on? If not, it seems like you could be better off just fixing the routing table: https://serverfault.com/questions/182550/specifing-ip-address-for-outbound-connections-on-a-multi-ip-host
infernix commentedon Oct 4, 2019
This can't be fixed through a routing table because it's not about return packets for incoming connections but for packets that are for connections initiated by the process itself, which if not bindable to a specific IP (as per this request) will just use the hosts' default IP (which may not be the IP where incoming packets arrive). So not that unusual of a request, I had to dockerize and apply some iptables magic to make this work right on a node with multiple IPs within the same subnet.
Nyanraltotlapun commentedon Nov 16, 2021
I feel that this is needed for avoiding mess up with IPv6 privacy randomized addresses.
vasild commentedon Aug 5, 2023
This request looks reasonable. Is there still interest in it?
Something like this should do it (and pass the proper argument to
ConnectSocketDirectly()untested):Nyanraltotlapun commentedon Aug 6, 2023
Well, I still interested in it. It is a logical thing to do in general.
I think people uses some workarounds for this when they need this, but have native behavior is right thing to do.
mahdibx commentedon Apr 16, 2025
Also, as the score is set by address, having multiple outgoing addresses means that the score of your node will be all over the place depending on which address other nodes know you by. I think it's reasonable to add an option to set the outgoing ipv6 address.
6 remaining items
net: add -outboundbind option for outgoing source address
net: add -outboundbind option for outgoing source address
net: add -outboundbind option for outgoing source address