debian修改ip地址为dhcp(怎么看dhcp分配的ip)

当我们在安装 Debian Linux 时,在安装过程中它试图从调制解调器(或 DHCP 服务器)获得 DHCP ip 地址(如果可用的话)。但是在您的系统上总是建议有一个静态 IP 地址。静态 IP 地址的主要好处是,它将在整个重新引导过程中保持持久。

在本指南中,我们将演示如何在 Debian 11 (Bullseye) 上设置静态 ip 地址。

在 Debian 11 中,我们可以通过 GUI (图形用户界面) 或命令行 (cli) 设置静态 ip 地址。

通过 GUI 设置静态 IP 地址

登录到您的 Debian Desktop 环境, 选择菜单 Settings –> Choose Network

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

点击 Wired Settings,然后我们会看到下面的窗口

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

*注意: 如果要禁用 IPv6,请进入 IPv6 Tab 页并选择 Disable 选项

单击 IPv4 Tab 页

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

上面的窗口显示已经配置了自动 DHCP,因此要配置静态 IP 的话,请选择 Manual,然后指定 IP 地址、子网掩码、网关和 dns 服务器 IP 等详细信息。

注意: 若要指定 dns 服务器 IP,请先关闭自动 dns 服务器 IP。

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

单击 Apply 保存更改

然后,通过切换禁用和启用接口,以便为接口分配新的 IP 地址。

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

再次单击 wired settings,以验证是否分配了新的静态 ip 地址。

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

完美,以上确认新的静态 IP 地址配置成功。

通过命令行设置静态 IP 地址

Open the terminal and identify the interface on which we will configure static IP address. Run below ip command

打开终端并识别网络接口,执行以下 ip 命令

$ ip add show
debian修改ip地址为dhcp(怎么看dhcp分配的ip)

运行 nmcli 命令获取连接名称

$ nmcli connection

Once we get the connection name, run below nmcli command to assign static ipv4 address,

获取连接名后,运行下面的 nmcli 命令分配静态 ipv4 地址

$ nmcli con mod 'eth0' ipv4.address 192.168.1.151/24

运行下面的命令设置网关

$ nmcli con mod 'eth0' ipv4.gateway 192.168.1.1

将配置从 DHCP 更改为手动,这样 IP 将是静态和持久的,运行

$ nmcli con mod 'eth0' ipv4.method manual

使用如下命令设置 DNS 服务器 IP 地址

$ nmcli con mod 'eth0' ipv4.dns '8.8.8.8'

禁用并启用连接,以便上述更改生效。

$ nmcli connection down eth0
$ nmcli connection up eth0

运行 IP 命令查看 IP 地址

$ ip add show eth0
debian修改ip地址为dhcp(怎么看dhcp分配的ip)

完美,以上输出确认静态 IP 地址已在 eth0 接口上成功配置。

在最小安装的 Debian 11 上设置静态 IP 地址

Whenever we install minimal Debian 11 then we will have only the CLI console and don’t have any nmcli utility. So, to configure static ip address we will edit the file ‘/etc/network/interfaces’.

每当我们安装最小的 Debian 11 时,我们只有 CLI 控制台,并且没有任何 nmcli 实用程序。因此,要配置静态 IP 地址,我们需要编辑 /etc/network/interfaces 文件。

查看文件的默认内容

$ cat /etc/network/interfaces
debian修改ip地址为dhcp(怎么看dhcp分配的ip)

编辑该文件并设置静态 IP 地址,如下所示

$ sudo vi /etc/network/interfaces

删除 allow-htplug enp0s3 行,修改 dhcp 参数为 static。下面是我的示例文件,根据您的环境更改接口名称和 ip 详细信息。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet static
 address 192.168.1.183
 netmask 255.255.255.0
 gateway 192.168.1.1
 dns-nameservers 8.8.8.8

保存并关闭文件

debian修改ip地址为dhcp(怎么看dhcp分配的ip)

要使上述更改生效,必须重新启动网络服务

$ sudo systemctl restart networking.service

执行 IP 命令验证 IP 地址

$ ip add show
debian修改ip地址为dhcp(怎么看dhcp分配的ip)

以上就是本文的全部内容,请在下面的评论区分享你的反馈和疑问。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至2705686032@qq.com 举报,一经查实,本站将立刻删除。文章链接:https://www.zun.com/zx/yunwei/4204.html

(0)
尊云服务器的头像尊云服务器
上一篇 2024 年 4 月 20 日 08:07
下一篇 2024 年 4 月 20 日 08:13

相关推荐

发表回复

登录后才能评论

联系我们

400-900-3935

在线咨询: QQ交谈

邮件:cong@zun.com

工作时间:365天无休服务 24小时在线

添加微信