> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Working with nmcli

> Hands-on demo of using nmcli to create, modify, activate, verify, and delete NetworkManager Ethernet connections

In this lesson you'll learn how to manage network connectivity using nmcli, the command-line tool for NetworkManager. This demo walks through inspecting device status, creating a new Ethernet connection, verifying IP/routing/DNS, modifying addresses, and deleting the connection.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Managing-Network-Configuration-and-Security/Demo-Working-with-nmcli/demo-working-with-nmcli-slide.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=aac58f137a878a499b3765946f0b8d21" alt="A dark-themed presentation slide with the title &#x22;Demo&#x22; and the subtitle &#x22;Working with nmcli&#x22; on the left. A large empty dark rectangle occupies the right side of the slide." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Managing-Network-Configuration-and-Security/Demo-Working-with-nmcli/demo-working-with-nmcli-slide.jpg" />
</Frame>

Callouts

<Callout icon="lightbulb" color="#1CB2FE">
  Run `nmcli` commands as root (or with `sudo`) because most connection operations require privileges. You can inspect system-managed connection files under `/etc/NetworkManager/system-connections/`.
</Callout>

## 1. Check current devices and connections

Start by listing device status to discover available interfaces:

```bash theme={null}
root@control:~# nmcli device status
DEVICE  TYPE      STATE      CONNECTION
enp0s3  ethernet  connected  enp0s3
lo      loopback  unmanaged  lo
```

Then list configured connections and the devices they are bound to:

```bash theme={null}
root@control:~# nmcli connection show
NAME    UUID                                  TYPE      DEVICE
enp0s3  6f9c3bb8-fb17-38d3-93c0-e6cfa258782e  ethernet  enp0s3
lo      a8886d34-a666-4301-9bae-e6d2e7b4eda2  loopback  lo
```

## 2. Create a new Ethernet connection

In this example we'll create a static IPv4 Ethernet connection with these parameters:

* `type`: `ethernet`
* `ifname`: `enp0s3` (interface name)
* `con-name`: `custom-connection` (human-friendly connection name)
* `ipv4.addresses`: `10.0.2.18/24`
* `ipv4.gateway`: `10.0.2.1`
* `ipv4.dns`: `8.8.8.8`
* `ipv4.method`: `manual`

Run the add command:

```bash theme={null}
root@control:~# nmcli connection add type ethernet ifname enp0s3 con-name custom-connection ipv4.addresses 10.0.2.18/24 ipv4.gateway 10.0.2.1 ipv4.dns 8.8.8.8 ipv4.method manual
Connection 'custom-connection' (75de3eb2-9883-4dd5-8bac-1b89ee0bb9c5) successfully added.
```

Verify the connection was created (note the `DEVICE` column shows `--` when not active):

```bash theme={null}
root@control:~# nmcli connection show
NAME                UUID                                  TYPE      DEVICE
enp0s3              6f9c3bb8-fb17-38d3-93c0-e6cfa258782e  ethernet  enp0s3
lo                  a8886d34-a666-4301-9bae-e6d2e7b4eda2  loopback  lo
custom-connection   75de3eb2-9883-4dd5-8bac-1b89ee0bb9c5  ethernet  --
```

To inspect the connection's full properties:

```bash theme={null}
root@control:~# nmcli connection show custom-connection
```

(That command prints the connection's stored properties, such as IPv4/IPv6 settings, MAC address, autoconnect, and more.)

## 3. Activate the connection

Bring the connection up:

```bash theme={null}
root@control:~# nmcli connection up custom-connection
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
```

Then verify the interface has the configured IP address:

```bash theme={null}
root@control:~# ip addr show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:f0:46:06 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.18/24 brd 10.0.2.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::4c93:328c:c333:34cb/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
```

Confirm the routing table shows the configured gateway:

```bash theme={null}
root@control:~# ip route
default via 10.0.2.1 dev enp0s3 proto static metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.18 metric 100
```

Check DNS as configured by NetworkManager:

```bash theme={null}
root@control:~# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
```

<Callout icon="warning" color="#FF6B6B">
  Do not edit `/etc/resolv.conf` manually when NetworkManager is managing it — changes may be overwritten. Configure DNS via `nmcli` or NetworkManager config files if you need persistent edits.
</Callout>

Test connectivity by pinging the DNS server and resolving a hostname:

```bash theme={null}
root@control:~# ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=255 time=17.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=255 time=18.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=255 time=20.3 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 17.878/18.766/20.288/1.080 ms

root@control:~# ping -c 2 google.com
PING google.com (172.217.17.78) 56(84) bytes of data.
64 bytes from ams16s30-in-f78.1e100.net (172.217.17.78): icmp_seq=1 ttl=255 time=18.3 ms
64 bytes from ams16s30-in-f78.1e100.net (172.217.17.78): icmp_seq=2 ttl=255 time=19.7 ms
```

## 4. Modify an existing connection (add a second IPv4 address)

Use `nmcli connection modify` together with the `+` operator to append an IPv4 address:

```bash theme={null}
root@control:~# nmcli connection modify custom-connection +ipv4.addresses 10.0.2.19/24
```

If the connection is active, reapply it to make changes take effect:

```bash theme={null}
root@control:~# nmcli connection up custom-connection
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
```

Verify both IP addresses are present:

```bash theme={null}
root@control:~# ip addr show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:f0:46:06 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.18/24 brd 10.0.2.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet 10.0.2.19/24 brd 10.0.2.255 scope global secondary noprefixroute enp0s3
       valid_lft forever preferred_lft forever
```

## 5. Delete the custom connection

When you no longer need the connection, remove it:

```bash theme={null}
root@control:~# nmcli connection delete custom-connection
Connection 'custom-connection' successfully deleted.
```

Confirm removal:

```bash theme={null}
root@control:~# nmcli connection show
NAME    UUID                                  TYPE      DEVICE
enp0s3  6f9c3bb8-fb17-38d3-93c0-e6cfa258782e  ethernet  enp0s3
lo      a8886d34-a666-4301-9bae-e6d2e7b4eda2  loopback  lo
```

## Quick reference: common nmcli commands

| Task | Command |
| - | - |
| List device status | `nmcli device status` |
| List configured connections | `nmcli connection show` |
| Add a connection | `nmcli connection add type ethernet ifname <iface> con-name <name> ipv4.addresses <addr/mask> ipv4.gateway <gw> ipv4.dns <dns> ipv4.method manual` |
| Show connection details | `nmcli connection show <con-name>` |
| Activate a connection | `nmcli connection up <con-name>` |
| Modify a connection (append) | `nmcli connection modify <con-name> +ipv4.addresses <addr/mask>` |
| Delete a connection | `nmcli connection delete <con-name>` |

## Links and references

* NetworkManager documentation: [https://networkmanager.dev/docs/](https://networkmanager.dev/docs/)
* nmcli manual: `man nmcli`
* Red Hat NetworkManager guide: [https://access.redhat.com/documentation/en-us/red\_hat\_enterprise\_linux/](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/)

This concludes the demo on using nmcli to create, modify, activate, verify, and delete NetworkManager connections.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/6bd67b03-1052-4557-8920-4b79d1b17abf/lesson/05a8f637-d022-4ceb-9edb-9c9c9481c49c" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.