Red Hat Training

A Red Hat training course is available for RHEL 8

Chapter 31. Configuring ip networking with ifcfg files

Interface configuration (ifcfg) files control the software interfaces for individual network devices. As the system boots, it uses these files to determine what interfaces to bring up and how to configure them. These files are named ifcfg-name_pass, where the suffix name refers to the name of the device that the configuration file controls. By convention, the ifcfg file’s suffix is the same as the string given by the DEVICE directive in the configuration file itself.

Important

NetworkManager supports profiles stored in the keyfile format. However, by default, NetworkManager uses the ifcfg format when you use the NetworkManager API to create or update profiles.

In a future major RHEL release, the keyfile format will be default. Consider using the keyfile format if you want to manually create and manage configuration files. For details, see NetworkManager connection profiles in keyfile format.

31.1. Configuring an interface with static network settings using ifcfg files

If you do not use the NetworkManager utilities and applications, you can manually configure a network interface by creating ifcfg files.

Procedure

  • To configure an interface with static network settings using ifcfg files, for an interface with the name enp1s0, create a file with the name ifcfg-enp1s0 in the /etc/sysconfig/network-scripts/ directory that contains:

    • For IPv4 configuration:

      DEVICE=enp1s0
      BOOTPROTO=none
      ONBOOT=yes
      PREFIX=24
      IPADDR=192.0.2.1
      GATEWAY=192.0.2.254
    • For IPv6 configuration:

      DEVICE=enp1s0
      BOOTPROTO=none
      ONBOOT=yes
      IPV6INIT=yes
      IPV6ADDR=2001:db8:1::2/64

Additional resources

  • nm-settings-ifcfg-rh(5) man page

31.2. Configuring an interface with dynamic network settings using ifcfg files

If you do not use the NetworkManager utilities and applications, you can manually configure a network interface by creating ifcfg files.

Procedure

  1. To configure an interface named em1 with dynamic network settings using ifcfg files, create a file with the name ifcfg-em1 in the /etc/sysconfig/network-scripts/ directory that contains:

    DEVICE=em1
    BOOTPROTO=dhcp
    ONBOOT=yes
  2. To configure an interface to send:

    • A different host name to the DHCP server, add the following line to the ifcfg file:

      DHCP_HOSTNAME=hostname
    • A different fully qualified domain name (FQDN) to the DHCP server, add the following line to the ifcfg file:

      DHCP_FQDN=fully.qualified.domain.name
    Note

    You can use only one of these settings. If you specify both DHCP_HOSTNAME and DHCP_FQDN, only DHCP_FQDN is used.

  3. To configure an interface to use particular DNS servers, add the following lines to the ifcfg file:

    PEERDNS=no
    DNS1=ip-address
    DNS2=ip-address

    where ip-address is the address of a DNS server. This will cause the network service to update /etc/resolv.conf with the specified DNS servers specified. Only one DNS server address is necessary, the other is optional.

31.3. Managing system-wide and private connection profiles with ifcfg files

By default, all users on a host can use the connections defined in ifcfg files. You can limit this behavior to specific users by adding the USERS parameter to the ifcfg file.

Prerequisite

  • The ifcfg file already exists.

Procedure

  1. Edit the ifcfg file in the /etc/sysconfig/network-scripts/ directory that you want to limit to certain users, and add:

    USERS="username1 username2 ..."
  2. Reactive the connection:

    # nmcli connection up connection_name