How to Configure a Static IP Address with nmcli
Table of Contents
- Introduction
- Step 1: Identify the Network Interface π₯οΈ
- Step 2: Configure the Primary Static IP Address π
- Step 3: Add a Secondary Static IP Address β
- Step 4: Set DNS Servers (Optional) π οΈ
- Step 5: Bring Up the Interface π
- Step 6: Verify the Configuration β
- 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:
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:
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:
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:
If the connection is already active, reload the settings:
7. Step 6: Verify the Configuration β
Make sure both the primary and secondary IP addresses are correctly configured:
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:
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.