如何在 Debian 11 上设置一个静态 IP 地址
<div><div>
<p>当你在电脑上安装一个新的操作系统时,DHCP服务器会给你分配一个动态IP地址。然而,在各种情况下,你可能需要在你的机器上<strong>设置</strong>一个<strong>静态IP地址</strong>,例如,当你正在托管一个网络服务器,或者任何服务需要一个IP地址而不是域名,或者在你即将授予某人远程访问你的系统的情况下。不管是什么原因,你应该知道如何在你的系统上设置一个静态IP地址。</p>
<p>在这篇文章中,你将学习<strong>如何</strong>使用<strong>两种不同的方法</strong> <strong>在 Debian 11 上设置静态 IP</strong>。那么,让我们开始吧!</p>
<h2 data-id="heading-0">方法1:使用终端在 Debian 11 上设置静态 IP 地址</h2>
<p>作为一个<strong>Debian</strong> 用户,你可以通过使用终端轻松设置一个<strong>静态IP</strong>。要做到这一点,首先,你必须在你的系统上选择一个有效的网络接口。</p>
<h2 data-id="heading-1">如何在 Debian 11 上检查可用的网络接口</h2>
<p>您可以利用 "<strong>ip</strong>"命令来获取您的系统当前可用网络接口的详细信息。<strong>ip</strong>"是 "<strong>互联网协议</strong>"的缩写。<strong>ip</strong>"命令是基于Linux系统的网络和系统管理员用来配置网络接口的一个工具。在 "<strong>ip</strong>"命令中,"<strong>link</strong>"是用来查看和修改网络接口的子命令。在你的<strong>Debian 11</strong>终端中写出下面的命令来查看当前可用的网络接口。</p>
<pre class="highlighter-prismjs language-shell prismjs-lines-highlighted"><code>$ ip link
复制代码</code></pre>
<p>从输出结果中,我们将记下我们活动的网络接口的名称,即 "<strong>enpos3</strong>"。因为 "<strong>enpos3</strong>"是我们要设置一个静态IP的网络接口。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-1.png" alt="" class="medium-zoom-image"></p>
<h2 data-id="heading-2">如何在 Debian 11 上设置一个静态 IP 地址</h2>
<p>现在,用nano编辑器打开网络接口的配置文件"<strong>/etc/network/interfaces</strong>"。</p>
<pre class="highlighter-prismjs language-shell prismjs-lines-highlighted"><code>$ sudo nano /etc/network/interfaces
复制代码</code></pre>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-2.png" alt="" class="medium-zoom-image"></p>
<p>在默认设置下,你的网络接口配置文件将看起来像这样。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-3.png" alt="" class="medium-zoom-image"></p>
<p>在"<strong>/etc/network/interfaces</strong>"文件中,添加关于你的网络接口的以下细节,如你要设置的静态<strong>IP地址</strong>、<strong>网络掩码、网关、dns-nameservers。</strong></p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-arduino"><code>auto enp0s3
iface enp0s3 inet static
address 192.168.2.2
netmask 255.255.255.0
gateway 192.168.2.2
dns-nameservers 8.8.4.4 8.8.8.8
复制代码</code></pre>
<p>这里,前两行声明我们正在为 "<strong>enpos3</strong>"网络接口设置一个静态IP地址。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-4.png" alt="" class="medium-zoom-image"></p>
<p>要保存你在网络接口配置文件中所作的修改,请按 "<strong>CTRL+O</strong>"。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-5.png" alt="" class="medium-zoom-image"></p>
<h2 data-id="heading-3">如何在 Debian 11 上重新启动网络服务</h2>
<p>在为 "<strong>enpos3</strong>"网络接口配置了静态 IP 地址之后,现在我们将使用<strong>systemctl</strong> 命令重启网络服务。</p>
<pre class="highlighter-prismjs language-ruby prismjs-lines-highlighted"><code>$ sudo systemctl restart NetworkManager.service
复制代码</code></pre>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-6.png" alt="" class="medium-zoom-image"></p>
<p>你可以验证你的 Debian 系统是否已经为你选择的网络接口配置了静态 IP。</p>
<pre class="highlighter-prismjs language-css prismjs-lines-highlighted"><code>$ ip a
复制代码</code></pre>
<p>从输出结果中,你可以看到我们已经成功地为 "<strong>enpos3</strong>"网络接口配置了静态 IP 地址 "<strong>192.168.2.2</strong>"。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-7.png" alt="" class="medium-zoom-image"></p>
<h2 data-id="heading-4">方法2:在Debian 11上使用GUI设置静态IP地址</h2>
<p><strong>蝶变11</strong>还提供了一个设施,让您可以使用它的图形用户界面来设置您的活动网络接口的静态 IP 地址。如果您想使用 Debian GUI 方法来配置静态 IP 地址,请在应用程序栏中搜索 "<strong>设置</strong>"来打开您的系统设置。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-8.png" alt="" class="medium-zoom-image"></p>
<p>在左侧菜单中的不同类别中,选择 "<strong>网络</strong>"。通过点击齿轮图标打开你的活动网络连接的设置。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-9.png" alt="" class="medium-zoom-image"></p>
<p>在打开的网络设置窗口中,点击 "<strong>IPv4</strong>"标签。为你的网络选择 "<strong>手动</strong>"IPv4方式。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-10.png" alt="" class="medium-zoom-image"></p>
<p>之后,为你的网络添加你的<strong>静态IP地址、网络掩码、网关、DNS</strong>,然后点击 "<strong>应用</strong>"按钮。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-11.png" alt="" class="medium-zoom-image"></p>
<p>现在,打开 "<strong>详细信息</strong>"标签。在这里,你将验证为你的网络添加的细节,如其IP地址。</p>
<p><img src="https://linuxhint.com/wp-content/uploads/2017/11/How-to-set-up-a-static-IP-address-on-Debian-11-12.png" alt="" class="medium-zoom-image"></p>
<p>这就是你如何在 Debian 11 上使用图形用户界面为你的网络接口设置静态 IP 地址。</p>
<h2 data-id="heading-5">总结</h2>
<p>蝶变<strong>11</strong>为您提供了为您的系统 <strong>设置静态 IP 地址</strong>的选项,无论您是想为您的网络服务器提供主机,还是为任何人提供远程访问。当您安装一个新的操作系统时,DHCP 会自动启用一个动态服务器。然而,您可以使用 Debian 终端和 GUI 来配置您的 IP 地址。在这篇文章中,你已经学会了<strong>如何</strong>用两种不同的方法<strong>在你的 Debian 11 上设置一个静态 IP 地址</strong>。</p>
</div>
</div>
</div>
<div id="MySignature" role="contentinfo">
<p>本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/17128331.html</p><br><br>
来源:https://www.cnblogs.com/HGNET/p/17128331.html
頁:
[1]