Web3.js: RPC call issue with domain name as host

Created on 27 Mar 2018  路  4Comments  路  Source: ChainSafe/web3.js

I'm getting following error (Base path of file is replaced with <>) -

Error: Invalid JSON RPC response: "invalid host specified\n"
    at Object.InvalidResponse (<>/node_modules/web3/lib/web3/errors.js:38:16)
    at HttpProvider.send (<>/node_modules/web3/lib/web3/httpprovider.js:91:22)
    at RequestManager.send (<>/node_modules/web3/lib/web3/requestmanager.js:58:32)
    at Eth.get [as gasPrice] (<>/node_modules/web3/lib/web3/property.js:107:62)
    at Object.getGasPrice (<>/helpers/ether.helper.js:43:31)

When making any RPC call, if my Host in provider is a domain.

const etherAddress = "http://ethernode:8545";
const provider = new Web3.providers.HttpProvider(etherAddress);

In my /etc/hosts file

...
192.168.23.33 ethernode  # Random IP
...

But, If I'm changing the ether address to "http://192.168.23.33:8545", all the methods are working as expected.

Is there any configuration that I'm missing?

Here is how my geth is running -

./geth --rpc --rpcaddr "0.0.0.0" --rpccorsdomain "*" --datadir /crypto/geth

Most helpful comment

Hi, I have just noticed the same behavior for a configuration that was working several months ago.
My config was not far from yours
I am now using last version of ethereum geth, and it seems there is another parameter to provide :
--rpcvhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
I haven't made the test yet but I hope this will correct your issue (and also mine :-) )
Happy easter !

All 4 comments

Hi, I have just noticed the same behavior for a configuration that was working several months ago.
My config was not far from yours
I am now using last version of ethereum geth, and it seems there is another parameter to provide :
--rpcvhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
I haven't made the test yet but I hope this will correct your issue (and also mine :-) )
Happy easter !

@stephgou is correct, you need to configure the whitelist the domain in the rpc. I wouldn't recommend '*' for security reasons..

I just ran across this thread which seems incoherent. I encountered the same problem as the OP, i.e., the RPC interface returns "invalid host specified\n"

The problem is overcome by omitting/bypassing DNS reference and directly specifying the server IP address in the client request. The failure is exhibited regardless of the geth option: --rpcvhosts '*', which I interpret as a filter for the client ID, not the server ID. I am unable (as yet) to successfully issue requests that identify a server by DNS name.

I am using web3py.

@ElectricBill run into this too. did you find any solution for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dzarezenko picture dzarezenko  路  3Comments

webersson picture webersson  路  3Comments

FradSer picture FradSer  路  3Comments

connectdotz picture connectdotz  路  3Comments

joeriexelmans picture joeriexelmans  路  3Comments