当我们在安装 Debian Linux 时,在默认使用 DHCP 获取ip 地址,本文介绍如果在路由器不支持固定ip的情况下系统获取一个不会变化的ip地址

演示环境:

debian12官方网络安装镜像全新安装无gui环境
配置文件默认内容:

# 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
allow-hotplug enp2s0
iface enp2s0 inet dhcp

配置文件默认内容

固定IP地址

  1. 打开/etc/network/interfaces文件
nano /etc/network/interfaces
  1. 修改dhcp为static enp2s0用你自己的不要改
iface enp2s0 inet static
#使用静态地址
address 192.168.31.254
#固定的ip地址
netmask 255.255.255.0
#子网掩码
gateway 192.168.31.1
#网关地址
iface enp2s0 inet6 dhcp
#启用ipv6 dhcp

修改结果如图:

按下ctrl+x 回车
输入 y 回车
即可保存

重启网卡

systemctl restart networking.service

愿这盛世 每一天