You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VirtualBox中Ubuntu虚拟机无法联网,需同时实现宿主机与虚拟机互通

Hey there, let's get your Ubuntu Server VM connected to the internet while keeping that host-VM connectivity you already have. Since you're using bridge mode and the host-VM link works, we just need to adjust a few network settings on the VM side. Here's how to fix it step by step:

Step 1: Verify Your Active Network Interface

You mentioned enp0s3 is the working interface (with eth0 being unused), so first let's make sure it's enabled:

  • Run ifconfig -a or ip link show to confirm enp0s3 is listed.
  • If it's not marked as "UP", enable it with:
    sudo ip link set enp0s3 up
    
Step 2: Configure Network Settings (DHCP or Static IP)

Since you're using bridge mode, your VM should sit on the same network segment as your Windows 7 host's WiFi connection. Let's start with the simplest option first:

Option A: Use DHCP (Auto-IP Assignment)

Most home routers support DHCP, which will automatically assign your VM a valid IP, gateway, and DNS:

  • Run this command to request an IP from your router:
    sudo dhclient enp0s3
    
  • Check if it worked by running ip addr show enp0s3 — you should see an IP in the same range as your host's WiFi (e.g., if your host is 192.168.1.5, the VM might get 192.168.1.10).

Option B: Manual Static IP (If DHCP Fails)

If DHCP doesn't work, set a static IP that matches your host's network:

  1. Get your host's network details: On Windows 7, open Command Prompt and run ipconfig. Look for your WiFi adapter's:

    • IPv4 Address (e.g., 192.168.1.5)
    • Subnet Mask (e.g., 255.255.255.0)
    • Default Gateway (e.g., 192.168.1.1)
    • DNS Servers (you can also use public ones like 8.8.8.8 or 1.1.1.1)
  2. Configure the VM's network:

    • For Ubuntu 18.04+ (uses Netplan):
      Edit the Netplan config file (usually in /etc/netplan/ — look for a .yaml file like 00-installer-config.yaml):

      network:
        ethernets:
          enp0s3:
            addresses: [192.168.1.100/24]  # Pick an unused IP in your host's network range
            gateway4: 192.168.1.1          # Your host's default gateway
            nameservers:
              addresses: [8.8.8.8, 1.1.1.1] # Public DNS or your router's DNS
        version: 2
      

      Apply the changes with:

      sudo netplan apply
      
    • For older Ubuntu versions (uses /etc/network/interfaces):
      Edit the file with:

      sudo nano /etc/network/interfaces
      

      Add these lines (replace values with your host's details):

      auto enp0s3
      iface enp0s3 inet static
          address 192.168.1.100
          netmask 255.255.255.0
          gateway 192.168.1.1
          dns-nameservers 8.8.8.8 1.1.1.1
      

      Restart the network service:

      sudo /etc/init.d/networking restart
      
Step 3: Test Connectivity

Let's confirm everything works:

  • First, verify host-VM connectivity is still intact: ping [your-windows-host-ip] (replace with your host's actual IP from ipconfig).
  • Next, ping your router's gateway: ping 192.168.1.1 (use your gateway IP). If this works, your VM can reach the router.
  • Then ping a public DNS server: ping 8.8.8.8. Success here means your VM can reach the internet.
  • Finally, test DNS resolution: ping google.com. If this works, your VM can resolve domain names properly.
Step 4: Check Common Issues
  • Ensure bridge mode targets the right adapter: In your virtualization software (VirtualBox/VMware), double-check that bridge mode is set to your WiFi adapter (not a wired Ethernet adapter, since you're using WiFi).
  • Ubuntu Firewall: Even if Windows Firewall is off, Ubuntu's default firewall (ufw) might block traffic. Temporarily disable it to test:
    sudo ufw disable
    
    If this fixes it, you can re-enable it and add rules to allow internet traffic later.
  • Host WiFi is working: Confirm your Windows 7 laptop can actually connect to the internet — if the host has no internet, the VM won't either via bridge mode.

内容的提问来源于stack exchange,提问作者Albert Lazaro de Lara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:39:10