linux - 如何在未连接到网络的情况下访问 (ping) 虚拟机?

标签 linux networking dns virtualbox

我有一台 Mac 主机,其中一个 Virtualbox 虚拟机运行 Linux(ubuntu),另一个运行 Windows。

我已为所有 guest 虚拟机设置桥接网络适配器和仅主机网络适配器。

主机能够 ping 通虚拟机,虚拟机也能够 ping 通主机。当主机连接到网络时,这可以正常工作。家里的路由器充当 DNS,以便 ping(和其他网络服务)被路由到正确的虚拟机。
但是当我没有连接到网络时该怎么办?(我经常出差)是否有某种方式(可能是服务)可以在主机上运行,​​该主机将充当轻量级 DNS 并将流量路由到正确的虚拟机?

最佳答案

您可以查找虚拟机的本地地址

# ip addr

然后编辑

# vi /etc/hosts "hosts - static table lookup for hostnames "

并添加您的虚拟机本地地址

您可以编辑

# vi /etc/host.conf

订购主机,绑定(bind)

并更改查找顺序。

"etc/host.conf file. The line order hosts, bind specifies that /etc/hosts takes precedence over the name servers. Changing the line to order bind, hosts configures the system to resolve hostnames and IP addresses using the name servers first. If the IP address cannot be resolved through the name servers, the system then looks for the IP address in the /etc/hosts file. "

更新 您可以创建 VPN 吗?

这将允许您拥有静态 IP,然后让 VPN 来处理来自路由器的动态 IP?

Choose Apple menu > System Preferences,

then click Network. Click Add (+) at the bottom of the network connection services list, then choose VPN from the Interface pop-up menu.

Choose what kind of VPN connection you want to set up from the VPN Type pop-up menu, depending on the network you are connecting to, and give the VPN service a name.

Enter the server address and the account name for the VPN connection. Click Authentication Settings, then enter the user authentication information you were given by the network administrator.

After entering the user authentication information, click OK, then click Connect.

然后将虚拟机指向新的网络接口(interface)

VBoxManage modifyvm "VM name" --natbindip1 "192.168.0.x"

您还可以在脚本中运行上述内容,以在“离线”时更改所有虚拟机的网络

引用号https://Apple support VPN

引用号virtualbox.org vboxmanage

或者

这是一个小技巧。

我的路由器也动态分配我的 IP。但是我强制它给我IP。我通过在我的 Linux 机器上将其设置为静态来分配 IP:) 这在办公室中确实有效。对于不在办公室的情况,我有网络脚本的备份,因此我只需删除网络,然后替换文件并启动网络(文件位置位于 Fedora/Redhat/Centos/etc/sysconfig/network-scripts/上)

祝一切顺利

关于linux - 如何在未连接到网络的情况下访问 (ping) 虚拟机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37816507/

相关文章:

linux - 打印和排序输出的替代方法

linux - Azure Linux 机器未连接

linux - 在 cat << 'EOT' 之后使用 sed 仅替换生成的脚本中的一个变量

python - 将 TCP 校验和与 Scapy 进行比较?

linux - 数据迁移并从 Bitnami GitLab 8.9.6 升级到最新的 GitLab CE 综合总线

c++ - c++ linux 上的套接字编程 tcp 有哪些替代方案

android - 使用 Android 应用更改网络运营商

Oracle SQL Developer 上的 Windows 域登录

Firebase使用1个项目将多个子域托管到应用程序目录

dns - 将自定义域与 IBM Bluemix 网站结合使用