OSX connection configuration issue to rack application I am on mac ElCapitan 10.11.6 (15G31) and running simple rack application rackup -p 5004. I can connect to it with http://localhost:5004/ and http://[::1]:5004/

But can't connect with http://127.0.0.1:5004/ and http://192.168.0.111:5004/.

This looks like mis-configuration on my machine. I get different errors when try to connect with IPv4 and IPv6.

$ nc -v -4 192.168.0.111 5004 # and nc -v -4 127.0.0.1 5004 and nc -v -4 localhost 5004
nc: connectx to 192.168.0.111 port 5004 (tcp) failed: Connection refused

$ nc -v -6 192.168.0.111 5004 # and nc -v -6 127.0.0.1 5004
nc: getaddrinfo: nodename nor servname provided, or not known


But I can connect with nc -v -6 localhost 5004

My hosts file is pretty simple:

$ cat /etc/hosts                                                                                                                                                       
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost


I need to make it work with my host machine IP address 192.168.0.111 so I can connect within Docker container. How to fix this?



Additional information I found on different topics


scutil

$ scutil -r 192.168.0.111
Reachable, Local Address, Directly Reachable Address

$ scutil -r 127.0.0.1
Reachable, Local Address, Directly Reachable Address

$ scutil -r localhost
Reachable

$ scutil -r ::1
Reachable, Local Address, Directly Reachable Address

# but note, ???
$ scutil -r qwerty
Reachable

lsof port usage


lsof shows port is by ruby executable and the interesting part is localhost:avt-profile-1. Checking what avt-profile-1 is gives results for "Real-time Transport Protocol media data". More info here. Also interesting is when I stop the rackup application there is no port usage, so this is not service/daemon running on my machine.

lsof -i :5004
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    12167 kode   16u  IPv6 0xf3c39e30b59c5321      0t0  TCP localhost:avt-profile-1 (LISTEN)


Here I have different application running on port 5000. It's reachable via the host IP at 192.168.0.111:5000. Note the NAME *:commplex-main. Addittionaly I would like to know what this is used for.

lsof -i :5000
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    12889 kode   14u  IPv4 0xf3c39e30b22fcbe9      0t0  TCP *:commplex-main (LISTEN)



host address name

host 192.168.0.111
111.0.168.192.in-addr.arpa has no PTR record

arp

$ arp 192.168.0.111
? (192.168.0.111) at a0:99:9b:17:16:1d on en0 ifscope permanent [ethernet]

nslookup

$ nslookup localhost
Server:     192.168.0.1
Address:    192.168.0.1#53

Name:   localhost
Address: 127.0.0.1

$ nslookup 127.0.0.1
Server:     192.168.0.1
Address:    192.168.0.1#53

1.0.0.127.in-addr.arpa  name = localhost.

$ nslookup 192.168.0.111
Server:     192.168.0.1
Address:    192.168.0.1#53

** server can't find 111.0.168.192.in-addr.arpa.: NXDOMAIN
The issue was rackup runs on localhost by default. To use host one must specify it with -o like rackup -o 192.168.0.111 -p 5004. Only one host can be specified.