Cannot call rpc api from other machine in same local network

2

cannot call rpc api from other machine in same local network

There is a regtest node in my local network , I can call rpc api only from the node's machine,not my local machine.

I know rpcallowip is changed in recent release https://bitcoin.org/en/release/v0.18.0#configuration-option-changes

http clinet httpie

my local machine's ip: 192.168.1.155

btc node's ip: 192.168.1.132

the port 8332 is opened sudo ufw allow 8332.

bitcoind version

$ bitcoind -version                 
# Bitcoin Core Daemon version v0.18.0.0-g2472733a24a9364e4c6233ccd04166a26a68cc65

command start bitcoind

I start regtest , and my ip is 192.168.1.155

bitcoind -regtest -deprecatedrpc=generate -printtoconsole -rpcuser=user -rpcpassword=password -rpcallowip=0.0.0.0/24 -rpcbind=127.0.0.1  -server -rpcport=8332

client request

# request from btc node's machine
http POST http://user:password@127.0.0.1:8332 jsonrpc="2.0" method="getblockchaininfo" id=1
# successed

# request from my local machine 192.168.1.155
http POST http://user:password@192.168.1.132:8332 jsonrpc="2.0" method="getblockchaininfo" id=1
# http: error: ConnectionError: HTTPConnectionPool(host='192.168.1.132', port=8332): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd6e288f438>: Failed to establish a new connection: [Errno 111] Connection refused',)) while doing POST request to URL: http://user:password@192.168.1.132:8332/

Toknsit Toknsit

Posted 2019-10-14T05:54:19.903

Reputation: 25

rpcbind should probably be 0.0.0.0Raghav Sood 2019-10-14T07:42:40.297

@RaghavSood bitcoind -regtest -deprecatedrpc=generate -printtoconsole -rpcuser=user -rpcpassword=password -rpcallowip=0.0.0.0/24 -rpcbind=0.0.0.0 -server -rpcport=8332 still return Failed to establish a new connection.Toknsit Toknsit 2019-10-14T08:03:53.017

Try changing rpcallowip to 192.168.1.155, I believe some (all?) of the RPC options don't accept netmasksRaghav Sood 2019-10-14T08:31:26.133

@RaghavSood It still doesn't work. What's your bitcoind versiosn?Toknsit Toknsit 2019-10-14T08:53:38.980

@ToknsitToknsit I had a simil problem and the problem was the local network, and the example you use more modem to connect?vincenzopalazzo 2019-10-27T21:48:43.533

@vincenzopalazzo I try one week on it and give up .But solve it by an other way: using a proxy to request it from remote.Toknsit Toknsit 2019-10-29T02:46:35.507

@RaghavSood sorry your are right , the netmask is wrong. I use -rpcallowip=192.168.1.155 -rpcbind=127.0.0.1 in Oct 14 , It should be-rpcallowip=192.168.1.155 -rpcbind=0.0.0.0 from Slavik Svyrydiuk's ansower.Toknsit Toknsit 2019-10-30T06:00:19.823

Answers

0

The problem is that you apply wrong options values for -rpcallowip and -rpcbind.

-rpcbind=127.0.0.1

This one tells bitcoind to bind RCP server to 127.0.0.1(localhost). That means it will be available from the same host only.

-rpcallowip=0.0.0.0/24

0.0.0.0/24 means Class C network with IP address range 0.0.0.1 - 0.0.0.254

The correct options in your case are:

-rpcallowip=192.168.1.0/24 -rpcbind=0.0.0.0

or even more secure:

-rpcallowip=192.168.1.155 -rpcbind=192.168.1.132

Slavik Svyrydiuk

Posted 2019-10-14T05:54:19.903

Reputation: 16

0

Finally,I create a proxy to solve it. I am not sure if there is a risk of this code.

https://gist.github.com/toknT/195dc5bf6d5cb6c1cb89cd424ee783bf

var httpProxy = require('http-proxy');
const rpcPort = process.env.RPC_PORT;
const exportPort = process.env.EXPORT_PORT;

httpProxy.createProxyServer({ target: `http://127.0.0.1:${rpcPort}` }).listen(exportPort);

Toknsit Toknsit

Posted 2019-10-14T05:54:19.903

Reputation: 25