Bookmark this page

Chapter 11.  Manage Networking

Abstract

Goal

Configure network interfaces and settings on Red Hat Enterprise Linux servers.

Objectives
  • Describe fundamental concepts of network addressing and routing for a server.

  • Test and inspect the current network configuration with command-line utilities.

  • Manage network settings and devices with the nmcli command.

  • Modify network configuration by editing configuration files.

  • Configure a server's static hostname and its name resolution and test the results.

Sections
  • Describe Networking Concepts (and Quiz)

  • Validate Network Configuration (and Guided Exercise)

  • Configure Networking from the Command Line (and Guided Exercise)

  • Edit Network Configuration Files (and Guided Exercise)

  • Configure Hostnames and Name Resolution (and Guided Exercise)

Lab
  • Manage Networking

Describe Networking Concepts

Objectives

  • Describe fundamental concepts of network addressing and routing for a server.

TCP/IP Network Model

The TCP/IP network model is a four-layered set of communication protocols that describes how data communications are packetized, addressed, transmitted, routed, and received between computers over a network.

The protocol is specified by RFC 1122, Requirements for Internet Hosts - Communication Layers.

Following are the four layers of the TCP/IP network model:

  • Application

    Each application has specifications for communication so that clients and servers can communicate across platforms. Common protocols include SSH, HTTPS (secure web), FTP (file sharing), and SMTP (electronic mail delivery).

  • Transport

    TCP and UDP are transport protocols. TCP is a reliable connection-oriented communication, whereas UDP is a connectionless datagram protocol. Application protocols can use either TCP or UDP ports. A list of well-known and registered ports is in the /etc/services file.

    When a packet is sent on the network, the combination of the service port and IP address forms a socket. Each packet has a source socket and a destination socket. This information can be used when monitoring and filtering network traffic.

  • Internet

    The internet layer, or network layer, carries data from the source host to the destination host. The IPv4 and IPv6 protocols are internet layer protocols. Each host has an IP address and a prefix to determine network addresses. Routers are used to connect networks.

  • Link

    The link layer, or media access layer, provides the connection to physical media. The most common types of networks are wired Ethernet (802.3) and wireless Wi-Fi (802.11). Each physical device has a Media Access Control (MAC) address, which is also known as a hardware address, to identify the destination of packets on the local network segment.

Figure 11.1: Comparison of the TCP/IP and OSI network models

Describe Network Interface Names

Each network port on a system has a name, which you use to configure and identify it.

Earlier versions of Red Hat Enterprise Linux used names such as eth0, eth1, and eth2 for each network interface. The eth0 interface name was the first network port that the operating system detected; eth1 was the second interface, and so on. However, as devices were added and removed, the mechanism that detected and named devices could change which interface was assigned to which name. Furthermore, the PCIe standard does not guarantee the order in which PCIe devices are detected on boot, which could change device naming unexpectedly due to variations during device or system startup.

In Red Hat Enterprise Linux 7 and later, the default naming system generates names that are consistent across reboots. Instead of being based on the detection order, the assignment of network interface names is based on information from the firmware, the PCI bus topology, and the type of network device. Without consistent device naming, the Linux kernel assigns names to network interfaces used in earlier versions of Red Hat Enterprise Linux by combining a fixed prefix and an index.

Network interface names start with the type of interface:

  • Ethernet interfaces begin with en

  • WLAN interfaces begin with wl

  • WWAN interfaces begin with ww

The rest of the interface name after the type is based on information from the server's firmware, or is determined by the location of the device in the PCI topology.

  • oN indicates an on-board device with unique index N from the server's firmware. The eno1 name is on-board Ethernet device 1.

  • sN indicates a device in PCI hotplug slot N. For example, ens3 is an Ethernet card in PCI hotplug slot 3.

  • pMsN indicates a PCI device on bus M in slot N. A wlp4s0 interface is a WLAN card on PCI bus 4 in slot 0. If the card is a multi-function device (such as an Ethernet card with multiple ports, or a device with both Ethernet and another function), then you might see fN in the device name. An enp0s1f0 interface is function 0 of the Ethernet card on bus 0 in slot 1. A second card interface would be named enp0s1f1, which is function 1 of that same device.

Persistent naming means that when the name is set for a network interface on the system, the name of the interface does not change, even if you add or remove hardware. A behavior of persistent naming is that a system with a single interface generates a device name by using a hardware information scheme, and is not expected to use the eth0 kernel naming scheme.

IPv4 Networks

Although IPv4 remains the most common addressing scheme in enterprise networks today, IPv6 has surpassed IPv4 usage in cellular networks. You need a basic understanding of IPv4 networking to manage networking on your servers.

IPv4 Addresses

An IPv4 address is a 32-bit number, which is expressed as four 8-bit octets in a decimal format that ranges in value from 0 to 255, separated by single dots. The address is divided into two parts: the network prefix and the host number. The network prefix identifies a unique physical or virtual subnet. The host number identifies a specific host on the subnet. All hosts on the same subnet have the same network prefix and can talk to each other directly without a router. A network gateway connects different networks, and a network router commonly operates as the gateway for a subnet.

Note

A subnet is a segment of a larger network, and the use of the term depends on the context. An IP network is partitioned into multiple, smaller network segments. Typically, segment refers to the physical or virtual link layer, whereas subnet refers to the logical, network-layer addressing for the corresponding segment.

Additionally, subnetting an assigned large network address subdivides it into multiple, smaller network segments. This IPv4 section introduces network addresses that are implemented as single subnets. The upcoming IPv6 section includes another context, where large networks are subnetted into multiple subnets.

In the original IPv4 specification, the allowed network prefixes were one of three fixed sizes for unicast packets that have a single source and destination. The network prefix might be 8 bits (class A), 16 bits (class B), or 24 bits (class C). Today, the number of bits in the network prefix is variable, which means that the prefix can be any number in the supported range, and this later specification is called Classless Inter-Domain Routing (CIDR). Although fixed-address classes are no longer in use, many network professionals still refer to networks with 8-bit, 16-bit, or 24-bit network prefixes by using the original class A, B, or C designation.

A network mask (netmask) is a binary mask whose length indicates how many bits belong to the network prefix that identifies the subnet. Because an IPv4 address is always 32 bits long, a subnet with a longer network mask has fewer available bits to identify hosts, which means fewer possible hosts. A subnet with a shorter network mask has more available bits to identify hosts, which means more possible hosts and a larger subnet.

Network masks are expressed in one of two forms, which are both used routinely. The first form, which is known as CIDR notation, appends a forward slash (/) and an integer up to 32 that indicates the number of bits in the binary mask. The second notation displays the number of bits in the binary mask as four 8-bit octets in decimal format.

IPv4 Subnets and Netmasks

The number of available host addresses in a subnet depends on the network prefix size. For example, a network prefix of /24 leaves 8 bits, or 255 possible host addresses in the subnet. A network prefix of /16 leaves 16 bits, or 65536 possible host addresses in the subnet.

  • The network address for a subnet is the lowest possible address on a subnet, where the host number is all binary zeros.

  • The broadcast address for a subnet is the highest possible address on a subnet, where the host number is all binary ones, and is a special address for broadcasting packets to all subnet hosts.

  • The gateway address for a subnet can be any unique host number in the subnet, but is commonly set to the first available host number, which is a binary number of all zeroes except for a '1' in the last bit. This gateway numbering convention is not mandatory, and subnets that do not need external communication do not set a network gateway.

The following figures illustrate the use of an IP address and a netmask to calculate the network prefix and the host number for a subnet. Perform a binary AND calculation where each bit in the IP address and netmask is binary, and compare each bit to its corresponding bit in the IP address and netmask through the prefix length. In an AND calculation, both bits must be a '1' for the result to be a '1', and all other combinations result in '0'. Perform a binary OR calculation on the remaining bits in the host number, where either bit can be a '1' for the result to be a '1'. In a binary OR calculation, only two '0' bits result in a '0'.

Figure 11.2: IPv4 netmask calculation for a small network
Figure 11.3: IPv4 netmask calculation for a larger network

Example Network Calculations

In the following example, identify the netmask first, and then perform the binary calculations. A netmask of /24 means that the leading 24 bits of the address define the network address (192.168.1.0). In this scenario, 8 bits, or 254 addresses, are available for host addressing.

Table 11.1. IPv4 address of 192.168.1.107/24

Network prefix/24 or 255.255.255.0 11111111.11111111.11111111.00000000
Host address192.168.1.107 11000000.10101000.00000001.01101011
Network address192.168.1.0 11000000.10101000.00000001.00000000
Address range for hosts on subnet192.168.1.1 - 192.168.1.254 11000000.10101000.00000001.00000001 to 11000000.10101000.00000001.11111110
Broadcast address192.168.1.255 11000000.10101000.00000001.11111111

In the following example, a /19 netmask is a valid network prefix that uses only a partial octet. Variable length netmasks allow subnets with a different quantity of hosts than the full-octet netmasks. The remaining 13 bits, or 8190 addresses, are available for host addressing.

Table 11.2. IPv4 address of 172.16.181.23/19

Network prefix/19 or 255.255.224.0 11111111.11111111.11100000.00000000
Host address172.16.181.23 10101100.00010000.10110101.00010111
Network address172.16.160.0 10101100.00010000.10100000.00000000
Address range for hosts on subnet172.16.160.1 - 172.16.191.254 10101100.00010000.10100000.00000001 to 10101100.00010000.10111111.11111110
Broadcast address172.16.191.255 10101100.00010000.10111111.11111111

In the following example, the /8 indicates a large network. Only the first octet is used for the network prefix (10.0.0.0). The remaining 24 bits, or 16,777,214 addresses, are available for host addressing. The 10.255.255.255 broadcast address is the last address of the network.

Table 11.3. IPv4 address of 10.1.1.18/8

Network prefix/8 or 255.0.0.0 11111111.00000000.00000000.00000000
Host address10.1.1.18 00001010.00000001.00000001.00010010
Network address10.0.0.0 00001010.00000000.00000000.00000000
Address range for hosts on subnet10.0.0.1 - 10.255.255.254 00001010.00000000.00000000.00000001 to 00001010.11111111.11111111.11111110
Broadcast address10.255.255.255 00001010.11111111.11111111.11111111

IPv4 Routes

Network packets move from host to host on a subnet and through routers from network to network. Each host has a routing table, which determines which network interface is correct for sending packets to particular networks. A routing table entry lists the destination network, which network interface to use, and the IP address of the router to forward the packet to the final destination. The routing table entry that matches the network prefix of the destination address is used to route the packet. If multiple entries are valid for the destination address, then the entry with the longer prefix is used.

If the destination network does not match a more specific entry, then the packet is routed by using the 0.0.0.0/0 default entry. This default route points to the gateway router on a local subnet that the host can reach.

When a router receives packets that are not addressed to itself, the router forwards the traffic based on its own routing table. Forwarding might send the packet directly to the destination host if this router is on the destination's subnet, or might forward the packet again to another router network. Packet forwarding on routers continues until the packet reaches the requested destination network and host.

Figure 11.4: Example network topology

Table 11.4. Example routing table for the hostb machine

DestinationInterfaceRouter (if needed)
192.168.5.0/24 enp0s1f0  
192.168.6.0/24 enp0s2f0  
172.17.0.0/16 enp0s1f0 192.168.5.1
0.0.0.0/0 (default) enp0s1f0 192.168.5.1

Consider the preceding network diagram and network routing table.

  • Network traffic from the hostb machine to any host in the 192.168.6.0/24 network is transmitted directly via the enp0s2f0 interface.

    • This traffic is because the hostb machine has an interface attached to that network, and is the closest match to the route entry.

  • Network traffic from the hostb machine to a host with the 172.17.50.120 IP address uses the enp0s1f0 interface, because the traffic matches the third entry in the routing table.

    • The hostb machine does not have an interface that is directly attached to this network, so this traffic is sent to the next hop router with the address of 192.168.5.1, which is reachable via the enp0s1f0 interface. The traffic is then forwarded to its destination.

    • Because the hostb machine does not have an interface that is directly connected to the 172.17.0.0/16 network, someone with knowledge of the network topology must add this route entry to the routing table.

  • Network traffic with a destination that does not match any entry in the routing table is sent to the default route. The default route, which is designated with 0.0.0.0/0, is shown in the fourth entry.

    • For example, all traffic from the hostb machine to the internet is forwarded to the next hop router with the address of 192.168.5.1, which is reachable via the enp0s1f0 interface. The traffic is then forwarded to its destination.

IPv4 Address and Route Configuration

A server can automatically configure its IPv4 network settings by communicating with a DHCP server. A local DHCP client queries the subnet by using a link layer protocol to locate a DHCP server or proxy, and negotiates to use a unique address and other settings for a specific lease period. The client must periodically request lease renewal to maintain use of the assigned network configuration.

As an alternative, you can configure a server to use a static network configuration. Static network settings are read from local configuration files. The settings that you use must be appropriate for your subnet. Coordinate with your network administrator to avoid conflicts with other servers in the same subnets.

IPv6 Networks

IPv6 is designed to greatly expand the number of total available device addresses. IPv6 is used in both enterprise networks and for mobile communications. Most if not all Internet Service Providers (ISPs) use IPv6 extensively for assigning to internal equipment and for dynamic assignment for customer devices.

IPv6 can also be used in parallel with IPv4 in a dual-stack mode. A network interface can have both IPv6 and IPv4 addresses. Red Hat Enterprise Linux operates in a dual-stack mode by default.

IPv6 Addresses

An IPv6 address is a 128-bit number, which is normally expressed as eight colon-separated groups of four hexadecimal nibbles (half-bytes). Each nibble represents four bits of the IPv6 address, so each group represents 16 bits of the IPv6 address.

2001:0db8:0000:0010:0000:0000:0000:0001

To simplify writing IPv6 addresses, leading zeros in a colon-separated group are not needed. However, at least one hexadecimal digit must be written in each colon-separated group.

2001:db8:0:10:0:0:0:1

Because addresses with long strings of zeros are common, one or more consecutive groups of zeros only can be combined with exactly one block of two colon :: characters.

2001:db8:0:10::1

The 2001:db8::0010:0:0:0:1 IPv6 address, though a valid representation, is a less convenient way to write the example address. This different representation can confuse administrators who are new to IPv6. The following list shows tips for writing consistently readable addresses:

  • Suppress leading zeros in a group.

  • Use a two-colon :: block to shorten the address as much as possible.

  • If an address contains two consecutive groups of zeros, which are equal in length, then shorten the leftmost groups of zeros to :: and the rightmost groups to :0: for each group.

  • Although it is allowed, do not use :: to shorten a single group of zeros. Use :0: instead, and save :: for consecutive groups of zeros.

  • Always use lowercase letters for a through f hexadecimal characters.

Important

When including a TCP or UDP network port after an IPv6 address, always enclose the IPv6 address in square brackets so that the port does not appear to be part of the address.

[2001:db8:0:10::1]:80

IPv6 Subnets

A normal IPv6 unicast address is divided into two parts: the network prefix and interface ID. The network prefix identifies the subnet. Two network interfaces on the same subnet cannot have the same interface ID; the interface ID identifies a particular interface on the subnet.

Unlike IPv4, IPv6 has a standard subnet mask, /64, which is used for almost all normal addresses. In this case, half of the 128 bit address is the network prefix and the other half is the interface ID. With 64 bits for host addresses, a single subnet could theoretically contain 2^64 hosts.

Typically, the network provider allocates a shorter prefix to an organization, such as a /48. This prefix leaves the rest of the network part for assigning subnets (up to the maximum /64 length) from that allocated prefix. For example, when a /48 allocation prefix is assigned, 16 bits are available for up to 65536 subnets.

Figure 11.5: IPv6 address parts and subnetting

Table 11.5. Common IPv6 Addresses and Networks

IPv6 address or networkPurposeDescription
::1/128 localhostThe IPv6 equivalent to the 127.0.0.1/8 address, which is set on the loopback interface.
:: The unspecified addressThe IPv6 equivalent to 0.0.0.0. For a network service, it might indicate that it is listening on all configured IP addresses.
::/0 The default route (the IPv6 internet)The IPv6 equivalent to the 0.0.0.0/0 address. The default route in the routing table matches this network; the router for this network is where all traffic is sent in the absence of a better route.
2000::/3 Global unicast addressesThe Internet Assigned Numbers Authority (IANA) currently allocates "normal" IPv6 addresses from this space. The addresses include all the networks that range from 2000::/16 through 3fff::/16.
fd00::/8 Unique local addresses (RFC 4193)IPv6 has no direct equivalent of the RFC 1918 private address space, although this network range is close. A site can use these networks to self-allocate a private routable IP address space inside the organization. However, these networks cannot be used on the global internet. The site must randomly select a /48 from this space, but it can subnet the allocation into /64 networks normally.
fe80::/10 Link-local addressesEvery IPv6 interface automatically configures a link-local unicast address that works only on the local link on the fe80::/64 network. However, the entire fe80::/10 range is reserved for future use by the local link. This topic is discussed in more detail later.
ff00::/8 MulticastThe IPv6 equivalent to the 224.0.0.0/4 address. Multicast is used to transmit to multiple hosts at the same time, and is particularly important in IPv6 because it has no broadcast addresses.

Important

The previous table lists network address allocations that are reserved for specific purposes. These allocations might consist of many networks. IPv6 networks are allocated from the global unicast and link-local unicast address spaces that have a standard /64 network mask.

A link-local address in IPv6 is an unroutable address that the system uses only to talk to other systems on the same network link. To ensure that the IP address is unique, the system uses a specific method to compute the interface ID of the link-local address.

Note

Originally, the interface ID for the IPv6 link-local address was constructed from the MAC address of the network device. Exposing the MAC address as part of the IPv6 address might cause some security and privacy issues, because it becomes possible to identify and follow a computer on the network.

By default in Red Hat Enterprise Linux 9, NetworkManager generates a random but stable interface ID for the interface, according to the algorithm in RFC 7217. This algorithm is controlled by the ipv6.addr-gen-mode connection setting, which defaults to stable-privacy.

IPv6 Privacy Extensions (RFC 4941) are a different solution to the same concern and are controlled by different settings, which are disabled by default.

Use the ip addr show command to retrieve the link-local IPv6 address, as in the following example. Add the -br option for a brief listing of addresses only.

[user@host ~]$ ip addr show dev eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:01:fa:0a brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.1/16 brd 10.42.255.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::7418:cf98:c742:3681/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Add the -br option for a brief listing of IPv4 and IPv6 addresses only.

[user@host ~]$ ip -br addr show dev eth0
eth0          UP          10.42.0.1/16 fe80::7418:cf98:c742:3681/64

To operate correctly, IPv6 relies on the link-local address. The interface always keeps that address, even when you assign a routable IPv6 address manually or with an automated method.

With multicast, one system can send traffic to a special IP address that multiple systems receive. Multicast differs from broadcast, because broadcast packets are not routable and reach only local subnet hosts. Conversely, multicast packets are routed to specific hosts that announced a request for the uniquely addressed multicast packets. Multicast packets can be routed to other subnets, if all intermediary routers support forwarding multicast requests and routing.

Multicast plays a larger role in IPv6 than in IPv4, because IPv6 has no broadcast address. The ff02::1 IPv6 address is a key multicast address that is used as the all-nodes link-local address, and behaves like a broadcast address. You can ping this address to send traffic to all nodes on the link. Link-scope multicast addresses (which start with ff02::/8) must be specified with a scope identifier, as for a link-local address.

[user@host ~]$ ping6 ff02::1%ens3
PING ff02::1%ens3(ff02::1) 56 data bytes
64 bytes from fe80::211:22ff:feaa:bbcc: icmp_seq=1 ttl=64 time=0.072 ms
64 bytes from fe80::200:aaff:fe33:2211: icmp_seq=1 ttl=64 time=102 ms (DUP!)
64 bytes from fe80::bcd:efff:fea1:b2c3: icmp_seq=1 ttl=64 time=103 ms (DUP!)
64 bytes from fe80::211:22ff:feaa:bbcc: icmp_seq=2 ttl=64 time=0.079 ms
...output omitted...

IPv6 Address Configuration

IPv4 has two ways to configure addresses on network interfaces. The administrator can manually configure network addresses on interfaces, or addresses can be configured dynamically with DHCP. IPv6 supports manual configuration, and two methods of dynamic configuration, one of which is DHCPv6.

You can select interface IDs for static IPv6 addresses, similar to IPv4. In IPv4, two addresses on a network cannot be used: the lowest address, which is the network address; and the highest address, which is the broadcast address. In IPv6, two interface IDs are reserved, and cannot be used as normal host interface addresses:

  • The all-zeros identifier 0000:0000:0000:0000 ("subnet router anycast") that all routers on the link use. For example, on the 2001:db8::/64 network, the anycast address is 2001:db8::.

  • The identifiers fdff:ffff:ffff:ff80 through fdff:ffff:ffff:ffff.

DHCPv6 lease negotiations work differently from IPv4 DHCP, because DHCPv6 has no broadcast address. A host sends a DHCPv6 request from a link-local address to port 547/UDP on the dedicated ff02::1:2 all-dhcp-servers link-local multicast group. A listening DHCPv6 server can choose to reply with appropriate information to port 546/UDP on the client's provided link-local address.

The dhcp package in Red Hat Enterprise Linux 9 provides support for a DHCPv6 server.

In addition to DHCPv6, IPv6 also supports another dynamic configuration method, which is called Stateless Address Autoconfiguration (SLAAC). To use SLAAC, a host configures its interface with a link-local fe80::/64 address, and sends a "router solicitation" to the ff02::2 all-routers link-local multicast group. An IPv6 router on the local link responds to the host's link-local address with the subnet's previously configured network prefix and other relevant information. The host uses the provided network prefix with an interface ID that is constructed the same as for link-local addresses. The router periodically sends multicast updates (router advertisements) to confirm or to update the provided network information.

With the radvd package in Red Hat Enterprise Linux 9, a Red Hat Enterprise Linux based IPv6 router can provide SLAAC through router advertisements.

Important

A typical Red Hat Enterprise Linux 9 system that is configured for dynamic IPv4 addresses with DHCP is typically configured for dynamic IPv6 by using SLAAC. Hosts with a dynamic IPv6 configuration might unexpectedly obtain additional IPv6 addresses when a new IPv6 router is added to the network.

Some IPv6 deployments combine SLAAC and DHCPv6, and use SLAAC to provide the network address information, where DHCPv6 provides more network options, such as DNS servers and search domains.

Hostnames and IP Addresses

IP addresses are not human-friendly in daily use. Users generally prefer to work with hostnames rather than with number strings. Linux has name resolution mechanisms to map a hostname to an IP address.

One method is to create static entries for each hostname in each system's /etc/hosts file. With this method, you must manually update each server's copy of the hosts file.

When configured, you can look up the address for a hostname (or a hostname from an address) by using the Domain Name System (DNS) network service. DNS is a distributed network of servers that provides name resolution mappings. For name resolution to work, a host must be configured to know where to contact a nameserver. The nameserver does not need to be on the same subnet, but the host must be able to reach it. A nameserver configuration is typically obtained through DHCP or by creating static address settings in the /etc/resolv.conf file. Later sections of this chapter discuss how to configure name resolution.

Revision: rh124-9.3-770cc61