惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
博客园_首页
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
B
Blog RSS Feed
D
Docker
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
V
V2EX
量子位
雷峰网
雷峰网
月光博客
月光博客
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog

梦荟楼的后花园

玩转OpenClaw(Moltbot)|启用webui-梦荟楼的后花园 玩转OpenClaw(Moltbot)|重生之我用ai自动考试-梦荟楼的后花园 银河麒麟CVE-2025-6019漏洞排查和修复-梦荟楼的后花园 国产系统(kylin、uos)维护工具推荐-梦荟楼的后花园 debian常用命令、配置文件位置及配置方式-梦荟楼的后花园 华为防火墙多wan口指定接口进行dns透明代理-梦荟楼的后花园 华为防火墙光电互斥口切换模式-梦荟楼的后花园 天融信防火墙设置双向地址转换-梦荟楼的后花园 1panel添加群晖webdav作为备份账号-梦荟楼的后花园 Windows映射文件夹-梦荟楼的后花园 linux下使用硬盘哨兵查看raid下硬盘健康状态-梦荟楼的后花园 Windows命令查看文件的MD5/SHA1/SHA256-梦荟楼的后花园 雷池最佳实践-梦荟楼的后花园 matomo设置使用cdn获取真实客户端IP-梦荟楼的后花园 Linux硬盘io测试-梦荟楼的后花园 雷池专业版4.3.0测评💦-梦荟楼的后花园 长亭新春礼盒开箱-梦荟楼的后花园 盈高准入加密U盘或移动硬盘时一直提示正在等待Windows加载系统盘符-梦荟楼的后花园 华为交换机解决设备观察端口不足的问题-梦荟楼的后花园
Debian12配置静态ipv4和ipv6-梦荟楼的后花园
梦荟楼 · 2024-02-13 · via 梦荟楼的后花园

环境

系统: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

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