Este conteúdo não está disponível no idioma selecionado.
3.5. Configuring IP Networking with ifcfg Files
As a system administrator, you can configure a network interface manually, editing the
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 usually named
ifcfg-name, 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.
Configuring an Interface with Static Network Settings Using ifcfg Files
For example, 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
IPv4configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - For
IPv6configurationYou do not need to specify the network or broadcast address as this is calculated automatically by ipcalc.Copy to Clipboard Copied! Toggle word wrap Toggle overflow For moreIPv6ifcfg configuration options, see nm-settings-ifcfg-rh(5) man page.
Important
In Red Hat Enterprise Linux 7, the naming convention for network interfaces has been changed, as explained in Chapter 11, Consistent Network Device Naming. Specifying the hardware or MAC address using
HWADDR directive can influence the device naming procedure.
Configuring an Interface with Dynamic Network Settings Using ifcfg Files
To configure an interface named em1 with dynamic network settings using
ifcfg files:
- Create a file with the name
ifcfg-em1in the/etc/sysconfig/network-scripts/directory, that contains:DEVICE=em1 BOOTPROTO=dhcp ONBOOT=yes
DEVICE=em1 BOOTPROTO=dhcp ONBOOT=yesCopy to Clipboard Copied! Toggle word wrap Toggle overflow - To configure an interface to send a different host name to the
DHCPserver, add the following line to theifcfgfile:DHCP_HOSTNAME=hostname
DHCP_HOSTNAME=hostnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow To configure an interface to send a different fully qualified domain name (FQDN) to theDHCPserver, add the following line to theifcfgfile:DHCP_FQDN=fully.qualified.domain.name
DHCP_FQDN=fully.qualified.domain.nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note
Only one directive, eitherDHCP_HOSTNAMEorDHCP_FQDN, should be used in a givenifcfgfile. In case bothDHCP_HOSTNAMEandDHCP_FQDNare specified, only the latter is used. - To configure an interface to use particular
DNSservers, add the following lines to theifcfgfile:where ip-address is the address of aPEERDNS=no DNS1=ip-address DNS2=ip-address
PEERDNS=no DNS1=ip-address DNS2=ip-addressCopy to Clipboard Copied! Toggle word wrap Toggle overflow DNSserver. This will cause the network service to update/etc/resolv.confwith the specifiedDNSservers specified. Only oneDNSserver address is necessary, the other is optional. - To configure static routes in the
ifcfgfile, see Section 4.5, “Configuring Static Routes in ifcfg files”.By default, NetworkManager calls theDHCPclient, dhclient, when a profile has been set to obtain addresses automatically by settingBOOTPROTOtodhcpin an interface configuration file. IfDHCPis required, an instance of dhclient is started for every Internet protocol,IPv4andIPv6, on an interface. If NetworkManager is not running, or is not managing an interface, then the legacy network service will call instances of dhclient as required. For more details on dynamic IP addresses, see Section 1.2, “Comparing Static to Dynamic IP Addressing”. - To apply the configuration:
- Reload the updated connection files:
nmcli connection reload
# nmcli connection reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Re-activate the connection:
nmcli connection up connection_name
# nmcli connection up connection_nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.5.1. Managing System-wide and Private Connection Profiles with ifcfg Files Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
The permissions correspond to the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
USERS directive in the ifcfg files. If the USERS directive is not present, the network profile will be available to all users. As an example, the following command in an ifcfg file will make the connection available only to the users listed: USERS="joe bob alice"
USERS="joe bob alice"
Also, you can set the
USERCTL directive to manage the device:
- If you set yes, non-
rootusers are allowed to control this device. - If you set no, non-
rootusers are not allowed to control this device.