VirtualBox Network

本文介绍如何在VirtualBox中为虚拟机设置两个网络适配器:一个使用NAT网络,另一个使用宿主机仅适配器。通过这种方式,可以在不影响外部网络连接的情况下,实现宿主机与虚拟机之间的直接通信。
VirtualBox Network

Last one year, I am not setting my VirtualBox in the right way. So I need to switch the IP address between my working environment and home wifi environment.

Actually it is not necessary. I knew this long time ago. VirtualBox support the VM using 2 network Adapters. So the best way to set up the VM is that, one adapter with NAT Network and one with Host-only Adapter. Then we can access the outside network via NAT, and our host machine can access the VM from the Host-only Adapter.

Open the VirtualBox —> References ——> Network —> Add NAT Networks ——> Host-only Networks Tab, add One vboxnet0 —> Edit that —> Setting the DHCP Server with these information
Server Address: 192.168.56.100
Server Mask: 255.255.255.0
Lower Address Bound: 192.168.56.101
Upper Address Bound: 192.168.56.254

Then start the Virtual Machine.
> sudo vi /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp

It works pretty well.

References:
https://technology.amis.nl/2014/01/27/a-short-guide-to-networking-in-virtual-box-with-oracle-linux-inside/
### 设置和排查 VirtualBox 主机仅网络 (Host-Only Network) #### 创建主机仅适配器 为了使虚拟机通过主机仅网络通信,在创建新虚拟机或编辑现有虚拟机时,需配置网络适配器为“主机仅适配器”。这允许虚拟机连接到特定于宿主系统的专用网络接口。 ```bash VBoxManage hostonlyif create ``` 上述命令用于创建新的主机仅网络接口。如果遇到权限问题,则可能需要管理员权限来执行此操作[^1]。 #### 配置静态 IP 地址 对于每台希望加入同一主机仅网络的虚拟机而言,应为其分配固定的IP地址范围内的唯一IP地址。通常情况下,默认网关设为主机的IP地址(例如 `192.168.56.1`)。确保所有设备处于相同子网内以便相互通信。 #### 启用 DHCP 服务 启用DHCP服务器可以简化IP地址管理过程。VirtualBox自带了一个简单的内置DHCP服务器选项: ```bash VBoxManage dhcpserver add --netname HostInterfaceNetworking-vboxnet0 \ --ip 192.168.56.100 --netmask 255.255.255.0 \ --lowerip 192.168.56.101 --upperip 192.168.56.200 ``` 以上脚本定义了DHCP池并指定了可用的动态IP地址区间。 #### 排查常见错误 当无法建立有效的主机仅网络连接时,考虑以下几个方面: - 检查防火墙设置是否阻止了必要的端口; - 确认已安装最新版本的Guest Additions以获得更好的兼容性和性能优化; - 查看日志文件中的任何警告或错误消息,它们往往能提供解决问题的关键线索; #### 测试连通性 完成上述配置之后,可以通过ping命令测试两台或多台机器间的连通状况。另外也可以尝试SSH登录等方式验证跨节点访问能力。 ```bash ping 192.168.56.XXX # 替换XXX为目标VM的实际IP地址 ssh user@192.168.56.YYY # 使用实际用户名及目标VM的IP替换相应部分 ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值