Debian-10-standard用`networking`服务的`/etc/network/interfaces`配置文件设置多网卡多IPv6

Debian-10-buster-standard用networking服务的/etc/network/interfaces配置文件设置多网卡多IPv6

Debian-10-buster-standard用networking服务的/etc/network/interfaces配置文件设置多网卡多IPv6 250703_123456

三块网卡 : enp0s3 , enp0s8 , enp0s9

/etc/network/interfaces 的内容👇:

bash 复制代码
# 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 enp0s3
iface enp0s3 inet dhcp
# This is an autoconfigured IPv6 interface
iface enp0s3 inet6 auto

👆上面是安装好系统后自动生成的原版, 未更改. source /etc/network/interfaces.d/*会引用 /etc/network/interfaces.d/下的所有文件, 默认有个setup

/etc/network/interfaces.d/setup 的内容👇:

bash 复制代码
auto lo
iface lo inet loopback

auto enp0s8
iface enp0s8 inet dhcp
iface enp0s8 inet6 static
address fc21::deba:1012:f5e1/16
iface enp0s8 inet6 static
address fc21::deba:1012:f5e1:ef41/16


auto enp0s9
iface enp0s9 inet6 static
address fc22::deba:1012:adad:b105:f5e1/16
iface enp0s9 inet6 static
address fc22::deba:1012:adad:f5e1/16
iface enp0s9 inet6 static
address fc22::deba:1012:f5e1/16


post-up   ip -6 addr add fc21::deba:1012:adad:f5e1/16 dev enp0s8
   up     ip -6 addr add fc21::deba:1012:adad:b105:f5e1/16 dev enp0s8
pre-down  ip -6 addr add fc21::deba:1010:adad:b105:1a11:f5e1/16 dev enp0s8

可看出, 开头的缩进并非必要, 可以没有缩进, 但每用address设置一次IP, 上面都要对应一次iface 也就是

ruby 复制代码
iface enp0s8 inet6 static
address fc21::deba:1012:f5e1/16
address fc21::deba:1012:f5e1:ef41/16

👆会报错, sudo systemctl restart networking 时不能通过, 要写成👇

ruby 复制代码
iface enp0s8 inet6 static
address fc21::deba:1012:f5e1/16
iface enp0s8 inet6 static
address fc21::deba:1012:f5e1:ef41/16

sudo systemctl restart networking

bash 复制代码
sudo systemctl restart networking

ip a 看到的配置结果

bash 复制代码
root@1235vbox-deba1012adadf5e1:/etc/apt# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:45:6d:33 brd ff:ff:ff:ff:ff:ff
    inet6 fc22::deba:1012:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fc22::deba:1012:adad:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fc22::deba:1012:adad:b105:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe45:6d33/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:77:75:2c brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 82621sec preferred_lft 82621sec
    inet6 fd17:625c:f037:2:a00:27ff:fe77:752c/64 scope global dynamic mngtmpaddr 
       valid_lft 86067sec preferred_lft 14067sec
    inet6 fe80::a00:27ff:fe77:752c/64 scope link 
       valid_lft forever preferred_lft forever
4: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:e1:3d:bc brd ff:ff:ff:ff:ff:ff
    inet 21.1.1.6/8 brd 21.255.255.255 scope global dynamic enp0s8
       valid_lft 420sec preferred_lft 420sec
    inet6 fc21::deba:1012:adad:b105:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fc21::deba:1012:adad:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fc21::deba:1012:f5e1:ef41/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fc21::deba:1012:f5e1/16 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fee1:3dbc/64 scope link 
       valid_lft forever preferred_lft forever
  • 可看出, 一个iface下只能有一个address
  • 缩进不是必须的, 缩进可有可无,
  • 可以用多个相同的iface指定多个address 如:
bash 复制代码
iface enp0s9 inet static
address IPv4-1/mask
iface enp0s9 inet static
address IPv4-2/mask
iface enp0s9 inet static
address IPv4-3/mask

iface enp0s9 inet6 static
address IPv6-1/mask
iface enp0s9 inet6 static
address IPv6-2/mask
iface enp0s9 inet6 static
address IPv6-3/mask

所以,多ip的方式有

  1. 多次iface然后address
  2. post-up ip -6 addr add ip地址 dev 网卡名
  3. up ip -6 addr add ip地址 dev 网卡名
  4. pre-down ip -6 addr add ip地址 dev 网卡名

如:给网卡ens33设定了6个IPv6

bash 复制代码
iface ens33 inet6 static
address IPv6-1/mask
iface ens33 inet6 static
address IPv6-2/mask
iface ens33 inet6 static
address IPv6-3/mask
post-up  ip -6 addr add  IPv6-4/mask  dev ens33
up       ip -6 addr add  IPv6-5/mask  dev ens33
pre-down ip -6 addr add  IPv6-6/mask  dev ens33


相关推荐
朱包林19 分钟前
day45-nginx复杂跳转与https
linux·运维·服务器·网络·云计算
孙克旭_21 分钟前
day045-nginx跳转功能补充与https
linux·运维·nginx·https
孞㐑¥2 小时前
Linux之Socket 编程 UDP
linux·服务器·c++·经验分享·笔记·网络协议·udp
M4K05 小时前
Linux百度网盘优化三板斧
linux
好奇的菜鸟6 小时前
如何在 Ubuntu 24.04 (Noble) 上使用阿里源
linux·运维·ubuntu
bcbobo21cn6 小时前
初步了解Linux etc/profile文件
linux·运维·服务器·shell·profile
望获linux6 小时前
【实时Linux实战系列】CPU 隔离与屏蔽技术
java·linux·运维·服务器·操作系统·开源软件·嵌入式软件
0wioiw07 小时前
C#基础(项目结构和编译运行)
linux·运维·服务器
2401_873587828 小时前
Linux常见指令以及权限理解
linux·运维·服务器
Arthurmoo8 小时前
Linux系统之MySQL数据库基础
linux·数据库·mysql