Search code examples
redisvagrantpuphpet

Can't connect to redis on vagrant machine


I am setting up a dev environment that has two vagrant machines. One is a http server the other is a redis server. I cannot connect via port 6379 between the two machines. I also cannot connect to the vagrant machine from the host. I have set this type of configuration up in Centos but this is my first experiment with Ubuntu. Here are the Details, with private network addresses:

Host: OSX Yosemite(192.168.33.1)

Vagrant Machines: ubuntu1404-x64

http(192.168.33.22) redis(192.168.33.20)

Redis conf:
bind 0.0.0.0
port 6379

On redis vagrant I am able to connect to redis with:

redis-cli -h 192.168.33.20

And I can connect to the host redis from the vagrant machine with:

redis-cli -h 192.168.33.1

But I cannot connect to the vagrant redis server remotely (from host or another vagrant machine)

On the vagrant machine I get the following output:

$ sudo netstat -nlpt | grep 6379
6:tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN          1004/redis-server 0

From the host machine I get the following:

$:nmap   -Pn -p 6379  192.168.33.20

Starting Nmap 5.51 ( http://nmap.org ) at 2015-03-15 10:48 PDT
Nmap scan report for 192.168.33.20
Host is up.
PORT     STATE    SERVICE
6379/tcp filtered unknown

Nmap done: 1 IP address (1 host up) scanned in 3.39 seconds

On the redis machine I have tried disabling the firewall with

sudo ufw disable

and enabling the firewall and adding (current state):

sudo ufw allow 6379

Now I get the following output on the redis guest:

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
6379                       ALLOW       Anywhere
6379 (v6)                  ALLOW       Anywhere (v6)

But nothing has changed. I am still unable to reach the port from either the other vagrant machine or my host machine. Nmap still lists the port as "filtered".

Edit: As mentioned in a comment below this code is a project I am taking over for and the Vagrantfile was created using something called pupphpet. The Vagrantfile is boilerplate, all the configuration comes from a yaml file. Here it the config for the redis guest:

---
vagrantfile-local:
    vm:
        box: puphpet/ubuntu1404-x64
        box_url: puphpet/ubuntu1404-x64
        hostname: ''
        memory: '512'
        cpus: '1'
        chosen_provider: virtualbox
        network:
            private_network: 192.168.33.20
            forwarded_port:
                3KP0kJvFLAaL:
                    host: '6822'
                    guest: '22'
        post_up_message: ''
        provider:
            virtualbox:
                modifyvm:
                    natdnshostresolver1: on
            vmware:
                numvcpus: 1
            parallels:
                cpus: 1
        provision:
            puppet:
                manifests_path: puphpet/puppet
                manifest_file: site.pp
                module_path: puphpet/puppet/modules
                options:
                    - '--verbose'
                    - '--hiera_config /vagrant/puphpet/puppet/hiera.yaml'
                    - '--parser future'
        synced_folder:
            dQPBnJQ4bGCM:
                owner: www-data
                group: www-data
                source: ./
                target: /var/www
                sync_type: nfs
                rsync:
                    args:
                        - '--verbose'
                        - '--archive'
                        - '-z'
                    exclude:
                        - .vagrant/
                    auto: 'false'
        usable_port_range:
            start: 10200
            stop: 10500
    ssh:
        host: null
        port: null
        private_key_path: null
        username: vagrant
        guest_port: null
        keep_alive: true
        forward_agent: false
        forward_x11: false
        shell: 'bash -l'
    vagrant:
        host: detect
server:
    install: '1'
    packages:
        - vim
users_groups:
    install: '1'
    groups: {  }
    users: {  }
cron:
    install: '1'
    jobs: {  }
firewall:
    install: '1'
    rules: null
apache:
    install: '0'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules: {  }
    vhosts:
        ryf0d2cn58ci:
            servername: awesome.dev
            serveraliases:
                - www.awesome.dev
            docroot: /var/www/awesome
            port: '80'
            setenv:
                - 'APP_ENV dev'
            directories:
                thl9sg0zbb5i:
                    provider: directory
                    path: /var/www/awesome
                    options:
                        - Indexes
                        - FollowSymlinks
                        - MultiViews
                    allow_override:
                        - All
                    require:
                        - all
                        - granted
                    custom_fragment: ''
            engine: php
            custom_fragment: ''
            ssl_cert: ''
            ssl_key: ''
            ssl_chain: ''
            ssl_certs_dir: ''
    mod_pagespeed: 0
nginx:
    install: '0'
    settings:
        default_vhost: 1
        proxy_buffer_size: 128k
        proxy_buffers: '4 256k'
    upstreams: {  }
    vhosts:
        ken6pmlb2civ:
            proxy: ''
            server_name: awesome.dev
            server_aliases:
                - www.awesome.dev
            www_root: /var/www/awesome
            listen_port: '80'
            location: \.php$
            index_files:
                - index.html
                - index.htm
                - index.php
            envvars:
                - 'APP_ENV dev'
            engine: php
            client_max_body_size: 1m
            ssl_cert: ''
            ssl_key: ''
php:
    install: '1'
    version: '56'
    composer: '1'
    composer_home: ''
    modules:
        php:
            - cli
            - intl
            - mcrypt
        pear: {  }
        pecl:
            - pecl_http
    ini:
        display_errors: On
        error_reporting: '-1'
        session.save_path: /var/lib/php/session
    timezone: America/Chicago
    mod_php: 0
ruby:
    install: '1'
    versions:
        ADSqflP7ScSN:
            version: ''
nodejs:
    install: '1'
    npm_packages: {  }
python:
    install: '1'
    packages: {  }
    versions:
        B69DoSTPPd85:
            version: ''
mysql:
    install: '1'
    override_options: {  }
    root_password: '123'
    adminer: 0
    databases:
        4c8zPdNREcop:
            grant:
                - ALL
            name: dbname
            host: localhost
            user: dbuser
            password: '123'
            sql_file: ''

redis:
    install: '1'
    settings:
        conf_port: '6379'
        conf_bind: '0.0.0.0'

Solution

  • The problem was firewall. Since I am new to Ubuntu, I though the ufw replaced iptables, but it seems to be a front end to it. I am not sure why adding a rule to the ufw did not change the iptables but I think it was this line in the INPUT chain on iptables:

    DROP       all  --  anywhere             anywhere             /* 999 drop all */
    

    perhaps the ufw is appended to the bottom of the iptables chain? Regardless, manually adding a rule for port 6379 above the drop rule fixed the problem.