Bitcoin Forum
November 18, 2024, 03:18:37 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [SOLVED] Failed to connect to <IP> port 18332: Connection refused (code: 0)  (Read 267 times)
supermoney (OP)
Legendary
*
Offline Offline

Activity: 1161
Merit: 1004



View Profile
June 18, 2019, 09:56:58 AM
Last edit: June 18, 2019, 07:01:10 PM by supermoney
 #1

Good morning,
It's been 2 days I'm not able to send JSON-RPC commands from dedicated server #2 to dedicated server #1 (bitcoind host) because I continue to get CURL error: Failed to connect to <IP> port 18332: Connection refused (status code: 0)
Running on CentOS/CloudLinux 7, tested CURL (method getinfo and validateaddress) from two different Linux servers, tested on Bitcoin Core v0.17 (currently running) and v0.18.
Only localhost is able to send RPC commands with success status 200.

bitcoin.conf:

Code:
listen = 1
server = 1
daemon = 1
testnet = 1
prune = 5000

[test]
onlynet = ipv4
rpcuser = username123
rpcpassword = password456
rpcbind = 0.0.0.0:18332
rpcallowip = 0.0.0.0/0

Port 18332 is open to IPv4 connections (TCP):



supermoney (OP)
Legendary
*
Offline Offline

Activity: 1161
Merit: 1004



View Profile
June 18, 2019, 09:58:33 AM
Last edit: June 18, 2019, 07:04:41 PM by supermoney
 #2

I'm aware I should not use rpcallowip = 0.0.0.0/0 but it's just for testing purposes.
Also, if I don't bind RPC to 0.0.0.0:18332 I get this in debug.log:

Code:
2019-06-18T09:58:10Z Binding RPC on address 0.0.0.0 port 18332 failed.

Windows CURL returns HTTP error 500 internal server error instead of 0: (I know getinfo was removed but in that case I should get HTTP 404 error not found)

Code:
curl -v --user username123:password456 --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://bitcoindServerIP:18332



supermoney (OP)
Legendary
*
Offline Offline

Activity: 1161
Merit: 1004



View Profile
June 18, 2019, 06:45:35 PM
Last edit: June 18, 2019, 07:04:47 PM by supermoney
Merited by bob123 (1), poordeveloper (1)
 #3

I've managed to fix the issue by myself, so here comes the solution:

First of all Windows CURL requires to escape the quotes, from this:

Code:
curl -v --user username123:password456 --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://bitcoindServerIP:18332

To this:

Code:
curl -v --user username123:password456 --data "{\"id\":0, \"method\":\"getblockchaininfo\",\"params\":[]}" -H 'content-type:text/plain;' http://bitcoindServerIP:18332/

Also, in order to establish a connection for sending JSON-RPC commands from remote server I have enabled UDP port 18332 on that external server. Let me also remind you that bitcoind server is only listening to TCP port 18332.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!