4

I have geth running on local network (separate machine). curl'ing to http://localhost:8545 works just fine. How do I curl to that geth node from another machine on my private network? Curling to http://10.x.x.x:8545 just returns connection refused.

geth itself is all up and running on the other 10.x.x.x machine just fine and geth attach, curl, etc all work on localhost on that box.

e.g. this works:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://localhost:8545

result: ➜  {"jsonrpc":"2.0","id":67,"result":"Geth/v1.9.17-unstable-5b081ab2-20200714/darwin-amd64/go1.13.6"}


this fails (from another machine on that private network):

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://10.x.x.x:8545

result ➜ curl: (7) Failed to connect to 10.x.x.x port 8545: Connection refused

(using real IP's instead of x's of course)

Both nodes communicate just fine otherwise (ssh, browse websites, file sharing, etc...)

Badr Bellaj
  • 11,560
  • 2
  • 43
  • 44
Adivate
  • 361
  • 2
  • 13

2 Answers2

4

You'll need to enable --rpcaddr flag to accept connection. from somewhere/anywhere, --wsaddr flag for websocket connections.

Example:

$ geth --rpc --rpcaddr 0.0.0.0
$ geth --rpc --wsaddr 0.0.0.0
$ geth --rpc --rpcaddr 0.0.0.0 --wsaddr 0.0.0.0

This allows you to geth to accept connections from any interface and network. You can geth attach, curl, web3 provider.

Ming
  • 729
  • 3
  • 10
1

You'll need to enable RCP to accept a connection.

Flags such as --rpc --rpcaddr are deprecated. just use --http and --http.addr instead.

geth --http --http.addr 0.0.0.0
Mostafa Barmshory
  • 1,849
  • 24
  • 39