Skip to content

How to Configure a Static IP Address with nmcli

Table of Contents

  1. Introduction
  2. Step 1: Identify the Network Interface πŸ–₯️
  3. Step 2: Configure the Primary Static IP Address 🌐
  4. Step 3: Add a Secondary Static IP Address βž•
  5. Step 4: Set DNS Servers (Optional) πŸ› οΈ
  6. Step 5: Bring Up the Interface πŸ†™
  7. Step 6: Verify the Configuration βœ…
  8. Conclusion 🎯

1. Introduction

Setting a static IP address is important for devices that require a consistent network address. Additionally, in some cases, you may need to configure multiple IP addresses on the same interface. This tutorial will guide you through configuring both primary and secondary static IP addresses using the nmcli tool.


2. Step 1: Identify the Network Interface πŸ–₯️

First, identify the network interface you want to configure:

nmcli device status

You will see a list of interfaces, such as eth0, enp0s3, or wlp3s0. Choose the one you want to assign static IPs to.


3. Step 2: Configure the Primary Static IP Address 🌐

Let’s first configure the primary static IP address. Replace <interface> with your interface name, and set the IP address, gateway, and subnet:

nmcli connection modify <interface> ipv4.addresses 192.168.1.100/24
nmcli connection modify <interface> ipv4.gateway 192.168.1.1
nmcli connection modify <interface> ipv4.method manual

Explanation:

  • ipv4.addresses 192.168.1.100/24: The static IP address (192.168.1.100) and subnet mask (/24).
  • ipv4.gateway 192.168.1.1: The gateway address for your network.
  • ipv4.method manual: Configures the interface to use manual (static) IP settings instead of DHCP.

4. Step 3: Add a Secondary Static IP Address βž•

To add a secondary (or additional) IP address to the same interface, use the following command:

nmcli connection modify <interface> +ipv4.addresses 192.168.1.101/24

Explanation:

  • The +ipv4.addresses option appends the additional IP address (192.168.1.101) to the interface.

You can add more secondary IPs similarly if needed.


5. Step 4: Set DNS Servers (Optional) πŸ› οΈ

Optionally, specify DNS servers:

nmcli connection modify <interface> ipv4.dns "8.8.8.8 8.8.4.4"

This sets Google’s public DNS servers (8.8.8.8 and 8.8.4.4).


6. Step 5: Bring Up the Interface πŸ†™

Apply the configuration and bring the interface up:

nmcli connection up <interface>

If the connection is already active, reload the settings:

nmcli connection reload

7. Step 6: Verify the Configuration βœ…

Make sure both the primary and secondary IP addresses are correctly configured:

ip addr show <interface>

You should see both the primary IP (192.168.1.100) and the secondary IP (192.168.1.101) listed.

You can also verify the connection details with:

nmcli device show <interface>

8. Conclusion 🎯

You’ve now configured both a primary and a secondary static IP address using nmcli. This setup can be useful when a single interface needs to be accessible via multiple IP addresses.