Author

Topic: Can't get bitcoind to accept RPC connections from other machines (Read 5277 times)

newbie
Activity: 14
Merit: 0
newbie
Activity: 10
Merit: 0
Glad to hear it, happy mining!
newbie
Activity: 5
Merit: 0
Nacsiar - thanks for your reply.

My client was failing to connect because of a firewall issue, and I thought the problem was with bitcoind because netstat wasn't showing it listenting on IPv4 port 8332.
It turns out that bitcoind was listening on a joint IPv4/6 socket on port 8332, it was just that netstat shows this joint socket as tcp6.

If you don't set rpcallowip then separate IPv4 and IPv6 ports are opened (as you have shown).

If you set rpcallowip (e.g. rpcallowip=*) then a single joint IPv4/6 port is opened. This works fine, but netstat shows it as tcp6 only, and the difference in behaviour confused me.

I've got my client/server working now without any changes to bitcoind.
newbie
Activity: 10
Merit: 0
Code:
user@server:~$ netstat -lp | grep bitcoind
tcp        0      0 localhost:8332          *:*                     LISTEN      32153/bitcoind
tcp        0      0 *:8333                  *:*                     LISTEN      32153/bitcoind
tcp6       0      0 localhost:8332          [::]:*                  LISTEN      32153/bitcoind
tcp6       0      0 [::]:8333               [::]:*                  LISTEN      32153/bitcoind
As you can see, the RPC port (8332) is only listening for local connections, as expected.
I'm not seeing this at all (localhost is just the source in general). Looks like it's listening just fine.

What firewall are you using? do you have iptables enabled (I assume not since you say others are connecting fine)? It sounds more like your gateway not forwarding ports from your external IP.
newbie
Activity: 28
Merit: 0
I dont understand this code..
newbie
Activity: 5
Merit: 0
It turns out I was confused by the netstat output. It marks joint IPv4/6 sockets as tcp6
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453272

bitcoind was listening on IPv4 socket 8332 all along, but my client was failing to connect for other reasons.

With the IPv4 client able to connect on port 8332, my netstat output is:
Code:
user@server:~$ netstat -lp | grep bitcoind
tcp        0      0 *:8333                  *:*                     LISTEN      7574/bitcoind
tcp6       0      0 [::]:8332               [::]:*                  LISTEN      7574/bitcoind
tcp6       0      0 [::]:8333               [::]:*                  LISTEN      7574/bitcoind
newbie
Activity: 28
Merit: 0
goodluck solving your problem
newbie
Activity: 14
Merit: 0
newbie
Activity: 28
Merit: 0
Im having trouble understanding any of this code..
newbie
Activity: 5
Merit: 0
I've had a look at the code in bitcoinrpc.cpp, specifically the function StartRPCThreads().

The code attempts to open an IPv6 socket and then set the 'v6_only' option to false if the 'rpcallowip' option is used. This should cause the socket to listen for IPv4 connections, but on my system netstat doesn't show a listening IPv4 socket (see my original post).

If the socket failed to open, or the 'rpcallowip' option is not used, the code opens a separate IPv4 socket. This means that when 'rpcallowip' is not used, separate IPv4 and IPv6 sockets are always used.

When I modify the code (by setting fListening to false), so that it tries to open the IPv4 socket after opening the IPv4/IPv6 socket, I get the error:
Error: An error occurred while setting up the RPC port 8332 for listening on IPv4: Address already in use
which indicates that the combined IPv4/IPv6 socket is listening, although netstat doesn't show this.

When I modify the code (by forcing set_option(v6_only(true)) and removing the if( !fListening... ) line), so that it always opens separate IPv4 and IPv6 sockets, things work as I expect them to:
Code:
user@server:~$ netstat -lp | grep bitcoind
tcp        0      0 *:8332                  *:*                     LISTEN      3063/bitcoind
tcp        0      0 *:8333                  *:*                     LISTEN      3063/bitcoind
tcp6       0      0 [::]:8332               [::]:*                  LISTEN      3063/bitcoind
tcp6       0      0 [::]:8333               [::]:*                  LISTEN      3063/bitcoind

I assume that the IPv4/IPv6 socket just works on most systems. Unfortunately I can't see a work-around for systems like mine without recompiling bitcoind.

Here are the changes I made:
Code:
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index c99b74f..ba7f462 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -791,8 +791,8 @@ void StartRPCThreads()
         acceptor->open(endpoint.protocol());
         acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));

-        // Try making the socket dual IPv6/IPv4 (if listening on the "any" address)
-        acceptor->set_option(boost::asio::ip::v6_only(loopback), v6_only_error);
+        // This is an IPv6 only socket
+        acceptor->set_option(boost::asio::ip::v6_only(true), v6_only_error);

         acceptor->bind(endpoint);
         acceptor->listen(socket_base::max_connections);
@@ -807,8 +807,7 @@ void StartRPCThreads()
     }

     try {
-        // If dual IPv6/IPv4 failed (or we're opening loopback interfaces only), open IPv4 separately
-        if (!fListening || loopback || v6_only_error)
+        // This is an IPv4 socket
         {
             bindAddress = loopback ? asio::ip::address_v4::loopback() : asio::ip::address_v4::any();
             endpoint.address(bindAddress);
full member
Activity: 153
Merit: 100
I'm having this same issue.
newbie
Activity: 5
Merit: 0
I'm running bitcoind on a headless Debian 6.0 machine with the following bitcoin.conf, and the option '-daemon'
Code:
rpcuser=bitcoinrpc
rpcpassword=randompassword
It is successfully communicating with other nodes (currently 8 connections, and it has 229376 blocks). It is listening on ports 8332 and 8333:
Code:
user@server:~$ netstat -lp | grep bitcoind
tcp        0      0 localhost:8332          *:*                     LISTEN      32153/bitcoind
tcp        0      0 *:8333                  *:*                     LISTEN      32153/bitcoind
tcp6       0      0 localhost:8332          [::]:*                  LISTEN      32153/bitcoind
tcp6       0      0 [::]:8333               [::]:*                  LISTEN      32153/bitcoind
As you can see, the RPC port (8332) is only listening for local connections, as expected. I want to modify this to allow other machines to connect. The server is behind a firewall, so a wildcard is acceptable. I have tried modifying bitcoin.conf as follows:
Code:
rpcuser=bitcoinrpc
rpcpassword=randompassword
rpcallowip=*
but with this configuration bitcoind no longer listens on 8332 ipv4 at all:
Code:
user@server:~$ netstat -lp | grep bitcoind
tcp        0      0 *:8333                  *:*                     LISTEN      6981/bitcoind
tcp6       0      0 [::]:8332               [::]:*                  LISTEN      6981/bitcoind
tcp6       0      0 [::]:8333               [::]:*                  LISTEN      6981/bitcoind
I have also tried various combinations of the lines:
Code:
rpcallowip=*.*.*.*
rpcallowip=192.168.1.3
rpcport=8332
with the same result.

The log doesn't show any obvious reason. It includes the following lines:
Code:
Bound to [::]:8333
Bound to 0.0.0.0:8333
ThreadRPCServer started

Any ideas why bitcoind isn't listening on port 8332 when I specify rpcallowip?
I have seen this question on the forum a couple of times, but it either remains unsolved (https://bitcointalksearch.org/topic/bitcoind-debian-rpc-cant-listen-159504), or the problem was something simple like a firewall or misspelling (http://stackoverflow.com/questions/6018304).
I would like to allow other machines on my network to connect as miners (using poclbm).
Jump to: