在VirtualBox中设置Ubuntu 20.04使用固定IP
<ol><li>
<p>首先在虚拟机设置界面中将网络连接模式设置为“桥接网卡”,同时选择你的物理机上网所用的网卡,我这里是使用的无线网卡,故选择“Intel(R) Wi-Fi 6 AX200 160MHz”这一项<br>
<img src="https://img2020.cnblogs.com/blog/960866/202101/960866-20210107015401449-1410100199.png"><br>
<br></p>
</li>
<li>
<p>启动虚拟机,使用 <code>ip addr</code> 查看当前网络设置<br>
<img src="https://img2020.cnblogs.com/blog/960866/202101/960866-20210107012650483-1283161436.png"><br>
<br></p>
</li>
<li>
<p>编辑网络配置文件,<code>sudo vim /etc/netplan/00-installer-config.yaml</code>(网上有些文章这里的配置文件名是 50-cloud-init.yaml,我这里只有一个 00-installer-config.yaml 文件,看实际情况),打开后的原始文件是这样的:</p>
</li>
</ol>
<pre><code># This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
</code></pre>
<p>我们把配置改成:</p>
<pre><code>network:
ethernets:
enp0s3:#配置的网卡的名称
dhcp4: no#dhcp4关闭
addresses: #设置本机IP及掩码,/24即表示24位掩码255.255.255.0
gateway4: 192.168.1.1#网关IP,设置为和物理机相同
nameservers:
addresses: #设置DNS,与物理机相同
version: 2
</code></pre>
<br>
<ol start="4">
<li>输入 <code>:wq</code> 保存退出后,执行 <code>sudo netplan apply</code> 使配置生效,之后每次启动虚拟机IP地址就不会再改变了。这样虚拟机内部可以正常上网,在物理机中也可以直接使用虚拟机的ip访问内部的服务。</li>
</ol><br><br>
来源:https://www.cnblogs.com/shangxb/p/virtualbox-set-ubuntu-2004-static-ip.html
頁:
[1]