Currently geth listens on all interfaces (0.0.0.0:30303). I need to bind the main port 30303 to only a specific network interface in the device, which would normally be accomplished by specifying a local source IP address to bind to. Can this be accomplished?
2 Answers
You need to use the flags --rpc and --rpcaddr to bind the IP address upon execution of geth.
For example, if you wanted to bind 30303 which is the default port to 10.0.2.18, use --rpcaddr 10.0.2.18
When you run geth this is verified in the console with a message saying something like "Http connection established: http://your.ip."
If you need to change the port you can use both flags --rpcaddr 10.0.2.18
and --rpcport 30304
.
-
That seems like it would expose the RPC (control) interface, which is by default only bound to localhost, and change the RPC port, which is 8545 by default, right? I wish to keep RPC bound to localhost and in addition also bind the node P2P listen port (--port) to a specific network interface. Commented Apr 25, 2018 at 19:21
-
Oh yes, you can definitely customize that. I've used 8081 in the past using both localhost and custom IP. Just specify http: // localhost instead of 0.0.0.0. github.com/ethereum/wiki/wiki/JSON-RPC Commented Apr 25, 2018 at 23:29
-
Is --rpcaddr also changing the ip on which geth listens for p2p connections ? Commented Aug 22, 2018 at 21:55
-
@NicolasMassart geth will be exposed to that ip for connections. it is recommended to do this for trusted ip's and nodes Commented Aug 24, 2018 at 22:14
-
@blockstreetboi89 yes but --rpcaddr is only for JSON RPC service or is it also setting P2P discovery service? Commented Aug 25, 2018 at 7:17
I've used this to connect my desktop to my server's geth instance.
HTTP Server:
geth --http --http.port 8545 --http.addr 192.168.1.164 --http.api personal,eth,net --http.corsdomain '*'
Client:
geth attach http://192.168.1.164:8545
WS Server:
geth --ws --ws.port 8546 --ws.addr 192.168.1.164 --ws.api eth,net,web3 --ws.origins '*'
Client:
geth attach ws://192.168.1.164:8546