小樱知识 > 数码解读 > 怎么固定ip地址(快速云:如何防止IP被盗)

怎么固定ip地址(快速云:如何防止IP被盗)

提问时间:2022-12-25 07:16:06来源:小樱知识网


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

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

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

通过 GUI 设置静态 IP 地址

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

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

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

单击 IPv4 Tab 页

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

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

单击 Apply 保存更改

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

再次单击 wired settings,以验证是否分配了新的静态 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

运行 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

完美,以上输出确认静态 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

编辑该文件并设置静态 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

保存并关闭文件

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

$ sudo systemctl restart networking.service

执行 IP 命令验证 IP 地址

$ ip add show

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

我的开源项目

酷瓜云课堂 - 开源在线教育解决方案

course-tencent-cloud(酷瓜云课堂 - gitee 仓库)course-tencent-cloud(酷瓜云课堂 - github 仓库)

以上内容就是为大家推荐的怎么固定ip地址(快速云:如何防止IP被盗)最佳回答,如果还想搜索其他问题,请收藏本网站或点击搜索更多问题

内容来源于网络仅供参考
二维码

扫一扫关注我们

版权声明:所有来源标注为小樱知识网www.cnfyy.com的内容版权均为本站所有,若您需要引用、转载,只需要注明来源及原文链接即可。

本文标题:怎么固定ip地址(快速云:如何防止IP被盗)

本文地址:https://www.cnfyy.com/smjd/847207.html

相关文章