How to Set Up a Static IP address by using NetworkManager

Share this article

NetworkManager is a Linux utility used for managing network connections. NetworkManager serves as the default network management tool, particularly in desktop environments. Its primary function is to handle the configuration and connection management of network interfaces, both wired and wireless.
Setting up a static IP address with NetworkManager provides stability and control over your network configuration. Unlike dynamic IP assignments, a static IP ensures that your device consistently uses the same address on the network. This can be particularly beneficial for servers, networked devices, or scenarios where a consistent IP is essential.

Problem Statement

How to Set Up a Static IP Address for NetworkManager

Solution

Identify con name where you want to apply static IP

foofunc@ubuntu:~$ nmcli con show
NAME                UUID                                  TYPE      DEVICE    
o2-WLAN84           9f55239e-7f69-4d67-a1aa-63b850015a59  wifi      wlp0s20f3 
virbr0              588c5c3f-cba3-422a-9db4-26531020aa57  bridge    virbr0           
WorkOpenconnect  7c2eecfd-ba75-47f4-9da9-b7ccdbc9dd5d  vpn       --        
User1’s iPhone      cc06c83f-eb5b-4065-9085-8c757e41838a  wifi      --        
Wired connection 1  396de19a-46b3-397b-8695-1ad6ae2a170e  ethernet  --        
Wired connection 2  6c224136-d70e-39b7-bc68-dda699fb5c79  ethernet  --        

Run following command to set up an IP address

nmcli con mod "Wired connection 1"   ipv4.addresses "192.168.0.5/24"   ipv4.gateway "192.168.0.1"   ipv4.dns "8.8.8.8,8.8.4.4"   ipv4.method "manual"

Explaination

Important features of NetworkManager

  • Simplifying Connection Management: NetworkManager simplifies the process of configuring and managing network connections. It provides a graphical user interface (GUI) for users who prefer a point-and-click approach, as well as a command-line interface (CLI) for more advanced users.
  • Wired and Wireless Networks: NetworkManager supports both wired (Ethernet) and wireless (Wi-Fi) connections. It automatically detects available networks and allows users to connect to them easily.
  • VPN Support: NetworkManager includes support for Virtual Private Network (VPN) connections. Users can configure and manage VPN connections, including popular types like OpenVPN and PPTP.
  • Connection Profiles: NetworkManager stores connection settings in profiles, making it easy to switch between different networks or configurations.
  • Security Features: It supports various security features, such as WPA and WPA2 for wireless connections, ensuring that network connections are secure.
  • Integration with Desktop Environments: NetworkManager integrates well with various desktop environments, providing a seamless experience for users in graphical environments like GNOME, KDE, and others.

NetworkManager Command line

The NetworkManager command-line interface (CLI) provides a powerful way to manage network configurations on Linux systems. The primary tool for this purpose is nmcli. Below are some common commands for managing network connections using nmcli:

  • Show all connections
nmcli connection show

  • Show details of a specific connection:
nmcli connection show <connection-name>
  • Display information about networking devices:
nmcli device status

Setting up static IP throug CLI

nmcli connection modify <connection-name> ipv4.method manual ipv4.addresses <static-IP>/<subnet> ipv4.gateway <gateway> ipv4.dns <DNS>

Example of the above command

nmcli con mod "Wired connection 1"   ipv4.addresses "192.168.0.5/24"   ipv4.gateway "192.168.0.1"   ipv4.dns "8.8.8.8,8.8.4.4"   ipv4.method "manual"

Testing

We will use nmcli command to show the connection to test the IP address is setup properly or not use the nmcli con show command to show the connection, In the following code section we have shown the connection details, command yeild lots of options but here we have listed down the some important fields.

foofunc@ubuntu:~$ nmcli connection show  "Wired connection 1"  
connection.id:                          Wired connection 1
connection.uuid:                        396de19a-46b3-397b-8695-1ad6ae2a170e
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s31f6
connection.autoconnect:                 yes
ipv4.method:                            manual
ipv4.dns:                               8.8.8.8,8.8.4.4
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.0.5/24
ipv4.gateway:                           192.168.0.1

Leave a Comment

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