consul

consul agent could only bind to 127.0.0.1


After installing consul on a Debian virtualbox VM, I ran "consul agent -dev" to start the agent. The stdout looked fine.

Then I typed "consul members" in another terminal, and found it's listening on 127.0.0.1:8301 instead of a non-loopback address.

root@debian02:/home/steven# consul members
Node      Address         Status  Type    Build  Protocol  DC   Segment
debian02  127.0.0.1:8301  alive   server  1.0.1  2         dc1  <all>

I could run another program that can listen on all addresses, so the network configuration should be fine for the VM.

What could be wrong?

Here's the output of ip address:

root@debian02:/home/steven# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:9d:a7:7e brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.4/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 812sec preferred_lft 812sec
    inet6 fe80::a00:27ff:fe9d:a77e/64 scope link 
       valid_lft forever preferred_lft forever

Output of netstat:

root@debian02:/home/steven# netstat -lntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:8302          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8500          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8600          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8300          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8301          0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
udp        0      0 0.0.0.0:631             0.0.0.0:*                          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                          
udp        0      0 0.0.0.0:1900            0.0.0.0:*                          
udp        0      0 0.0.0.0:47046           0.0.0.0:*                          
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 127.0.0.1:8301          0.0.0.0:*                          
udp        0      0 127.0.0.1:8302          0.0.0.0:*                          
udp        0      0 127.0.0.1:8600          0.0.0.0:*                          
udp6       0      0 :::52337                :::*                               
udp6       0      0 :::5353                 :::*          

Thanks,

Steven


Solution

  • have you read the documentation? https://www.consul.io/docs/agent/options.html#_client

    it'll bind to 127.0.0.1 by default and its changeable. you can use 0.0.0.0