单独的 /etc/network/interfaces 文件

单独的 /etc/network/interfaces 文件

我想知道是否可以将配置从 /etc/network/interfaces 文件中分离到单独的文件中,例如一个文件中的一个节,另一个文件中的另一个节?(类似于 CentOS)。或者是否可以从 /etc/network/interfaces 文件中调用其他接口文件?我的想法是将以太网节放在一个文件中,将 vlan 节放在另一个文件中,将 vpn 节放在另一个文件中,等等(或类似文件)。通过这种方式,我可以更轻松地编辑和解析(是的,我知道有解析器),但我认为将它们分开放在不同的文件中会更有条理。

我已经尝试在 Google 和人机界面上寻找答案好几天了,但什么也没找到。我认为这是不可能的(除非修改操作系统的源代码)。有人知道这件事吗?

我正在使用 Ubuntu 12.04 LTS Server x64

谢谢!

答案1

这当然是可能的。请参阅接口(5)手册页了解完整详细信息,但我将在此处附上手册页的片段:

   Lines beginning with "source" are used to include stanzas from other  files,  so
   configuration can be split into many files. The word "source" is followed by the
   path of file to be sourced. Shell wildcards can be used.   (See  wordexp(3)  for
   details.)

此功能出现在 Precise 中。

例子:

在 /etc/网络/接口:

   auto lo
   iface lo inet loopback

   source /etc/network/interfaces.d/*.cfg

/etc/network/interfaces.d/eth0.cfg:

    auto eth0
    iface eth0 inet static
        address x.x.x.x
        [...]

我会谨慎地考虑一些工具是否已经意识到这个功能。一些脚本可能只检查 /etc/network/interfaces。

相关内容