在 Debian + VirtualBox 环境下联网,通常有以下几种常见方式和对应设置步骤。你可以按自己的需求选择。
适合:只想让 Debian 能上网
ping -c 3 8.8.8.8
如果能 ping 通 IP 但不能 ping 域名:
sudo nano /etc/resolv.conf
添加:
nameserver 8.8.8.8
适合:虚拟机像一台真实机器,和主机在同一局域网
ip a
主机可直接 ping 虚拟机 IP。
适合:做实验、开发,主机连虚拟机
sudo dhclient
ip a
sudo dhclient
编辑:
sudo nano /etc/network/interfaces
示例:
auto eth0
iface eth0 inet static
address 192.168.56.10
netmask 255.255.255.0
gateway 192.168.56.1
然后:
sudo systemctl restart networking
ip link set eth0 up
ip route
sudo ufw status
如果你愿意,可以告诉我:
我可以给你更精确的一步到位配置。