/etc/network/interfaces

The /etc/network/interfaces file is used to configure network interfaces on Debian-based Linux distributions (such as Ubuntu, Debian, and others). This file contains network settings that define how each interface is configured, whether through static IP, DHCP, or manual configuration.

Structure of /etc/network/interfaces

The file is made up of sections that define the configuration for individual network interfaces. Each section can include settings such as IP addresses, netmasks, gateways, and other network options.

Here are the key configuration options commonly used in the /etc/network/interfaces file:

Common Directives

  • iface: This defines a network interface and its associated configuration.

    • iface <interface> <method>: The interface (<interface>) is configured using the specified method (<method>).

  • auto: Automatically brings up the network interface during boot.

  • allow-hotplug: Brings up the interface when it's detected (without waiting for boot).

  • address: Specifies the static IP address.

  • netmask: Specifies the subnet mask.

  • gateway: Specifies the default gateway.

  • dns-nameservers: Specifies the DNS server addresses.

  • dns-search: Specifies the DNS search domain.

  • dhcp: Indicates that the interface should use DHCP for obtaining network settings automatically.

  • bridge_ports: Defines the interfaces to be added to a bridge.

  • bridge_stp: Enables or disables Spanning Tree Protocol (STP) on the bridge.

  • vlan-raw-device: Associates a VLAN interface with a physical network interface.

Example Configuration

  1. Static IP Configuration

    This example configures an interface eth0 with a static IP address.

    • The eth0 interface is set with the static IP 192.168.1.100, netmask 255.255.255.0, and gateway 192.168.1.1. DNS servers are set to Google's 8.8.8.8 and 8.8.4.4.

  2. DHCP Configuration

    This example configures the interface eth0 to obtain its IP address via DHCP.

    • The eth0 interface is set to use DHCP to automatically obtain an IP address.

  3. Multiple Interfaces with Static IPs

    You can configure multiple interfaces with static IP addresses.

    • The system has two interfaces: eth0 and eth1, each with a static IP.

  4. Bridge Configuration

    If you're using network bridging, you can configure a bridge interface like this:

    • The bridge interface br0 is created by combining eth0 and eth1 and is assigned a static IP.

  5. VLAN Configuration

    If you're using VLANs, you can create a VLAN interface as follows:

    • This configuration creates a VLAN interface vlan10 on eth0 with a static IP.

  6. Allow Hotplugging an Interface

    If you want an interface to be automatically brought up when it's plugged in (e.g., for USB network devices), you can use allow-hotplug.

    • The interface eth0 is configured to automatically come up when it is detected and use DHCP.

Managing Network Interfaces

After making changes to /etc/network/interfaces, you can apply them using the following commands:

  • Restart the networking service to apply the changes:

  • Bring up an interface manually:

  • Bring down an interface manually:

  • Check the interface status:

Conclusion

The /etc/network/interfaces file is a key configuration file for network interfaces on Debian-based Linux systems. It allows you to configure interfaces for static IPs, DHCP, bridges, VLANs, and hotplugging. After editing this file, network changes can be applied by restarting the networking service or bringing interfaces up/down manually.

Last updated