How to add IP to VM using nmcli Interactive Mode and Non-Interactive mode?

Helposoft Staff

Administrator
Staff member
Points
178
In this mode, commands are slightly different from using nmcli in a non-interactive way. Here’s how you can configure your network settings in the nmcli interactive mode and also outside of it.

Using nmcli Interactive Mode

In nmcli interactive mode, commands should be entered without the nmcli prefix, and you typically use specific commands for each setting. Here’s how to set the IP address and other network settings in interactive mode:
  1. Enter Interactive Mode
    If you're not already in interactive mode, start it with:

    Code:
    nmcli

  2. Edit the Connection
    To edit the network connection named ens18, enter the following command:

    Code:
    nmcli> con edit ens18

  3. Modify IP Address
    Within the interactive mode, use the following command to modify the IP address:

    Code:
    nmcli> set ipv4.addresses 31.xxx.xx.xxx/24

  4. Set the Gateway
    Set the gateway using:

    Code:
    nmcli> set ipv4.gateway 31.xxx.xx.x

  5. Set DNS Servers
    Configure the DNS servers with:

    Code:
    nmcli> set ipv4.dns "8.8.8.8 8.8.4.4"

  6. Set IPv4 Method to Manual
    Ensure the IPv4 method is set to manual:

    Code:
    nmcli> set ipv4.method manual

  7. Save and Quit
    Save the changes and exit the interactive mode with:

    Code:
    nmcli> save
    nmcli> quit

  8. Bring the Connection Up
    Apply the changes and bring the connection up:

    Code:
    nmcli con up ens18

Using nmcli Non-Interactive Commands

If you prefer to configure outside of interactive mode, use the non-interactive commands directly:
  1. Modify IP Address

    Code:
    nmcli con mod ens18 ipv4.addresses 31.xxx.xx.xxx/24

  2. Set the Gateway

    Code:
    nmcli con mod ens18 ipv4.gateway 31.xxx.xx.x

  3. Set DNS Servers

    Code:
    nmcli con mod ens18 ipv4.dns "8.8.8.8 8.8.4.4"

  4. Set IPv4 Method to Manual

    Code:
    nmcli con mod ens18 ipv4.method manual

  5. Bring the Connection Up

    Code:
    nmcli con up ens18

Summary

  • Interactive Mode: Use nmcli> con edit ens18 to start editing, then use set commands for configuration. Save and quit with save and quit.
  • Non-Interactive Mode: Directly use nmcli commands like nmcli con mod and nmcli con up.
Both methods are effective for configuring network settings. Choose the one that fits your workflow best. If you encounter any issues or need more assistance, feel free to ask!
 
Top