侧边栏壁纸
博主头像
晓然博主等级

梦想是沉淀和积累的结果.

  • 累计撰写 18 篇文章
  • 累计创建 11 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Debian11 设置静态ip

晓然
2022-07-15 / 0 评论 / 0 点赞 / 432 阅读 / 390 字
温馨提示:
本文最后更新于 2023-04-29,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1.查看主机的网卡名、ip、子网掩码、网关地址

可以使用ip a ip route show来查看网卡名称、ip、子网掩码以及网关地址等信息

ip_message从上可以看出,网卡名为ens33、ipv4地址为192.168.153.133、子网掩码为255.255.255.0、网关地址为192.168.153.2

2.修改配置文件

修改配置文件/etc/network/interfaces

$ sudo vim /etc/network/interfaces

默认的配置文件看起来是这样的

# 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 ens33
iface ens33 inet dhcp                   

在配置文件中添加网卡名称、ipv4地址、网关以及子网掩码等信息,注意要修改成自己的。

auto ens33 #网卡名称为ens33
iface ens33 inet static 
address 192.168.153.133 #ipv4地址
netmask 255.225.225.0 #子网掩码
gateway 192.168.153.2 #网关
dns-nameservers 114.114.114.144 8.8.8.8 #dns

配置文件/etc/network/interfaces最终效果如下:

...
# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.153.143
netmask 255.255.255.0
gateway 192.168.153.2
dns-nameservers 114.114.114.144 8.8.8.8

3. 重启网络使配置文件生效

#重启网络使配置文件生效
$ sudo systemctl restart networing
# 查看生效后的ipv4地址
$ ip a

image-20230118040147805

4. 小结

修改配置配置文件/etc/network/interfaces,添加静态ipv4地址以及网关等信息,最后systemctl restart networing重启网络即可

0
  • 0

评论区