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

如何通过VBoxManage控制台配置VirtualBox虚拟机网络及TCP/IPv4静态参数

Hey there! Let's tackle your two questions about configuring VirtualBox networking via VBoxManage from the console.

1. Configuring VirtualBox VM Network Settings with VBoxManage

VBoxManage lets you fully control your VM's network setup without using the GUI. Here are common configurations for popular network modes:

  • Bridged Networking (connects the VM directly to your physical local network, same as a physical device):

    vboxmanage modifyvm VMNAME --nic1 bridged --bridgeadapter1 eth0
    

    Replace VMNAME with your VM's actual name, and eth0 with your host's physical network interface (use ip link show on Linux/macOS or ipconfig on Windows to list available interfaces).

  • NAT Networking (default mode, shares the host's IP address for internet access):

    vboxmanage modifyvm VMNAME --nic1 nat
    

    You can add port forwarding to access services on the VM from the host:

    vboxmanage modifyvm VMNAME --natpf1 "guest_ssh,tcp,,2222,,22"
    

    This forwards host port 2222 to the VM's port 22 (for SSH access).

  • Host-Only Networking (VM can only communicate with the host and other VMs on the same host-only network):
    First create a host-only adapter if you don't have one:

    vboxmanage hostonlyif create
    vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1 --netmask 255.255.255.0
    

    Then attach it to your VM:

    vboxmanage modifyvm VMNAME --nic1 hostonly --hostonlyadapter1 vboxnet0
    
  • Internal Networking (VMs can only communicate with each other on a private internal network, no host access):

    vboxmanage modifyvm VMNAME --nic1 intnet --intnet1 my_internal_network
    

    Replace my_internal_network with a name for your private network.

2. Setting Static TCP/IPv4 Parameters for a Bridged VM

Important note: VBoxManage handles the virtual network adapter setup, but it doesn't configure the guest OS's network stack directly. To set static IP, subnet mask, gateway, and DNS, you need to adjust settings inside the guest operating system. Here are two ways to do this:

Option 1: Access the VM's terminal directly

If you can open the VM's console or connect via SSH:

  • Linux Guests (Debian/Ubuntu example):
    Edit the Netplan configuration file (location may vary by distro—some use /etc/network/interfaces):

    sudo nano /etc/netplan/00-installer-config.yaml
    

    Paste this configuration (adjust values to match your network):

    network:
      ethernets:
        enp0s3:  # Replace with your VM's network interface name (check with `ip addr`)
          addresses: [192.168.1.100/24]
          gateway4: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 1.1.1.1]
      version: 2
    

    Apply the changes:

    sudo netplan apply
    

    For RHEL/CentOS/Fedora:

    sudo nmcli con mod enp0s3 ipv4.addresses 192.168.1.100/24
    sudo nmcli con mod enp0s3 ipv4.gateway 192.168.1.1
    sudo nmcli con mod enp0s3 ipv4.dns "8.8.8.8 1.1.1.1"
    sudo nmcli con mod enp0s3 ipv4.method manual
    sudo nmcli con up enp0s3
    
  • Windows Guests:
    Open Command Prompt as Administrator and run these commands (replace Ethernet0 with your VM's adapter name, check with netsh interface ip show config):

    # Set static IP, subnet mask, and default gateway
    netsh interface ip set address "Ethernet0" static 192.168.1.100 255.255.255.0 192.168.1.1 1
    
    # Set primary and secondary DNS servers
    netsh interface ip set dns "Ethernet0" static 8.8.8.8
    netsh interface ip add dns "Ethernet0" 1.1.1.1 index=2
    

Option 2: Use VBoxManage GuestControl (requires Guest Additions)

If you can't access the VM's terminal directly, you can run commands remotely using guestcontrol (you'll need Guest Additions installed on the VM and know the guest OS credentials):

  • Linux Example:

    vboxmanage guestcontrol VMNAME run --username YOUR_GUEST_USER --password YOUR_GUEST_PASS -- /bin/bash -c "
    sudo tee /etc/netplan/00-installer-config.yaml <<EOF
    network:
      ethernets:
        enp0s3:
          addresses: [192.168.1.100/24]
          gateway4: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 1.1.1.1]
      version: 2
    EOF
    sudo netplan apply
    "
    
  • Windows Example:

    vboxmanage guestcontrol VMNAME run --username YOUR_GUEST_USER --password YOUR_GUEST_PASS -- cmd.exe /c "
    netsh interface ip set address \"Ethernet0\" static 192.168.1.100 255.255.255.0 192.168.1.1 1 &&
    netsh interface ip set dns \"Ethernet0\" static 8.8.8.8 &&
    netsh interface ip add dns \"Ethernet0\" 1.1.1.1 index=2
    "
    

内容的提问来源于stack exchange,提问作者FeR-S

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:55:08