bitcoindbitcoin-testnet

I can not connect through RPC port bitcoind


I have set up bitcoind, and I am able to run bitcoin-cli commands, I am also able to make request through RPC.

curl --user username:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332

It also works. But connecting through the public ip just return Connection refused.

curl --user username:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain;' http://public-ip:18332

It returns

curl: (7) Failed to connect to external-ip port 18332: Connection refused

Here is what my bitcoin.config file looks like,

blocksonly=1
prune=1200
rpcauth=username:hash
rpcallowip=0.0.0.0/0

[main]

[test]

[regtest]

The bitcoin node is runnning an ubuntu server and other applications/port allow external connections except all bitcoind RPC ports Is there away to fix this?


Solution

  • The RPC service only binds to the local interface by default.

    Use rpcbind=<ip-addr> in your config if you want to change that.

    However, be aware that exposing the rpc port publicly is a security risk.