Configuring Network Interfaces

Howto configure a Linux network interface card

Network Configuration

The following is a basic guide for the configuring of network settings on Red Hat Enterprise Linux 7.0, CentOS 7.0 and Oracle Linux 7.0 servers. In the following examples we will cover how to manually configure the network by editing configuration files and how to use new Network Manager configuration tool "nmtui". In most cases, Red Hat 7.0 based servers will automatically configure any active interfaces found during the installation process. However, there will be times when you will want to add additional interfaces, assign static IP addresses or switch to using DHCP. The following examples were all carried out on a standard Red Hat Enterprise Linux 7.0 server configured with a desktop GUI.

Location of Network Configuration Files

The following files are used for the configuration of network settings. These settings include Network Interfaces, Routing, DNS, Domain Search order, configuring of the hostname and host file resolution. These files can be manually modified with a text editor of your choice or by using the recommended network tool "nmtui".

Network Interface Files

The location of the network interface files used for holding the configuration settings of our interfaces and routing can be found in the following location:


Interfaces generally follow the naming convention of: ifcfg-eth0

The "ifcfg" indicates that this is an interface config file and the latter part of the name identifies the interface. Traditionally interfaces were called eth0, eth1, eth2 and so on, however, under Red Hat 7, interfaces are automatically named after the adapter. On this particular system the interface is called "ifcfg-enp0s3". Static routing files can also be found in this location. These are identified by the prefix of "route".

Interfaces: ifcfg-interface
Routing: route-interface

DHCP vs Static IP Addressing

For most desktop scenarios using DHCP (Dynamic Host Configuration Protocol) to obtain an IP address automatically is generally acceptable. However, most servers in a production environment will have a static IP address assigned. During a basic installation, you can specify whether you wish to configure the network manually or accept a DHCP address.

DHCP IP Addressing

DHCP (Dynamic Host Configuration Protocol) is the name given to a protocol for the assigning of IP addresses automatically to a network interface at system startup. These IP addresses are leased for a set period of time. This means that over a period of time the IP address may change.

Static IP Addressing

Static IP addresses are IP addresses that have been manually assigned to an interface. Unlike DHCP, these IP addresses will remain assigned to the interface until manually changed by an administrator. Most server environments will use static IP addressing.

Example DHCP configuration file - ifcfg-enp0s3

The important parameters here are: BOOTPROTO=dhcp for a dhcp connection type.


Example Static IP Addresses Configuration file - ifcfg-enp0s8

The important parameters here are BOOTPROTO=none for a static connection type.


BOOTPROTO is set to "dhcp" for a automatic configuration of an IP address. If this is set to "none", then a static route is to be used. (Note the word "static" is no longer valid)

Type=Ethernet Specifies that a wired connection is to be used.

ONBOOT=yes Specifies that the interface should be started at system boot.

NAME=xxxxxxx Specifies the name of the interface. Specifies the first IP address to be assigned to the interface. Additional IP addresses can be added using IPADDR1, IPADDR2 .... Specifies a DNS server to use. Additional DNS servers are added by using DNS2 .....

HWADDR= These are generated automatically and will be different on your systems.

Configuring the hostname

Normally during installation one of the steps is to provide a unique hostname by which your system will be identified by on your network. This name can be changed by editing the following configuration file:


An alternative way to manage your hostname is to use the command: hostnamectl


Hostnamectl is a command that allows you to define/change the hostname on your systems. The "hostnamectl" tool has three different types of hostname options that can be set:

The high-level "pretty" hostname can include all kinds of special characters (e.g. "Tux's's Laptop"), the "static" hostname which is used to initialize the kernel hostname at boot (e.g. "rhel07a"), and the "transient" hostname which might be assigned temporarily due to network configuration and may revert back to a static hostname if network connectivity is lost and is only temporarily written to the kernel hostname.

Note that the pretty hostname has little restrictions on the characters used, while the static and transient hostnames are limited to the usually accepted characters of Internet domain names.

Example of hostnamectl command:

If you issue the hostnamectl command with no parameters or options, then information relating to your system will be displayed:

[root@rhel07a network-scripts]# hostnamectl
   Static hostname: rhel07a
         Icon name: computer
           Chassis: n/a
        Machine ID: 5904595331544c5fb48da4501a98ae7c
           Boot ID: aa8349956c294c1f92ff096454a0d62e
    Virtualization: oracle
  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-121.el7.x86_64
      Architecture: x86_64

Setting a Static Hostname

# hostnamectl --static set-hostname rhel07a

Setting the Pretty Hostname Name

# hostnamectl --pretty set-hostname "Land of Linux's RHEL 7 test server"

The pretty hostname details can be found in a file "/etc/machine-info"):

[root@rhel07a etc]# cat machine-info 
PRETTY_HOSTNAME="Land of Linux\'s RHEL 7 test server"

Setting the Transient Hostname Name

# hostnamectl --transient set-hostname myserver

Verify all hostname settings

Now if we issue the command "hostnamectl" with no parameters we can now see the defined areas:

[root@rhel07a network-scripts]# hostnamectl
   Static hostname: rhel07a
   Pretty hostname: Land of Linux's RHEL 7 test server
Transient hostname: myserver
         Icon name: computer
           Chassis: n/a
        Machine ID: 5904595331544c5fb48da4501a98ae7c
           Boot ID: aa8349956c294c1f92ff096454a0d62e
    Virtualization: oracle
  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-121.el7.x86_64
      Architecture: x86_64

Location of DNS settings and domain search order

During installation, you may have configured your network manually providing the name of a DNS server and the domain search order. Again, these entries can be modified. Additional DNS servers may be added easily. The configuration of these settings can be found in the following location:


By default most systems will use a DNS server to make a lookup, however, you can override this by modifying the "nsswitch.conf" file (see below).

DNS or Host file lookups - Name Service Switch configuration file "nsswitch.conf"

The above file can be found in the following location:


The Name Service Switch (NSS) configuration file "/etc/nsswitch.conf", is used by the GNU C Library to determine the sources from which to obtain name service information in a range of categories, and in what order.

Example taken from RHEL 7.0 server

# /etc/nsswitch.conf

passwd:     files sss
shadow:     files sss
group:      files sss

hosts:      files dns

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files sss

netgroup:   files sss

publickey:  nisplus

automount:  files
aliases:    files nisplus

The line that specifies the lookup order is as follows:

hosts:        files dns

This entry specifies that we will look in the host file first for an entry before trying a DNS server.

Hosts File - "/etc/hosts"

The "/etc/hosts" file is a simple text file that associates IP addresses with hostnames, one line per IP address. For each host a single line should be present with the following information:

IP_address canonical_hostname [aliases...]

Example:  myserver

Modifications to this file normally take effect immediately, except in cases where the file is cached by an application.

Adding a Persistent Static Route

There are several ways to add or remove static routing information. The traditional way was to use the "route" command which allowed a systems administrator to manipulate the routing table. When the "add" or "del" options are used, the route command would modify the routing table. If no options are passed to the route command, then the routing table is displayed:

[root@rhel07a etc]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         UG    1024   0        0 enp0s3   U     0      0        0 enp0s3

Note: The route command is now classed as obsolete and the "ip route" command should be used instead.

ip route command

The "ip route" command is used for routing table management and is a replacement for the obsolete "route" command. Static routes are for traffic that must not, or should not, go through the default gateway.

The "default gateway" is for any and all traffic which is not destined for the local network and for which no preferred route has been specified in the routing table.

Configuring Static Routes Using the Command Line

If static routes are required, they can be added to the routing table by means of the "ip route add" command and removed using the "ip route del" command. Commonly used options with the "ip route" command are as follows:

ip route [ add | del | change | append | replace ] destination-address

If you issue the "ip route" command without any options/parameters you will see output similar to the output below:

[root@rhel07a etc]# ip route
default via dev enp0s3  proto static  metric 1024 dev enp0s3  proto kernel  scope link  src 

Add a static route to a host address

To add a static route to a host address, issue the following command as root:

ip route add via [dev interface]

Where "" is the IP address of the host and "" is the next hop address and "interface" is the exit interface leading to the next hop. To add a static route to a network representing a range of IP addresses, issue the following command as root:

ip route add via [dev interface]

where "" is the IP address of the destination network and "/24" is the network prefix. The network prefix is the number of enabled bits in the subnet mask.

Static route configurations can be stored per interface in a file with a naming convention of "/etc/sysconfig/network-scripts/route-interface. An interface with the name of "eth0" would be stored in a file by the name of /etc/sysconfig/network-scripts/route-eth0.

There are two formats available to the "route-interface" file. One is to use the "ip arguments" and the other is to use "network/netmask" directives.

Configuring a Default Gateway

The default gateway is determined by the network scripts which parse the "/etc/sysconfig/network" file first and then any network interface "ifcfg" files for interfaces that are in a state of “up”. These ifcfg interface files are parsed in numerical ascending order. The last GATEWAY directive to be read is used to compose a default route in the routing table.

A default route can be specified by means of a GATEWAY directive and can be either set globally or in an interface specific configuration file.

A Global Default Gateway's configuration is stored in the file "/etc/sysconfig/network". This configuration file specifies gateway and host information for all network interfaces.

Configuring Static Routes in ifcfg interface files

Static routes that are set using the ip command from the command line are not persistent, they will be lost if the system is shutdown or restarted. To configure static routes that are persistent after a system restart, they must be placed in an interface configuration file in the "/etc/sysconfig/network-scripts/" directory.

The file name should be of the format "route-interface".

Static Routes Using the IP Command Arguments

Create an interface file with the following naming convention (the name eth0 is used in the example), for example "/etc/sysconfig/network-scripts/route-eth0", then define a route to a default gateway on the first line. This will only be needed if the gateway has not been set by DHCP and is not set globally in the "/etc/sysconfig/network" file:

default via dev interface

"" is the IP address of the default gateway. The "interface" is the interface that is connected to, or can reach, the default gateway. The "dev" option can be omitted, as it is optional. This interface configuration file setting takes precedence over a setting defined in the "/etc/sysconfig/network" file.

If a route to a remote network is required, a static route can be specified as follows: via [dev interface]

Each line is parsed as an individual route. is the network address and the prefix length of the remote or destination network (CIDR format). The address is the IP address leading to the remote network. It's preferably the next hop address, however, the address of the exit interface will work.

The “next hop” refers to the remote end of a link (gateway/router). The "dev" option can be used to specify the exit interface.

Network/Netmask Directives Format

The following format uses the "ADDRESS", "NETMASK" and "GATEWAY" fields. Each of these fields has a number appended to it indicating which route it is applicable to.




Where "" is the network address of the remote network or remote host to be reached.
"" is the netmask of the network address defined with "".
"" is the default gateway, or an IP address that can be used to reach the address ""

The following is an example of a route-interface layout using the network/netmask directives format. In this example several routes have been added.


Static routes must be numbered sequentially. For example, ADDRESS0, ADDRESS1, ADDRESS2, and so on.

Network Configuration Using "nmtui" - Network Manager Text User Interface

The NetworkManager text user interface tool (nmtui), provides a text interface to configure networking by controlling the NetworkManager. The tool should now be included by default with the NetworkManager, however, if it is missing, it can be easily installed with the following commands:

yum install NetworkManager-tui

You can easily identify if your interfaces are under the control of the NetworkManager by issuing the following command from a console or terminal:

Command Issued: nmcli dev status

[root@rhel07a ~]# nmcli dev status
enp0s3  ethernet  connected  enp0s3     
lo      loopback  unmanaged  --   

From the above output you can see that an interface by the name of "enp0s3" is under the control of the NetworkManager.

Starting nmtui

To start the NM Text User Interface issue the command nmtui as the root user. Although the command can be issued as a none root user, you will not be able to make any changes to your configuration.

NetworkManager nmtui

To navigate, use the arrow keys or press the Tab key to step forwards and Shift+Tab to step backwards through the presented options.
Press Enter to select an option. The Space Bar is used to toggle the status of a check box.

If you know the name of your connection interface, you can go straight to the appropriate screen:

Command Issued: nmtui edit connection-interface

# nmtui edit enp0s3

NetworkManager nmtui - edit connection

Any changes made to the interface "enp0s3" will be recorded in the interface file: /etc/sysconfig/network-scripts/ifcfg-enp0s3

Connection can also be activated by issuing the following nmtui command:

nmtui connect connection-interface

BY navigating through the various panels, you can configure your network settings easily. Static/DHCP settings, Routing and hostname information can be configured using this tool. The nmtui is the recommended way to configure your interfaces. The "nmtui" tool can be used in a graphical and none graphical environment.

Verify the Status of the NetworkManager

To verify the status of NetworkManager service you can issue the following "systemctl" command:

systemctl status NetworkManager.service

[root@rhel07a ~]# systemctl status NetworkManager.service
NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled)
   Active: active (running) since Fri 2014-10-03 20:01:32 BST; 43min ago
 Main PID: 797 (NetworkManager)
   CGroup: /system.slice/NetworkManager.service
           ├─ 797 /usr/sbin/NetworkManager --no-daemon
           └─1233 /sbin/dhclient -d -sf /usr/libexec/nm-dhcp-helper -pf /var/...

Oct 03 20:25:47 rhel07a dhclient[1233]: bound to -- renewal in ....
Oct 03 20:25:47 rhel07a NetworkManager[797]: bound to -- renewa....
Oct 03 20:25:47 rhel07a NetworkManager[797]:  (enp0s3): DHCPv4 state c...w
Oct 03 20:25:47 rhel07a NetworkManager[797]:    address
Oct 03 20:25:47 rhel07a NetworkManager[797]:    plen 24 (
Oct 03 20:25:47 rhel07a NetworkManager[797]:    gateway
Oct 03 20:25:47 rhel07a NetworkManager[797]:    server identifier 192....1
Oct 03 20:25:47 rhel07a NetworkManager[797]:    lease time 3600
Oct 03 20:25:47 rhel07a NetworkManager[797]:    nameserver ''
Oct 03 20:25:47 rhel07a NetworkManager[797]:    nameserver ''

From the above output you can see that the service is active.

Starting and Stopping Services and interfaces

Red Hat Enterprise Linux 7.0, CentOS 7.0, Oracle Linux 7.0 and Scientific Linux 7.0 all use systemd commands for manipulating services.

Below are some useful Networking related commands:

Display Current Network Status: systemctl status network.service

Restart Network Services: systemctl restart network.service

Stop Network Service: systemctl stop network.service

Start Network Service: systemctl start network.service

Stop an Interface: ifdown interface

Activate an interface: ifup interface

Miscellaneous Network Commands

Display Devices controlled by NetworkManager: nmcli dev status

NetworkManager Text User Interface (nmtui): nmtui

NetworkManager Text User Interface (nmtui): nmtui edit interface

Display Interface Connections: ip link

Display Interface Statistics: ip -s link

Display Assigned IP Address: ip address show

Display Routing Table: ip route show

Manage Routing table: ip route { add | del | change | append | replace } ROUTE

Display Routing Table: netstat -nr

Display Routing Table (obsolete): route

Display and Configure interfaces (obsolete): ifconfig

Display Hostname Information: hostnamectl

Set Hostname - Static: hostnamectl --static set-hostname rhel07a

Set Hostname - Pretty: hostnamectl --pretty set-hostname "Land of Linux's RHEL 7 test server"

Set Hostname - Transient: hostnamectl --transient set-hostname myserver

Documentation - Red Hat

A comprehensive Networking Guide in "pdf" format is freely available from Red Hat. To download, Click the link below:

Download RHEL 7.0 Networking Administration Guide