侧边栏壁纸
博主头像
梦荟楼的后花园博主等级

干啥啥不行干饭第一名

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

目 录CONTENT

文章目录

Debian12配置静态ipv4和ipv6

梦荟楼
2024-02-13 / 0 评论 / 6 点赞 / 230 阅读 / 4820 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2024-02-13,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

环境

系统:Debian12

网络环境:ipv4 ipv6均为静态ip

配置

编辑配置文件

配置思路:在动配置文件前先备份配置文件(在动配置文件前先备份是个良好的习惯),然后再编辑interfaces

备份和打开配置文件

备份原有配置文件配置文件

interface 配置文件复制并重命名为 interfacesbak

cp /etc/network/interfaces /etc/network/interfacesbak 
打开interfaces
vim /etc/network/interfaces

示例如图所示

image-rxzl.png

# 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


allow-hotplug eth0
iface eth0 inet static
address 192.168.1.233
netmask 255.255.255.0
gateway 192.168.1.1

iface eth0 inet6 static
address fe80:66:666:666::1FA2
netmask 64
gateway fe80:66:666:666::1

ipv4静态IP配置

iface eth0 inet static
address 192.168.1.233
netmask 255.255.255.0
gateway 192.168.1.1

将eth0设置为ipv4静态模式 iface eth0 inet static static表示使用固定ip,dhcp表述使用动态ip
将IP设置为192.168.1.233 address 192.168.1.233
将掩码设置为24位 netmask 255.255.255.0
将网关设置为192.168.1.1 gateway 192.168.1.1

ipv6静态IP配置

配置思路:先确认debian是否开启了ipv6然后再去配置静态IP, 不然就算配置了ipv6也不会生效

检查系统是否开启ipv6
确认是否加载ipv6内核
lsmod | grep ipv6

如果有类似的输出,则表示已经加载

nf_reject_ipv6         20480  1 ip6t_REJECT
nf_defrag_ipv6         24576  1 nf_conntrack
检查系统是否开启ipv6
cat /proc/sys/net/ipv6/conf/all/disable_ipv6

如果输出 0 ,则表示启用了,如果输入 1 则表示没有启用

若输出为1则需编辑配置文件 /etc/sysctl.conf 若输出为0则忽略以下内容

vim /etc/sysctl.conf

找到 net.ipv6.conf.all.disable\_ipv6 = 1 ,将1改为0即可。

重启网络和系统

systemctl restart networking.service
reboot
配置静态ipv6
iface eth0 inet6 static
address fe80:66:666:666::1FA2
netmask 64
gateway fe80:66:666:666::1

将eth0设置为ipv6静态模式 iface eth0 inet6 static static表示使用固定ip,dhcp表述使用动态ip
将IP设置为fe80:66:666:666::1FA2 address fe80:66:666:666::1FA2
将掩码设置为64位 netmask 64
将网关设置为fe80:66:666:666::1 gateway fe80:66:666:666::1

小知识

代码示例

# 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


allow-hotplug eth0
iface eth0 inet static
address 192.168.1.233
netmask 255.255.255.0
gateway 192.168.1.1

iface eth0 inet6 static
address fe80:66:666:666::1FA2
netmask 64
gateway fe80:66:666:666::1

allow-hotplugauto的区别

auto

在系统启动的时候启动网络接口,无论网络接口有无连接 (插入网线)。如果该接口配置了 DHCP,则无论有无网线,系统都会去获取 DHCP。并且如果没有插入网线,则等该接口超时后才会继续 DHCP。

allow-hotplug

只有当内核从网络接口检测到热插拔事件后才会启动该接口。如果系统开机时该接口没有插入网线,则系统不会启动该接口。系统启动后,如果插入网线,系统会自动启动该接口。

6

评论区