Ubuntu – Separate /etc/network/interfaces file

networking

I was wondering if it is possible to separate the configuration from /etc/network/interfaces file into separate files, like one stanza in one file and another stanza in another file? (similar to CentOS). Or from /etc/network/interfaces file is it possible to call other interfaces files? My idea is to have ethernet stanzas in one file, vlan's in another, vpn's in another, etc (or something similar). By doing it this way, it would be easier for me to edit and parse (yes I know there are parsers out there), but I think by having them separate in different files it would be more organized.

I have tried to look for answers in google for several days, and man interfaces but I haven't found anything. I'm thinking is not possible (unless modifying source code from the OS I guess). Anyone knows anything about this?

I'm using Ubuntu 12.04 LTS Server x64

Thanks!

Best Answer

This is certainly possible. See the interfaces(5) manpage for full details, but I'll include a fragment of the man page here:

   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.)

This feature appears in Precise.

Example:

/etc/network/interfaces:

   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
        [...]

I'd be cautious whether some tools are yet aware of this feature. Some scripts may only check /etc/network/interfaces.

Related Question