如何从 vagrant virtualbox 机器连接主机 PostgreSQL [英] How to connect with host PostgreSQL from vagrant virtualbox machine

查看:25
本文介绍了如何从 vagrant virtualbox 机器连接主机 PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台在 Mac OS X 主机上运行 Ubuntu 12.04 的 VirtualBox 机器.在我的主机 (Mac OS X) 中,我安装了 PostgreSQL.我想从我的 Ubuntu 虚拟机连接到这个 PostgreSQL 服务器(我知道通常是相反的方式).

I have a VirtualBox machine running Ubuntu 12.04 in a Mac OS X host machine. In my host machine (Mac OS X), I have PostgreSQL installed. I would like to connect to this PostgreSQL server from my Ubuntu virtual machine (I know normally it's the opposite way).

我想我应该在 VirtualBox 中配置一些网络参数.我从 Vagrant docs 得到的只是我需要为我的虚拟机分配一个静态 IP 以使用专用网络.但是一旦创建,我如何从我的客人到达我的主人?

I guess I should configure some networking parameters in VirtualBox itself. All I get from Vagrant docs is I need to assign my vm a static IP to use a private network. But once created, how do I reach my host from my guest?

我在流浪文档中没有找到类似的东西.所以,这可能是一个很好的理由.是否有意义?我不想重复 PostgreSQL 安装.就用我现有的吧.

I didn't find anything like that in vagrant docs. So, there's probably a good reason for that. Does it make sense? I don't want to duplicate PostgreSQL installation. Just use my current existent one.

推荐答案

您可以使用虚拟机上的默认网关从来宾访问主机.

You can reach your host from your guest by using the default gateway on your VM.

有关解释,请参阅此答案.

通过运行 netstat -rn,您可以获得默认网关,然后在应用程序的配置文件中使用该 IP 地址.

By running netstat -rn you can get the default gateway and then use that ip address in your config file of your application.

运行 netstat -rn |grep "^0.0.0.0 " |cut -d " " -f10 应该给你正确的IP地址.(仅在我的机器上测试过)

Running netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10 should give you the correct ip address. (only tested this on my machine)

这篇关于如何从 vagrant virtualbox 机器连接主机 PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆