smallgoogle
V2EX  ›  问与答

Vagrant 如何配置虚拟机访问宿主机的端口

  •  
  •   smallgoogle · Aug 20, 2019 · 3224 views
    This topic created in 2654 days ago, the information mentioned may be changed or developed.

    关于 Vagrant 搜索出来的都是 虚拟机映射端口到宿主机,共享目录到宿主机;

    那么问题来了,我想让虚拟机访问宿主机的端口,咋办?

    我的场景大概是,创建了两台虚拟机,一台 A 一台 B ;

    我在 A 创建了数据库,映射了端口到宿主机,那么我想 B 可以访问宿主机的端口 访问到 A 的数据库。咋办?

    忽略给他们配置独立内网 IP 的想法。

    5 replies  •  2019-08-20 14:14:26 +08:00
    blackeeper
    blackeeper
    Aug 20, 2019
    1
    vagrant bridge 模式不是默认就可以么
    smallgoogle
    smallgoogle
    OP
    Aug 20, 2019
    2
    @blackeeper 可以吗?那虚拟机应该访问啥 ip 才能访问到宿主机?
    Sylv
    Sylv
    Aug 20, 2019 via iPhone
    3
    bridge 模式下宿主机和虚拟机在局域网内就是平级的,直接访问宿主机的内网 IP 就行。
    blackeeper
    blackeeper
    Aug 20, 2019
    4
    @smallgoogle 宿主机配置一个网络 192.168.88.1/24,A/B 主机 bridge 这个网络,IP 分别为:192.168.88.2/3,那么他们就是一个网段,这样都是通的。
    smallgoogle
    smallgoogle
    OP
    Aug 20, 2019
    5
    @Sylv
    @blackeeper 谢谢。我自己骚操作一波看看。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1725 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:17 · PVG 00:17 · LAX 08:17 · JFK 11:17
    ♥ Do have faith in what you're doing.