Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


RHCSA - Manage Basic Networking: Configure IPv4 & IPv6 Addresses

IPv4 and IPv6 Addresses

IPv4 (Internet Protocol version 4) and IPv6 (Internet Protocol version 6) are addressing schemes used to uniquely identify devices on a network. They serve as numerical labels assigned to devices like computers, smartphones, servers, and other networked devices.

  • IPv4 Addresses: These are 32-bit addresses, typically written in dotted-decimal notation (e.g., 192.168.1.1). The rapid growth of the internet and the increasing number of connected devices led to the depletion of available IPv4 addresses, prompting the need for a new addressing scheme.

  • IPv6 Addresses: IPv6 uses a 128-bit address format, expressed in hexadecimal notation with colons separating each group (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334). IPv6 provides a significantly larger address space, allowing for more devices to be connected directly to the internet.

CIDR vs. Classical Notation

CIDR (Classless Inter-Domain Routing) notation and classical notation are ways of representing IP address ranges:

  • CIDR Notation: This is a more flexible and efficient way of representing IP addresses and address ranges. It includes the base IP address followed by a slash ("/") and a number representing the number of bits that are used for the network portion of the address (e.g., 192.168.1.0/24). CIDR notation allows for variable subnetting and more efficient use of IP address space.

  • Classical Notation: Also known as subnet masks, it represents the division of an IP address into a network portion and a host portion. It is expressed as four numbers separated by dots, each representing 8 bits (e.g., 192.168.1.1/255.255.255.0). This notation was used in the older classful network addressing scheme.

Network Classes

Network classes refer to the division of IPv4 address space into address spaces, with the main classes being A, B & C and are based on the initial bits of the IP address. However, the classful network addressing scheme is mostly obsolete due to the adoption of CIDR. The classes were used to determine the default subnet mask and address range:

  • Class A:

    Class A Network: 10.0.0.0/8

    IP Address Range: 10.0.0.0 to 10.255.255.255

    Class A networks are designed for large organizations and have a very large number of host addresses available.

  • Class B:

    Class B Network: 172.16.0.0/12

    IP Address Range: 172.16.0.0 to 172.31.255.255

    Class B networks are suitable for medium-sized organizations and offer a moderate number of host addresses.

  • Class C:

    Class C Network: 192.168.0.0/16

    IP Address Range: 192.168.0.0 to 192.168.255.255

    Class C networks are used for small networks and provide a limited number of host addresses.

Broadcast Address:

A broadcast address is a special address used to send a message to all devices within a specific network segment or subnet. In IPv4, the broadcast address is typically the highest address within the subnet, with all host bits set to 1 (e.g., 192.168.1.255 in a /24 subnet). In IPv6, broadcast is generally replaced by multicast addressing, which allows messages to be sent to specific groups of devices rather than all devices on a network.

Validating IP Configuration

The ip command enables administrators to validate IP configuration by providing detailed information about network interfaces, routing tables, and addresses. By using various subcommands and options, such as ip addr show to display interface addresses, ip route show to show routing information, and ip link show to list network interfaces, the ip command allows users to quickly verify and troubleshoot IP settings.

Display the current IP address configuration:

To display the current IPv4 & IPv6 addresses and subnet masks, along with MAC addresses assigned to network interfaces, you can use the ip address show command:

The ip command sub commands can be shortened as long as the command would still be unique if written in full. For example, as there is no other sub command starting with a, you can actually run ip a instead of ip address show.

ip address show

The output of the command will look similar to the below, with your loopback interface and any of your network interfaces also. My interface is enp0s3 and its state is UP. The IPv4 address is 192.168.0.219 and is on a /24 network with a broadcast address of 192.168.0.255. The MAC address is 09:00:44:25:16:95 and the IPv6 address is fe80::a00:26ff:fe27:4598 on a /64 network.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 09:00:44:25:16:95 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.219/24 brd 192.168.0.255 scope global dynamic noprefixroute enp0s3
       valid_lft 86335sec preferred_lft 86335sec
    inet6 fe80::a00:26ff:fe27:4598/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Configure IPv4 & IPv6 Addresses

Only attempt these exercises via console access and not SSH as a wrong configuration could could you to lose access. Never change network settings on a production system unless a configuration change has been tested thoroughly on a dev/test environment.

Networking is managed by the NetworkManager service and provides tools for managing connections, for example, the NetworkManager Text User Interface (nmtui) and the NetworkManager Command Line Interface (nmcli).

The network configuration scripts that NetworkManager reads from and writes to are found in directory /etc/NetworkManager/system-connections. The configuration is written in INI file format and is named <network-interface>.nmconnection.

In older versions of Red Hat, the network configuration files used to exist in directory /etc/sysconfig/network-scripts with the name of ifcfg-<network-interface>.

The exercises in this lesson use IPv4, however you can get IPv6 example by running man nmcli-examples.

Review network interface configuration file:

To display the contents of the configuration file for the network device, run the following, replacing enp0s3 with your returned device:

sudo cat /etc/NetworkManager/system-connections/enp0s3.nmconnection

The contents will look similar to:

[connection]
id=enp0s3
uuid=29c942f7-9ff2-3e56-99b8-2edd84c50ada
type=ethernet
autoconnect-priority=-999
interface-name=enp0s3
timestamp=1687415236

[ethernet]

[ipv4]
method=auto

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

nmcli

The NetworkManager Command Line Interface can be used to show and configure connections, with the following exercises getting you working with the nmcli command.

In the exercises make sure to swap out my example IP addresses and device names with valid replacements for your network and system.

Display connection information:

nmcli con show

The output will look similar to the following, which in my case shows the device as enp0s3:

NAME    UUID                                  TYPE      DEVICE 
enp0s3  29c942f7-9ff2-3e56-99b8-2edd84c50ada  ethernet  enp0s3 
lo      ab92dd8f-1ac8-4956-987f-8b7d71fd2c9f  loopback  lo

When specifying a device to the command you get presented with all the configuration for that connection:

nmcli con show enps03

Example output (many lines removed for readability):

connection.id:                          enp0s3
connection.uuid:                        29c942f7-9ff2-3e56-99b8-2edd84c50ada
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s3
connection.autoconnect:                 yes
...
ipv4.method:                            auto
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.routes:                            --
...
ipv6.method:                            auto
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       --
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
...
GENERAL.NAME:                           enp0s3
GENERAL.UUID:                           29c942f7-9ff2-3e56-99b8-2edd84c50ada
GENERAL.DEVICES:                        enp0s3
GENERAL.IP-IFACE:                       enp0s3
...
IP4.ADDRESS[1]:                         192.168.0.219/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt = 100
IP4.DNS[1]:                             194.168.4.100
IP4.DNS[2]:                             194.168.8.100
...
IP6.ADDRESS[1]:                         fe80::a00:26ff:fe27:4598/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 1024

Add a connection to a device:

Add a static connection to an existing interface (enps03 in my case).

sudo nmcli con add con-name cli type ethernet ipv4.method manual ip4 192.168.0.220/24 gw4 192.168.0.1 ifname enp0s3

The command is broken down as follows:

  • con add: Add a connection
  • con-name cli: With a connection name of cli
  • type ethernet: Of type ethernet
  • ipv4.method manual: With a static configuration
  • ip4 192.168.0.220/24: That has an ip4 address and subnet mask of 192.168.0.220/24
  • gw4 192.168.0.1: With the gateway set to 192.168.0.1
  • ifname enp0s3: For the enp0s3 interface

And if the command is successful would receive output similar to:

Connection 'cli' (3faab58a-3c21-4b83-a031-704642743f2b) successfully added.

Check network connections again to see the cli connection is now present:

nmcli con show

The output shows the cli connection is not active. You added a new connection to an existing device and only one connection can be active at a time:

NAME    UUID                                  TYPE      DEVICE 
enp0s3  29c942f7-9ff2-3e56-99b8-2edd84c50ada  ethernet  enp0s3 
lo      ab92dd8f-1ac8-4956-987f-8b7d71fd2c9f  loopback  lo
cli     3faab58a-3c21-4b83-a031-704642743f2b  ethernet  --

To activate the cli connection run:

sudo nmcli con up cli

Confirm the connection is now active by running the nmcli con show command again.

nmcli con show

As there can only be one connection active per device, by specifying the cli connection to be brought up, the existing connection enp0s3 has to go down.

One connection active per device does not mean only one IP address can be active at a time per device. A connection can have multiple addresses assigned and we have this scenario in the next exercise.

NAME    UUID                                  TYPE      DEVICE 
cli     3faab58a-3c21-4b83-a031-704642743f2b  ethernet  enp0s3 
lo      cff5534d-2c82-49ac-8dd1-9e027bec160d  loopback  lo     
enp0s3  29c942f7-9ff2-3e56-99b8-2edd84c50ada  ethernet  --

Modify an existing connection:

Add an additional IPv4 address to the cli connection:

sudo nmcli con mod cli +ipv4.addresses 192.168.0.221/24"

The command is broken down as follows:

  • con mod: Modify a connection
  • cli: For connection name of cli
  • +ipv4.addresses 192.168.0.221/24: Adding an additional IP address (+)

To activate the updated cli connection, run:

sudo nmcli con up cli

Running the ip a command shows 2 IP addresses assigned to the enp0s3 device:

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:26:46:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.220/24 brd 192.168.0.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet 192.168.0.221/24 brd 192.168.0.255 scope global secondary noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::3d88:2ef8:c797:bb59/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

nmtui

The NetworkManager Text User Interface can be used to show and configure connections, with the following exercises getting you working with the nmtui command.

In the exercises make sure to swap out my example IP addresses and device names with valid replacements for your network and system.

Create a new connection:

Launch the NetworkManager Text User Interface:

sudo nmtui

Highlight Edit Connection and press Enter:

edit-connection

Highlight <Add> and press Enter

add

Highlight Ethernet, Tab across to <Create> then press Enter:

create

Give it a profile name of tui and type the name of your device(enp0s3 in my case). Then Tab to <OK> and press Enter:

profile

Press Enter on <Back>:

back

Highlight Activate a connection, then Tab to <OK> and press Enter:

activate

You will see an asterisk * against the current active connection.

Highlight the tui entry, Tab across to <Activate> and press Enter:

activate-02

The asterisk * has now changed to the tui connection.

Select <Back> and press Enter:

activate-03

Highlight Quit, Tab to <OK> and press Enter to quit out of the nmtui tool:

quit

Lesson Tidy Up

If you performed both exercises you will have 2 additional connections to what you started with, and the tui connection will be active. To revert back to the state before the lesson started, follow the below exercise:

Remove exercise connections:

Activate the original connection:

sudo nmcli con up enp0s3

Delete the tui connection:

sudo nmcli con del tui

Delete the cli connection:

sudo nmcli con del cli

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.