单独的 /etc/network/interfaces 文件

joz*_*oze 14 networking

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

我试图在谷歌和人界面上寻找答案几天,但我没有找到任何东西。我认为这是不可能的(除非我想从操作系统修改源代码)。任何人都知道这件事吗?

我正在使用 Ubuntu 12.04 LTS 服务器 x64

谢谢!

小智 14

这当然是可能的。有关完整详细信息,请参阅 interfaces(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.)
Run Code Online (Sandbox Code Playgroud)

此功能出现在 Precise 中。

例子:

/etc/network/interfaces:

   auto lo
   iface lo inet loopback

   source /etc/network/interfaces.d/*.cfg
Run Code Online (Sandbox Code Playgroud)

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

    auto eth0
    iface eth0 inet static
        address x.x.x.x
        [...]
Run Code Online (Sandbox Code Playgroud)

我会谨慎对待某些工具是否还知道此功能。某些脚本可能只检查 /etc/network/interfaces。