Debian 11 网络配置文件
Debian 11 网络配置文件为:/etc/network/interfaces 。
默认配置使用 DHCP,安装过程并没有手动配置提示。内容如下:
$ cat /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 #ens33 修改为 eth0
iface ens33 inet dhcp #ens33 修改为 eth0
修改 IP 地址:
sudo vi /etc/network/interfaces
# 修改为以下内容:
iface lo inet loopback
auto lo
auto eth0
iface eth0 inet static
address 10.10.1.5
netmask 255.255.255.0
#broadcast 10.10.1.255 #可选,上述配置了掩码
#network 10.10.1.0 #可选,上述配置了掩码
gateway 10.10.1.1
#dns-domain example.com
# domain 和 search 不能共存;如果同时存在,后面出现的将会被使用。
dns-search sysin.org
dns-nameservers 10.10.1.1 8.8.8.8 #注意 debian 11 默认没有安装 resolvconf,所以需要手动在
resolv.conf 中编辑 DNS
# 或者安装 resolvconf 后,在这里配置,将自动更新 resolv.conf
sudo apt install resolvconf
# iface eth0 inet6 auto #ipv6 自动配置,不写则表示禁用了
# DHCP 配置如下:
auto eth0
iface eth0 inet dhcp
# 配置 DNS
cat /etc/resolv.conf #如果已经安装 resolvconf,不要手动编辑,直接在上述 interfaces 中编辑 dns
# 重启网络
sudo systemctl restart networking
#sudo service networking restart
可以看到 Debian 网络配置方法并没有变更,Ubuntu 16.04 也是这样配置,但是 18.04 开始使用
netplan,20.04 同样使用 netplan 但是默认配置文件名称再次变更。
配置多个 IP:
auto eth0:0
iface eth0:0 inet static
address 192.168.1.90
netmask 255.255.255.0
auto eth0:1
iface eth0:1 inet static
address 192.168.1.91
netmask 255.255.255.0
添加静态路由(Linux 通用,临时,重启消失):
route add -net 10.10.11.0/24 gw 10.10.1.1
Debian 配置永久静态路由:
#添加
cat >> /etc/network/interfaces << EOF
# static routes
up ip route add 10.10.12.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.13.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.14.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.15.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.16.0/24 via 10.10.1.1 dev eth0
EOF
#重启网络
systemctl restart networking
#验证
ip route