14

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!

1 Answer 1

14

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.

2
  • Thanks! I think this is what I am looking for! And you are absolutely right it is in their documentation, I think I was reading the man interfaces from another older version. For my purposes I want to put the VLAN's in a separate file for easier editing. Once again thanks, I will test it.
    – joze
    Jul 23, 2013 at 21:42
  • $man 5 interfaces (...) By default, on a freshly installed Debian system, the interfaces file includes a line to source files in the /etc/network/interfaces.d directory. So, at some point, you might just drop your interface snippets in /etc/network/interfaces.d But note that although the 'man' says the above sentence in Ubuntu 16.04, a fresh install of Ubuntu 16.04 does NOT have this feature "by default", you still have to add a line to source snippets.
    – Zakhar
    Dec 26, 2017 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .