Ubuntu 24.04 LTS 命令行固定 IP
<h2 id="参考">参考</h2><ul>
<li>https://www.sysgeek.cn/set-static-ip-ubuntu/</li>
<li>gpt</li>
</ul>
<h2 id="环境">环境</h2>
<table>
<thead>
<tr>
<th>环境</th>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>Windows</td>
<td>Windows 10 家庭中文版 22H2 19045.4529</td>
<td></td>
</tr>
<tr>
<td>VMware</td>
<td>Workstation 16 Pro</td>
<td></td>
</tr>
<tr>
<td>Ubuntu</td>
<td>Ubuntu 24.04 LTS</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="步骤">步骤</h2>
<p>我们可以使用 Netplan 工具和配置文件,为 Ubuntu Server 设置静态 IP 地址。Netplan 的配置文件通常位于/etc/netplan目录,取决于你的系统版本和实际环境,文件名可能是01-netcfg.yaml或50-cloud-init.yaml。</p>
<ol>
<li>使用以下命令列出所有网络接口,确定 Ubuntu 上可用的网络接口名称:<pre><code class="language-bash">ip link show
</code></pre>
<img src="https://img2024.cnblogs.com/blog/1550155/202406/1550155-20240630150006982-1084320735.png" alt="image" loading="lazy"></li>
<li>找到 Netplan 的配置文件:<pre><code class="language-bash">cd /etc/netplan
ls -l
</code></pre>
<img src="https://img2024.cnblogs.com/blog/1550155/202406/1550155-20240630150116186-749502733.png" alt="image" loading="lazy"></li>
<li>备份 Netplan 的配置文件:<pre><code class="language-bash">cp 50-cloud-init.yaml ./50-cloud-init-back.yaml
</code></pre>
</li>
<li>打开并编辑 Netplan 配置文件,例如 50-cloud-init.yaml,修改为如下:<pre><code class="language-bash">sudo nano 50-cloud-init.yaml
</code></pre>
<pre><code class="language-yaml"># This file is generated from information provided by the datasource.Changes
# to it will not persist across an instance reboot.To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
# 默认
# network:
# ethernets:
# ens33:
# dhcp4: true
# version: 2
# 当前
# 根据网络环境替换示例中的 IP 地址、网关和 DNS 服务器地址。
# renderer」配置为networkd,使用 systemd-networkd 作为网络配置的后端。桌面环境使用 NetworkManager,Ubuntu Server 和无头环境使用networkd。
network:
renderer: networkd
ethernets:
ens33: # 替换为你的网络接口名称
dhcp4: false # 关闭 DHCP
dhcp6: false # 关闭 DHCP
addresses: # 静态 IP 地址和子网掩码
routes:
- to: default
via: 192.168.72.1 # 网关地址
nameservers:
addresses: # DNS 服务器地址
search: []
version: 2
</code></pre>
</li>
<li>保存文件后,执行以下命令应用更改:<pre><code class="language-bash">sudo netplan apply
</code></pre>
</li>
<li>检查 IP 地址和网络连接:<pre><code class="language-bash">ip addr show
ip route show
ping www.sysgeek.cn
</code></pre>
</li>
</ol>
</div>
<div id="MySignature" role="contentinfo">
<div>
博主 :夏秋初<br />
地址 :https://www.cnblogs.com/xiaqiuchu/p/18276389 <br /> <br />
如果对你有帮助,可以点一下
<span style="color:#ff5722;cursor: pointer;" onclick="(()=>{$('#green_channel_follow').click()})() "> 推荐 </span>
或者
<span style="color:#ff5722;cursor: pointer;"onclick="(()=>{$('#div_digg .diggit').click()})() "> 关注 </span>
吗?会让我的分享变得更有动力~<br />
转载时请带上原文链接,谢谢。<br />
</div><br><br>
来源:https://www.cnblogs.com/xiaqiuchu/p/18276389
頁:
[1]