Debian12设置静态ip

最小化安装

如果安装图形化,可能是 NetworkManager,这部分不适用

查看网络接口的名字

1
ip a

编辑配置文件

1
sudo vim  /etc/network/interfaces

静态 ip

1
2
3
4
5
6
auto ens33
iface ens33 inet static
address 192.168.10.12
netmask 255.255.255.0
gateway 192.168.10.2
dns-nameservers 8.8.8.8 8.8.4.4
  • auto ens33:开机自动启动接口

动态 ip

1
2
auto enp0s3
iface enp0s3 inet dhcp

重启网络服务

1
sudo systemctl restart networking

开启 ipv6

先检查系统是否支持 IPv6:

1
lsmod | grep ipv6

如果没输出,可以手动加载 IPv6 模块:

1
sudo modprobe ipv6

让它在开机自动加载:

1
echo "ipv6" | sudo tee -a /etc/modules

查看是否有禁用 IPv6 的设置:

1
grep disable_ipv6 /etc/sysctl.conf /etc/sysctl.d/* 2>/dev/null

如果有类似:

1
net.ipv6.conf.all.disable_ipv6 = 1

请修改为:

1
2
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0

然后应用:

1
sudo sysctl -p

编辑网络配置文件: Debian 最小系统通常使用 ifupdown(非 NetworkManager)。

编辑网络配置文件:

1
sudo nano /etc/network/interfaces

根据你的网络情况添加 IPv6 配置。

DHCPv6 自动获取(最常见)

1
2
3
4
auto eth0
iface eth0 inet dhcp

iface eth0 inet6 auto

或者:

1
iface eth0 inet6 dhcp

(不同环境二选一,auto 会从路由器获取前缀,dhcp 会向 DHCPv6 请求。)

静态 IPv6 配置示例

如果你有固定 IPv6:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
auto eth0
iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1

iface eth0 inet6 static
    address 2404:6800:4003:c02::1234
    netmask 64
    gateway 2404:6800:4003:c02::1

重启网络服务

1
sudo systemctl restart networking

或者直接:

1
sudo ifdown eth0 && sudo ifup eth0
网站总访客数:Loading
网站总访问量:Loading

-->