在Ubuntu VirtualBox中设置虚拟机IP地址可以通过以下几种网络连接模式来实现:NAT模式、桥接模式、仅主机模式(Host-only)和内部网络(Internal)。以下是详细步骤:
ifconfig
或 ip addr
查看IP地址。/etc/netplan/00-installer-config.yaml
文件(Ubuntu 18.04及以上版本),设置固定IP。ifconfig
或 ip addr
查看IP地址。/etc/network/interfaces
文件,设置静态IP。ifconfig
或 ip addr
查看IP地址。/etc/network/interfaces
文件,设置静态IP。ifconfig
或 ip addr
查看IP地址。/etc/network/interfaces
文件,设置静态IP。在配置静态IP地址时,通常需要编辑 /etc/netplan/00-installer-config.yaml
或 /etc/network/interfaces
文件,设置IP地址、子网掩码、网关和DNS服务器。例如,使用 netplan
配置文件的示例如下:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
enp0s8:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
应用配置后,使用命令 sudo netplan apply
使配置生效。
通过以上步骤,您可以在Ubuntu VirtualBox虚拟机中设置静态IP地址,并根据需要选择不同的网络连接模式。