postgresql – 如何从vagrant客户机访问主机上的端口

我在我的mac(主机)上运行了
postgresql.我有2个ubuntu VM.我希望这些VM能够在我的mac上访问postgresql.似乎vagrant的端口转发仅在一个方向上工作,主机只能访问客户资源,但不能相反.

在我的ubuntu客户机上,我可以看到主机
inet addr:10.0.2.15 Bcast:10.0.2.255掩码:255.255.255.0
甚至可以ping它.

但尝试在guest虚拟机上建立从guest虚拟机到postgresql运行实例的连接失败.

telnet 10.0.2.15 5432

如何允许我的访客ubuntu机器访问我的主机上的postgresql?

更新:
来自客人的主机给出:

nmap scan report for 10.0.2.15
Host is up (0.00026s latency).
Not shown: 998 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
111/tcp open  rpcbind

最佳答案 您的PostgreSQL可能不接受localhost或127.0.0.1以外的连接.

documentation(强调我的):

listen_addresses (string)

Specifies the TCP/IP address(es) on which the server is to listen for connections from client applications. The value takes the form of a comma-separated list of host names and/or numeric IP addresses. The special entry * corresponds to all available IP interfaces. The entry 0.0.0.0 allows listening for all IPv4 addresses and :: allows listening for all IPv6 addresses. If the list is empty, the server does not listen on any IP interface at all, in which case only Unix-domain sockets can be used to connect to it. The default value is localhost, which allows only local TCP/IP “loopback” connections to be made. While client authentication (Chapter 19) allows fine-grained control over who can access the server, listen_addresses controls which interfaces accept connection attempts, which can help prevent repeated malicious connection requests on insecure network interfaces. This parameter can only be set at server start.

此配置文件最有可能位于/var/pgsql/postgresql.conf(source)中.

点赞