How to modify network configuration by editing configuration files in CentOS/RHEL 7 and 8
DESCRIBING CONNECTION CONFIGURATION FILES
By default, changes made with nmcli con mod name are automatically saved to /etc/ sysconfig/network-scripts/ifcfg-name. That ﬁle can also be manually edited with a text editor. After doing so, run nmcli con reload so that NetworkManager reads the conﬁguration changes.
For backward-compatibility reasons, the directives saved in that ﬁle have different names and syntax than the nm-settings(5) names. The following table maps some of the key setting names to ifcfg-* directives.
Comparison of nm-settings and ifcfg-* Directive
|NMCLI CON MOD||IFCFG-* FILE||EFFECT|
|ipv4.method manual||BOOTPROTO=none||IPv4 addresses configured statically.|
|ipv4.method auto||BOOTPROTO=dhcp||Looks for configuration settings from a DHCPv4 server. If static addresses are also set, will not bring those up until we have information from DHCPv4.|
|ipv4.addresses “192.0.2.1/24 192.0.2.254”||IPADDR0=192.0.2.1 PREFIX0=24 GATEWAY0=192.0.2.254||Sets static IPv4 address, network prefix, and default gateway. If more than one is set for the connection, then instead of 0, the ifcfg-* directives end with 1, 2, 3 and so on.|
|ipv4.dns 184.108.40.206||DNS0=220.127.116.11||Modify /etc/resolv.conf to use this nameserver.|
|ipv4.dns-search example.com||DOMAIN=example.com||Modify /etc/resolv.conf to use this domain in the search directive.|
|ipv4.ignore-auto-dns true||PEERDNS=no||Ignore DNS server information from the DHCP server.|
|ipv6.method manual||IPV6_AUTOCONF=no||IPv6 addresses configured statically.|
|ipv6.method auto||IPV6_AUTOCONF=yes||Configures network settings using SLAAC from router advertisements.|
|ipv6.method dhcp||IPV6_AUTOCONF=no DHCPV6C=yes||Configures network settings by using DHCPv6, but not SLAAC.|
|ipv6.addresses “2001:db8::a/64 2001:db8::1”||IPV6ADDR=2001:db8::a/64 IPV6_DEFAULTGW=2001:db8||Sets static IPv6 address, ::n1etwork prefix, and default gateway. If more than one address is set for the connection, IPV6_SECONDARIES takes a double-quoted list of space- delimited address/prefix definitions.|
|ipv6.dns …||DNS0= …||Modify /etc/resolv.conf to use this nameserver. Exactly the same as IPv4.|
|ipv6.dns-search example.com||DOMAIN=example.com||Modify /etc/resolv.conf to use this domain in the search directive. Exactly the same as IPv4.|
|ipv6.ignore-auto-dns true||IPV6_PEERDNS=no||Ignore DNS server information from the DHCP server.|
|connection.autoconnect yes||ONBOOT=yes||Automatically activate this connection at boot.|
|connection.id ens3||NAME=ens3||The name of this connection.|
|connection.interface- name ens3||DEVICE=ens3||The connection is bound to the network interface with this name.|
|802-3-ethernet.mac- address . . .||HWADDR= …||The connection is bound to the network interface with this MAC address.|
Modifying Network Configuration
It is also possible to conﬁgure the network by directly editing the connection conﬁguration ﬁles. Connection conﬁguration ﬁles control the software interfaces for individual network devices. These ﬁles are usually named /etc/sysconfig/network-scripts/ifcfg-name, where name refers to the name of the device or connection that the conﬁguration ﬁle controls. The following are standard variables found in the ﬁle used for static or dynamic IPv4 conﬁguration.
IPv4 Conﬁguration Options for ifcfg File
BOOTPROTO=none IPADDR0=172.25.250.10 PREFIX0=24 GATEWAY0=172.25.250.254 DEFROUTE=yes DNS1=172.25.254.254
DEVICE=ens3 NAME="static-ens3" ONBOOT=yes UUID=f3e8(...)ad3e USERCTL=yes
In the static settings, variables for IP address, preﬁx, and gateway have a number at the end. This allows multiple sets of values to be assigned to the interface. The DNS variable also has a number used to specify the order of lookup when multiple servers are speciﬁed.
After modifying the conﬁguration ﬁles, run nmcli con reload to make NetworkManager read the conﬁguration changes. The interface still needs to be restarted for changes to take effect.
[[email protected] ~]# nmcli con reload [[email protected] ~]# nmcli con down "static-ens3" [[email protected] ~]# nmcli con up "static-ens3"