Share on Social Media

Discover how to configure Linux network settings using nmcli commands. Follow our detailed guide to manage network connections, configure interfaces, and troubleshoot network issues on your Linux system efficiently. #centlinux #linux #networking

What is Linux Networking?

Linux Networking refers to the suite of tools, protocols, and services that facilitate the connection and communication between Linux systems and other devices within a network. It involves configuring and managing network interfaces, setting up routing, ensuring security, and handling network-related services. Here are the key components and aspects of Linux Networking:

Key Components

  1. Network Interfaces: Physical (Ethernet, Wi-Fi) and virtual interfaces (loopback, VLAN, bridge).
  2. IP Addressing: Assigning IP addresses to network interfaces, including static and dynamic IP configuration using DHCP.
  3. Routing: Directing data packets between different networks and subnets using routing tables.
  4. DNS (Domain Name System): Resolving domain names to IP addresses.
  5. Firewall: Implementing security rules to control incoming and outgoing network traffic (e.g., using iptables or firewalld).
  6. Network Services: Configuring services like DHCP, DNS, NFS, and Samba for sharing files and resources.

Tools and Commands

  1. ifconfig/ip: For configuring network interfaces.
  2. nmcli: A command-line tool for managing NetworkManager, which provides a high-level interface for network configuration.
  3. route/ip route: For managing routing tables.
  4. iptables/nftables: For setting up and managing firewall rules.
  5. netstat/ss: For displaying network connections, routing tables, and interface statistics.
  6. ping: For checking connectivity to other devices.
  7. traceroute: For tracing the path packets take to reach a destination.
  8. dhclient: For obtaining an IP address via DHCP.

Network Configuration Files

  1. /etc/network/interfaces: Configuration file for network interfaces (used by ifupdown).
  2. /etc/sysconfig/network-scripts/: Directory containing network scripts for interface configuration (used by network service).
  3. /etc/hostname: File for setting the system’s hostname.
  4. /etc/hosts: Static hostname to IP address mappings.
  5. /etc/resolv.conf: DNS resolver configuration.

Network Services

  1. SSH (Secure Shell): For remote login and command execution.
  2. DHCP (Dynamic Host Configuration Protocol): For dynamic IP address assignment.
  3. DNS (Domain Name System): For resolving domain names to IP addresses.
  4. NFS (Network File System): For file sharing between Unix/Linux systems.
  5. Samba: For file and print sharing with Windows systems.
  6. HTTP/HTTPS: For web services.
  7. FTP/SFTP: For file transfer.

Common Tasks

  1. Configuring Static and Dynamic IP Addresses: Setting up network interfaces with static IP addresses or using DHCP for dynamic IP address assignment.
  2. Managing Network Connections: Using tools like NetworkManager for managing wired and wireless connections.
  3. Setting Up Firewalls: Implementing security measures to protect the system from unauthorized access.
  4. Troubleshooting Network Issues: Using diagnostic tools like ping, traceroute, netstat, and ss to diagnose and resolve network problems.
  5. Securing Remote Access: Configuring SSH for secure remote administration.

Linux Networking is an essential skill for system administrators, allowing them to ensure connectivity, security, and efficient data exchange within and across networks.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

745772 0021

What is nmcli?

nmcli (NetworkManager Command Line Interface) is a command-line utility used to manage network connections on Linux systems. It interacts with the NetworkManager service to create, modify, and delete network connections, and provides detailed information about the network status and configuration. This utility is particularly useful for scripting and remote management, offering a powerful alternative to graphical network management tools.

Key Features of nmcli

  1. Connection Management: Create, modify, delete, and activate/deactivate network connections.
  2. Device Management: View and manage network devices, such as Ethernet and Wi-Fi interfaces.
  3. Network Status: Display detailed information about the network status, including IP addresses, routes, and connectivity.
  4. Scripting: Automate network configuration tasks through scripts.
  5. VPN Management: Create and manage VPN connections.

Summary

nmcli is a versatile tool for network management on Linux systems, offering extensive capabilities for handling both simple and complex network configurations. It is an essential utility for system administrators and anyone who needs to manage Linux networks from the command line.

Problem Statement

In RHEL/CentOS 7, by default network has been managed by the Network Manager. And we know that graphical mode is not available on the server, therefore, configuring network on a newly installed Linux machine can be a difficult task, if we are not familiar with the Network Manager command-line utilities i.e. nmtui and nmcli.

We prefer to work from CLI, therefore we will use nmcli. However, you may use nmtui as well.

In this article, we will configure dynamic and static Linux network with nmcli command.

Read Also: How to Configure Linux IPv6 Networking

Check Status of Linux Network Devices and Connections

To check status of current devices.

# nmcli device status
DEVICE       TYPE      STATE         CONNECTION
eno16777728  ethernet  connected     eno16777728
eno33554968  ethernet  disconnected  --
lo           loopback  unmanaged     --

To check status of current connections.

# nmcli connection show
NAME         UUID                                  TYPE            DEVICE
eno16777728  a5c248f9-1118-443e-a2bc-7b2de73afe72  802-3-ethernet  eno16777728

To check complete details about a connection.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            manual
ipv4.dns:                               192.168.116.2
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.116.11/24, gw = 192.168.116.2 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

Configure Linux Network

Dynamic Network Configurations

Currently, the IPv4 address of the above system is set statically. To change it to dynamically obtain an IP address from available DHCP Server.

# nmcli connection modify eno16777728 ipv4.method auto ipv4.addresses "" ipv4.dns ""

Restart connection to apply settings.

# nmcli connection down eno16777728 ; nmcli connection up eno16777728
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

Check the settings now.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

Static Network Configurations

To configure a network connection statically, we can use the same nmcli command with different parameters.

# nmcli connection modify eno16777728 ipv4.method manual ipv4.addresses "192.168.116.11/24 192.168.116.2" ipv4.dns 192.168.116.2

Restart connection to apply settings.

# nmcli connection down eno16777728 ; nmcli connection up eno16777728
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

Check the settings now.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            manual
ipv4.dns:                               192.168.116.2
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.116.11/24, gw = 192.168.116.2 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Final Thoughts

Configuring Linux network settings using nmcli commands offers a powerful and efficient way to manage your network connections. By mastering these commands, you can easily configure interfaces, manage connections, and troubleshoot network issues on your Linux system.

If you found this guide helpful and need additional support or personalized services for your projects, visit my Fiverr profile to explore my range of offerings. Whether it’s network configuration, troubleshooting, or other Linux-related tasks, I’m here to help you achieve your goals efficiently and effectively.

Thank you for reading, and happy networking!

Leave a Reply