/etc/network and /etc/sysconfig/network-scripts

The directories /etc/network and /etc/sysconfig/network-scripts are used in different Linux distributions to manage network configurations. Here's a detailed explanation of these directories, their configurations, and usage.

/etc/network

This directory is primarily used in Debian-based distributions (such as Debian, Ubuntu, and their derivatives) for network interface configurations. The main configuration file here is /etc/network/interfaces.

/etc/network/interfaces

This file defines network interfaces and their configurations. Here's an example of its contents and how to configure it:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4
  • auto lo and iface lo inet loopback configure the loopback interface.

  • auto eth0 ensures that the eth0 interface is brought up automatically at boot.

  • iface eth0 inet static specifies that eth0 should use a static IP address.

Commands to Manage Network

  • Bring Up an Interface:

    sudo ifup eth0
  • Bring Down an Interface:

    sudo ifdown eth0
  • Restart Networking Service:

    sudo service networking restart

/etc/sysconfig/network-scripts

This directory is used in Red Hat-based distributions (such as RHEL, CentOS, Fedora, and their derivatives) for network configurations. Each network interface has its configuration file in this directory.

ifcfg-eth0

A typical configuration file for an interface (e.g., ifcfg-eth0) might look like this:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
  • DEVICE specifies the network device name.

  • BOOTPROTO indicates the protocol used for obtaining an IP address (none, static, dhcp).

  • ONBOOT determines whether the interface should be brought up at boot.

  • IPADDR, NETMASK, GATEWAY, DNS1, and DNS2 define the network settings.

Commands to Manage Network

  • Restart Network Service:

    sudo systemctl restart network
  • Bring Up an Interface:

    sudo ifup eth0
  • Bring Down an Interface:

    sudo ifdown eth0

Key Differences and Usage

  1. File Locations:

    • Debian-based systems: /etc/network/interfaces.

    • Red Hat-based systems: /etc/sysconfig/network-scripts/ifcfg-*.

  2. Network Management:

    • Debian-based systems use ifup and ifdown commands.

    • Red Hat-based systems use systemctl restart network to apply changes.

  3. Configuration Syntax:

    • Debian-based systems use a more declarative style in /etc/network/interfaces.

    • Red Hat-based systems use individual files for each interface with a more key-value pair style.

Conclusion

Both /etc/network and /etc/sysconfig/network-scripts are crucial for managing network interfaces in their respective Linux distributions. Understanding their configurations and usage helps in effective network management and troubleshooting in different environments.

Last updated