How to configure Cassandra in GCP to remotely connect?

Author: Anbunathan

Originally Sourced from:

I am following the below steps to install and configure Cassandra in GCP. It works perfectly as long as working with Cassandra within GCP.

$java -version
$echo "deb 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
$curl | sudo apt-key add -
$sudo apt install apt-transport-https
$sudo apt-get update
$sudo apt-get install cassandra
$sudo systemctl status cassandra
//Active: active (running)
$nodetool status
//Datacenter: datacenter1
$tail -f /var/log/cassandra/system.log

$find /usr/lib/ -name cqlshlib
$export PYTHONPATH=/usr/lib/python3/dist-packages
$sudo nano ~/.bashrc
export PYTHONPATH=/usr/lib/python3/dist-packages
$source ~/.bashrc
$python --version
//it opens cqlsh shell

But I want to configure Cassandra to remotely connect.

I tried the following 7 different solutions.

But still I am getting the error.

1.In GCP,
VPC network -> firewall -> create
port tcp=9000,9042,8088,9870,8123,8020, udp=9000
tag = hadoop
Add this tag in VMs
2.rm -Rf ~/.cassandra
3.sudo nano ~/.cassandra/cqlshrc
hostname =
port = 9042
4. cqlsh -u cassandra -p cassandra
5. firewall - open ports
6. Get rid of this line: JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=localhost"
Try restart the service: sudo service cassandra restart
If you have a cluster, make sure that ports 7000 and 9042 are open within your security group.
7. you can set the environment variable $CQLSH_HOST= Then simply type cqlsh.
sudo nano /etc/cassandra/cassandra.yaml
listen_address: localhost
sudo service cassandra restart
sudo nano ~/.bashrc
export CQLSH_HOST=
source ~/.bashrc
sudo systemctl restart cassandra
sudo service cassandra restart
sudo systemctl status cassandra
nodetool status

Please suggest how to get rid of the following error

Connection error: ('Unable to connect to any servers', {'': ConnectionRefusedE
rror(111, "Tried connecting to [('', 9042)]. Last error: Connection refused")})