Ubuntu 下 VirtualBox 网络设置指南
一、常见网络模式与适用场景
二、在 VirtualBox 中配置网络适配器
三、在 Ubuntu 客户机内配置网络
ip addr(常见如 enp0s3、enp0s8)。sudo nano /etc/netplan/01-netcfg.yaml(文件名可能不同,如 50-cloud-init.yaml)。network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
enp0s8:
dhcp4: no
addresses: [192.168.56.110/24]
routes:
- to: default
via: 192.168.56.1
metric: 100
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
sudo netplan apply(远程环境可用 sudo netplan try 更稳妥)。auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet dhcp
auto enp0s8
iface enp0s8 inet static
address 192.168.56.110
netmask 255.255.255.0
gateway 192.168.56.1
dns-nameservers 8.8.8.8 1.1.1.1
修改后重启网络或系统:sudo systemctl restart networking 或 sudo reboot。四、验证与常见问题
ping 8.8.8.8、ping www.baidu.com(DNS 正常则域名可达)。ping 192.168.56.110;虚拟机 ping 192.168.56.1(Host-Only 网关)。ssh -p 2222 user@localhost(对应 NAT 端口转发)。sudo apt install openssh-server && sudo systemctl enable --now ssh。