使用virtualbox的HostOnly建立共享网络-实现虚拟机上网

目录

环境描述

在图书馆学习时,上网需要身份验证,在virtualbox虚拟机是ubuntu,设置Bridged Adapter时,ubuntu中不会弹出身份认证页面,无法在虚拟机ubuntu中上网,设置为NAT模式时也不能上网.

解决方案

使用windows的网络共享功能,把wifi网络分享给virtualbox host-only ethernet adpater,在虚拟机中通过这个虚拟网卡进行上网.

具体步骤

1.新建一个virtual host-only ethernet adapter

2.设置windows的wifi信号网络共享

3.确认winows宿主网络信息

在windows平台上运行cmd,然后在cmd终端中输入命令ipconfig /all查看当前的网络信息

3.1.wifi适配器的信息

bash 复制代码
Wireless LAN adapter wifi:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Wi-Fi 6E AX211 160MHz
   Physical Address. . . . . . . . . : F8-9E-94-EA-B0-14
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::2e11:cb45:77e2:7b3f%20(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.20.188.206(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Lease Obtained. . . . . . . . . . : Sunday, April 20, 2025 09:22:46
   Lease Expires . . . . . . . . . . : Sunday, April 20, 2025 13:41:22
   Default Gateway . . . . . . . . . : 172.20.1.1
   DHCP Server . . . . . . . . . . . : 172.20.188.1
   DHCPv6 IAID . . . . . . . . . . . : 133734036
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-2E-98-5D-FB-00-E0-4C-60-04-51
   DNS Servers . . . . . . . . . . . : 114.114.114.114
                                       202.96.134.133
   NetBIOS over Tcpip. . . . . . . . : Enabled

注意DNS Servers的信息,下面配置会用到.

3.2.虚拟网卡的信息

bash 复制代码
Ethernet adapter shareonly:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : VirtualBox Host-Only Ethernet Adapter #2
   Physical Address. . . . . . . . . : 0A-00-27-00-00-0E
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::cb8f:d2ca:1a24:e31c%14(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.137.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 1124728871
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-2E-98-5D-FB-00-E0-4C-60-04-51
   NetBIOS over Tcpip. . . . . . . . : Enabled

3.3.确认virtualbox中虚拟网卡的ip地址

确认ip地址被windows wifi sharing设置时,修改为192.168.137.1,如果没有修改,请手工修改.

确保HDCP Server关闭

4.虚拟机网卡设置

现在有两个host-only虚拟网卡:

1.hostonly用于本地连接

2.shareonly用于ubuntu虚拟机通过wifi网卡上网

5.虚拟机网络设置

5.1.本地连接设置

选择自动配置即可.

ifconfig查看网络ip地址192.168.56.6,在windows平台下ping一下

properties 复制代码
ping 192.168.56.6

Pinging 192.168.56.6 with 32 bytes of data:
Reply from 192.168.56.6: bytes=32 time<1ms TTL=64
Reply from 192.168.56.6: bytes=32 time<1ms TTL=64
Reply from 192.168.56.6: bytes=32 time<1ms TTL=64
Reply from 192.168.56.6: bytes=32 time<1ms TTL=64

5.2.ubuntu虚拟机联网设置

需要设置为手动模式

IP地址和网关设置参考3.2.虚拟网卡的信息

DNS设置参考3.1.wifi适配器的信息

在ubuntu虚拟机中ping一下外部网站

复制代码
ping www.baidu.com
properties 复制代码
64 bytes from 183.2.172.17 (183.2.172.17): icmp_seq=1 ttl=51 time=22.2 ms
64 bytes from 183.2.172.17 (183.2.172.17): icmp_seq=2 ttl=51 time=33.2 ms
64 bytes from 183.2.172.17 (183.2.172.17): icmp_seq=3 ttl=51 time=70.8 ms

总结

这是在特殊情况下的特例,具体场景具体应用.根据这个操作一遍后,以后发现其他使用场景,可以举一反三解决问题.

相关推荐
ACP广源盛139246256735 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑
Empty-Filled5 小时前
AI生成测试用例功能怎么测:一个完整实战案例
网络·人工智能·测试用例
码云数智-大飞6 小时前
本地部署大模型:隐私安全与多元优势一站式解读
运维·网络·人工智能
jinanwuhuaguo6 小时前
(第二十九篇)OpenClaw 实时与具身的跃迁——从异步孤岛到数字世界的“原住民”
前端·网络·人工智能·重构·openclaw
等风来不如迎风去7 小时前
【win11】最佳性能:fix 没有壁纸,一直黑屏
网络·人工智能
Harvy_没救了7 小时前
【网络部署】 Win11 + VMware CentOS8 + Nginx 文件共享服务 Wiki
运维·网络·nginx
汤愈韬8 小时前
NAT Server 与目的Nat
网络·网络协议·网络安全·security
2401_873479408 小时前
断网时如何实时判断IP归属?嵌入本地离线库,保障风控不中断
运维·服务器·网络
7ACE9 小时前
Wireshark TS | TLP 超时时间
网络·网络协议·tcp/ip·wireshark·tcpdump
其实防守也摸鱼10 小时前
CTF密码学综合教学指南--第三章
开发语言·网络·python·安全·网络安全·密码学