scorpion35
scorpion35

Reputation: 1084

Vagrant/Redis - Cannot connect from host

Still getting the hang of Vagrant/Redis/Linux. Please help! The issue is I cannot connect to redis server running on VM.

Host: Macbook

Vagrantfile:

config.vm.box = "laravel/homestead"
config.vm.hostname="redis-test"
config.vm.network "forwarded_port", guest: 6379, host: 6379, id: "redis"

Guest: laravel/homestead Vagrant box.

/etc/redis/redis.conf

bind 0.0.0.0

After changing redis.conf, I also restarted the service

sudo /etc/init.d/redis-server restart
(AND also) sudo service redis-server restart

Also made sure ufw is disabled

sudo ufw disable
sudo ufw status

Status: inactive

If I run redis-cli -h redis-test ping, I get pong, and can access redis as usual (on the guest VM)


Now back on the host machine (macbook), I cannot access redis-server.

redis-cli -h redis-test ping

Could not connect to Redis at redis-test:6379: nodename nor servname provided, or not known

Can someone help me connect to redis-server on vagrant box, please? Any help is greatly appreciated!

Upvotes: 1

Views: 2760

Answers (1)

nickgryg
nickgryg

Reputation: 28733

You forwarded redis port 6379 from host machine to redis-test VM, but host machine knows nothing about redis-test domain you are trying to connect to.

You can connect redis on redis-test VM from host machine in two ways:

1.

connect to localhost, because redis port is already forwarded to redis on redis-test VM:

redis-cli -h localhost ping

2.

add redis-test to /etc/hosts:

echo '127.0.0.1 redis-test' >> /etc/hosts

and you can connect redis the way you used:

redis-cli -h redis-test ping

Upvotes: 1

Related Questions