Streamline IP Address Management with NMCLI Scripts

Streamline IP Address Management

In this post, we’ll explore how NMCLI scripts can streamline IP address management tasks, making network administration smoother and more streamlined.

Table of Contents


Managing IP addresses in a network environment can be a tedious and time-consuming task. From assigning static IPs to configuring DHCP settings, network administrators often find themselves grappling with numerous manual configurations. However, with the right tools and automation techniques, this process can become significantly more efficient. One such tool that has gained popularity among Linux users is NMCLI (Network Manager Command Line Interface).

Understanding NMCLI

NMCLI is a command-line tool provided by NetworkManager, a Linux utility for managing network connections. It allows users to control various aspects of network configuration, including IP addressing, DNS settings, and network interface management, all from the command line.

Benefits of Using NMCLI Scripts

By leveraging NMCLI scripts, network administrators can automate repetitive tasks, reduce human error, and ensure consistent network configurations across multiple devices. Here are some key benefits of using NMCLI scripts:

Key FeaturesDescription
EfficiencyNMCLI scripts allow administrators to perform complex network configurations with a few simple commands, saving time and effort.
ConsistencyAutomating IP address management tasks ensures that network settings are applied consistently across all devices, minimizing the risk of misconfigurations.
ScalabilityNMCLI scripts can be easily scaled to manage large networks with hundreds or thousands of devices, making them ideal for enterprise environments.
FlexibilityWith NMCLI, administrators have fine-grained control over network configurations, allowing them to tailor settings to meet specific requirements.

Examples of NMCLI Scripts

Let’s dive into some practical examples of how NMCLI scripts can be used to automate IP address management tasks (modify them as needed to suit your environment):

Example 1: Assigning a Static IP Address

if [ -z "$IP_ADDRESS" ] || [ -z "$GATEWAY" ]; then
    echo "Usage: $0 <IP_ADDRESS> <GATEWAY>"
    exit 1
nmcli con mod eth0 ipv4.method manual
nmcli con mod eth0 ipv4.address "$IP_ADDRESS"/24
nmcli con mod eth0 ipv4.gateway "$GATEWAY"
nmcli con up eth0

This script takes an IP address and gateway IP address as arguments and configures the Ethernet interface eth0 with a static IP address and gateway.

Example 2: Configuring DHCP Settings

nmcli con mod eth0 ipv4.method auto
nmcli con up eth0

This script sets the Ethernet interface eth0 to obtain an IP address automatically via DHCP.

Example 3: Adding a Secondary IP Address

if [ -z "$IP_ADDRESS" ]; then
    echo "Usage: $0 <IP_ADDRESS>"
    exit 1
nmcli con mod eth0 +ipv4.address "$IP_ADDRESS"/24
nmcli con up eth0

This script takes an IP address as an argument and adds it as a secondary IP address to the Ethernet interface eth0.

Example 4: Configuring DNS Servers

if [ -z "$DNS_SERVERS" ]; then
    echo "Usage: $0 <DNS_SERVER_1 DNS_SERVER_2 ...>"
    exit 1
nmcli con mod eth0 ipv4.dns "$DNS_SERVERS"
nmcli con up eth0

This script takes DNS server IP addresses as arguments and configures them for the Ethernet interface eth0.


NMCLI scripts offer a powerful way to automate IP address management tasks in Linux environments. By writing simple scripts, network administrators can streamline configuration processes, improve efficiency, and ensure consistent network settings across their infrastructure. Whether it’s assigning static IPs, configuring DHCP settings, or managing DNS, NMCLI provides the flexibility and control needed to effectively manage network connections from the command line.

Incorporating NMCLI scripts into your network administration toolkit can lead to significant time savings and reduce the likelihood of errors associated with manual configuration. As networks continue to grow in complexity, automation tools like NMCLI will become increasingly essential for maintaining efficient and reliable connectivity.

Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *