Understanding the “source /etc/network/interfaces.d/*” Directive in Linux Network Configuration


10 views

In Linux systems, the /etc/network/interfaces file is the traditional way to configure network interfaces. The inclusion of source /etc/network/interfaces.d/* at the top of this file serves a specific purpose in modern network configuration management.

The source command in this context tells the system to read and process all files matching the wildcard pattern /etc/network/interfaces.d/*. This allows for:

  • Modular configuration management
  • Separation of concerns for different network interfaces
  • Easier maintenance and organization

Here's how you might structure your network configuration:

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

# Main interface configuration
auto eth0
iface eth0 inet dhcp

Then you could have separate files in /etc/network/interfaces.d/:

# /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

# /etc/network/interfaces.d/wlan0.cfg
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid MyNetwork
    wpa-psk MyPassword

Using this modular configuration offers several advantages:

  • Package Management Friendly: System packages can drop interface configurations without modifying the main file
  • Version Control: Easier to track changes when configurations are separated
  • Troubleshooting: Isolating configurations makes debugging simpler
  • Scalability: Particularly useful on servers with many network interfaces

While generally useful, there are some considerations:

  • File processing order is alphabetical - naming matters
  • Conflicting configurations might cause issues
  • Ensure proper file permissions (typically root:root with 644 permissions)

For more complex setups, you might combine this with other features:

# Conditional sourcing based on environment
if [ -d /etc/network/interfaces.d ]; then
    for file in /etc/network/interfaces.d/*.cfg; do
        [ -f "$file" ] || continue
        source "$file"
    done
fi

This approach gives you more control over which files get processed and in what order.

The source directive is supported by:

  • Debian and derivatives (Ubuntu, Mint, etc.)
  • Some other distributions may use different syntax
  • Always check your specific distribution's documentation

In Linux systems managing network interfaces, the source /etc/network/interfaces.d/* line serves a crucial modular configuration purpose. This directive tells the system to include all configuration files from the /etc/network/interfaces.d/ directory when processing network interface settings.

The source command (equivalent to . filename in bash) reads and executes commands from the specified file in the current shell environment. When used in /etc/network/interfaces, it:

1. Expands the wildcard (*) to match all files in interfaces.d/
2. Processes each file in alphabetical order
3. Combines configurations with the main interfaces file
4. Applies all settings during network service restart

Here's how you might structure your network configuration:

# Main /etc/network/interfaces file
auto lo
iface lo inet loopback

source /etc/network/interfaces.d/*

# Separate file in /etc/network/interfaces.d/eth0.cfg
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

This approach offers several advantages:

  • Clean separation of interface configurations
  • Easier management in multi-interface systems
  • Package managers can drop configs without modifying main file
  • Simpler version control for individual interface settings

For more complex setups, you might use:

# Conditional sourcing based on environment
if [ -d /etc/network/interfaces.d/${HOSTNAME} ]; then
    source /etc/network/interfaces.d/${HOSTNAME}/*
fi

# Specific file inclusion order
source /etc/network/interfaces.d/00-base
source /etc/network/interfaces.d/10-vlans
source /etc/network/interfaces.d/20-bridges

When debugging:

  1. Check file permissions (should be readable by root)
  2. Verify no syntax errors in included files
  3. Ensure proper file extensions (.cfg commonly used)
  4. Watch for conflicting configurations