linux - 使用可预测的网络接口(interface)名称

标签 linux networking debian

我第一次面对新的网络接口(interface)命名方案:可预测的网络接口(interface)名称。

我的问题与这个方案是好是坏无关……我只是想了解如何正确使用它。

Here我阅读:

When changing the interface naming scheme, do not forget to update all network-related configuration files and custom systemd unit files to reflect the change.

所以我必须在所有配置文件中写入实际的接口(interface)名称。在之前的方案中,它是 eth0,它只是表示第一个以太网卡,如果有多个接口(interface),则有已知的注意事项。

现在,我必须编写可预测的名称,它由一些简单的部分(即接口(interface)类型)和其他不可预测的部分组成,例如MAC 地址。据我所知,每张卡片都有不同的名称。

我承认我的问题可能看起来很傻,但我不明白如何准备配置文件。让我们看一个例子,/etc/dhcpcd.conf:

profile static_eth0
static ip_address=192.168.1.23/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface eth0
fallback static_eth0

我应该在 o.s. 中放什么而不是 eth0图像? 只有当我运行目标机器时,我才能检索以太网接口(interface)的实际名称。

我的系统 100% 都是 headless 的,我从不为它们连接键盘和显示器。此外,如果我必须发送 SBC 的备用部件,我是否需要重新配置所有部件?

你能帮我理解正确的用法吗?

附言。我知道我可以恢复到旧的命名方案...但这不是我的问题的重点。

最佳答案

参见 https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ 它解释了名称是如何分配的

Names incorporating Firmware/BIOS provided index numbers for on-board devices (example: eno1)
Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1)
Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0)
Names incorporating the interfaces's MAC address (example: enx78e7d1ea46da)
Classic, unpredictable kernel-native ethX naming (example: eth0)

By default, systemd v197 will now name interfaces following policy 1) if that
information from the firmware is applicable and available, falling back to 2) if
that information from the firmware is applicable and available, falling back to 3)
if applicable, falling back to 5) in all other cases. Policy 4) is not used by 
default, but is available if the user chooses so. 

因此您可以选择不同的方法,可能在您的设置中最简单的方法是使用 mac,只需在尝试 pxe/dhcp 请求的图像重新启动并记下发送的 mac 后即可。

根据您的设置,另一种可能有效的方法是界面分组。

来自“人机界面”

   auto /eth*

   If the kernel knows about the interfaces with names lo, eth0 and eth1, then the above line is then interpreted as:

   auto eth0 eth1

   Note that there must still be valid "iface" stanzas for each matching interface.  However, it is possible to combine a pattern with a mapping to a logical interface, like so:

   auto /eth*=eth
   iface eth inet dhcp

所以也许如果你只有一个接口(interface),但不知道它将被分配到哪里,你可以写“auto/e*=eth”来捕获所有以 e 开头的接口(interface),并在配置文件中将它们寻址为“伦理”。

关于linux - 使用可预测的网络接口(interface)名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838574/

相关文章:

R - 通过 ssh 连接并执行命令

C# 测试事件的互联网连接。 ping google.com

c# - 开发游戏服务器的好语言?

linux - 在自动启动中以 root 身份执行脚本

linux - 在 Ubuntu 中个性化差异命令

regex - 将正则表达式与 grep 结合使用来过滤详细命令输出中的数据

linux - 为什么在 x64 程序集中将复制变量地址移动到寄存器?

debian - 如何在Debian服务器上安装最新的libcurl?

linux - 在 MACOS 的 VM 中安装 Debian 中的 Gnome

linux - 在 ksh 中拆分字符串