If you’re still using ifconfig
, stop. This command was officially deprecated in Linux kernel 2.4 — way back in 2001.
When it comes to managing network configurations in Linux today, two popular tools stand out: ip
and nmcli
.
Both are powerful, but they serve different purposes and are used in different scenarios.
Picking the wrong one can make your job harder than it needs to be.
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Start Learning Linux today - Free!If you’re new to Linux or just trying to figure out which tool to use, this article is for you.
Table of Contents
What is the ip
Command?
The ip
command is a low-level tool used to manage and configure network interfaces, routes, and other networking settings.
It is part of the iproute2
package and is considered the modern replacement for older tools like ifconfig
.
Think of the ip
command as a “manual” tool for networking. It gives you full control over your network settings, but you need to know exactly what you’re doing.
One thing to keep in mind is that the ip
command only makes temporary changes to network settings—it doesn’t update any configuration files. This means that any changes made with ip
will be lost after a reboot.
If you want your changes to persist, you must save them in the appropriate configuration files or use tools like nmcli
(on RHEL) or Netplan
(on Ubuntu).
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:81:47:9d brd ff:ff:ff:ff:ff:ff
inet 10.254.175.59/25 brd 10.254.175.127 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:b9:14:7a:96 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
Why ip
Isn’t Always Enough
Don’t get me wrong — ip
is a powerhouse for managing network configurations in Linux. It’s fast, versatile, and far better than the outdated ifconfig
.
But here’s the problem: it has its limits. If you’ve ever struggled with networking in Linux, you’ve probably hit one (or more) of these roadblocks:
- 🚧 Verbose Output —
ip
dumps a lot of information at once, making it hard to parse when troubleshooting. Its output requires extra effort to read and debug. - ⚠️ No High-Level Abstractions — Need to manage Wi-Fi, VPNs, or bonding interfaces?
ip
won’t do it alone. - 📊 Limited Automation — While powerful in scripts,
ip
lacks built-in profiles or persistent configurations. - 📝 Syntax Overload — Commands like
ip route add 192.168.1.0/24 via 10.0.0.1 dev eth0
get unwieldy fast, especially in complex setups.
Common Use Cases for ip
Command – Temporary Change:
- To view all network interfaces and their IP addresses, use:
ip addr
- To enable or disable a specific network interface, use:
ip link set eth0 up
ip link set eth0 down
- To manually assign or remove an IP address from an interface, use:
ip addr add 192.168.1.100/24 dev eth0
ip addr del 192.168.1.100/24 dev eth0
- To display the current routing table, use:
ip route
- To add a route to a specific network, use:
ip route add 192.168.2.0/24 via 192.168.1.1
Key Features of ip
Command:
- Low-level control: You can configure almost every aspect of networking.
- No dependencies: It works without requiring any additional services or daemons.
- Manual configuration: Changes made with
ip
are not persistent (they reset after a reboot unless saved elsewhere).
What is nmcli
?
nmcli
(NetworkManager Command Line Interface) is a high-level tool used to interact with NetworkManager
, a service that manages network connections on Linux.
It simplifies network configuration by automating many tasks.
Think of nmcli
as a “smart assistant” for networking. It works with NetworkManager to handle complex configurations, making it easier for users to manage networks without diving into the details.
nmcli -t -f IP4.ADDRESS,IP4.GATEWAY device show
📌 Example Output
IP4.ADDRESS[1]:192.168.1.100/24
IP4.GATEWAY:192.168.1.1
Pro Tips for nmcli
:
- Use Autocomplete: Start typing a command and press
Tab
to see available options. - Make Changes Persist: Unlike
ip
, changes innmcli
are persistent after a reboot. - Script-Friendly:
nmcli
can be easily integrated into scripts for automated network management. nmcli
provides structured, human-readable output, making troubleshooting faster and easier.
Why nmcli
Isn’t perfect
No doubt, nmcli
is a game-changer for Linux networking. It brings NetworkManager
to the command line, making it easier to configure Wi-Fi, VPNs, and connections without digging into config files.
But here’s the problem: it’s not perfect. If you’ve ever tried using nmcli
, you might have run into these frustrations:
- 🖥 Too Abstract — While
nmcli
is great for managing profiles, it hides the raw networking details that tools likeip
expose. - 🔄 Not Always Available —
nmcli
relies onNetworkManager
, which isn’t installed by default on minimal server setups. - ⚡ Slower Than
ip
– Sincenmcli
interacts withNetworkManager
, it adds an extra layer compared to the direct approach ofip
.
If any of this sounds familiar, you might want to rethink when and where you use nmcli
.
Common Use Cases for nmcli
— Permanent Change:
- To view all active and saved network connections, use:
nmcli connection show
- To connect to a Wi-Fi network, use:
nmcli device wifi connect "WiFi-Name" password "WiFi-Password"
- To create a new Ethernet connection with a static IP, use:
nmcli connection add type ethernet ifname eth0 con-name "MyConnection" ip4 192.168.1.100/24 gw4 192.168.1.1
- To update the IP address of an existing connection, use:
nmcli connection modify "MyConnection" ipv4.addresses 192.168.1.200/24
- To enable or disable a specific interface, use:
nmcli device connect eth0
nmcli device disconnect eth0
You can also change network configurations by NetworkManager configuration file:
/etc/NetworkManager/system-connections/<connection-name>.nmconnection
Find your connection file by running:
ls /etc/NetworkManager/system-connections/
It should show a file like eth0.nmconnection
.
Edit the configuration file:
sudo nano /etc/NetworkManager/system-connections/eth0.nmconnection
Modify or add the following:
[ipv4]
method=manual
addresses=192.168.1.100/24
gateway=192.168.1.1
dns=8.8.8.8;8.8.4.4;
Restart NetworkManager to apply changes:
sudo systemctl restart NetworkManager
Key Features of nmcli
:
- High-level abstraction: It simplifies networking tasks by automating configurations.
- Persistent changes: Configurations made with
nmcli
are saved and persist after a reboot. - Integration with NetworkManager: It works seamlessly with the NetworkManager service to manage connections.
Key Differences Between ip
and nmcli
- Level:
ip
is low-level,nmcli
is high-level. - Persistence:
ip
changes are temporary,nmcli
changes are persistent. - Dependency:
ip
(iproute2) is usually core,nmcli
requires the NetworkManager service. - Abstraction:
ip
offers fine-grained control,nmcli
provides higher-level abstractions (like connection profiles). - Use Case:
ip
for temporary changes, troubleshooting, low-level scripting.nmcli
for managing persistent connections (especially Wi-Fi, VPNs), simplifying common tasks.
When to Use ip
vs. nmcli
Use ip
When:
- You need fine-grained control over network settings.
- NetworkManager is not installed or running on your system.
- You’re troubleshooting or making temporary changes.
Use nmcli
When:
- You want to manage saved network connections (e.g., Wi-Fi, Ethernet).
- You prefer a simpler, more automated approach to networking.
- You need persistent configurations that survive reboots.
Example Scenarios
Scenario 1: Assign a Temporary IP Address
If you need to quickly assign an IP address to an interface for testing, use the ip
command:
ip addr add 192.168.1.100/24 dev eth0
Scenario 2: Connect to a Wi-Fi Network
If you want to connect to a Wi-Fi network and save the configuration for future use, use nmcli
:
nmcli device wifi connect "MyWiFi" password "MyPassword"
Scenario 3: View All Active Connections
To see all active and saved connections, use nmcli
:
nmcli connection show
Scenario 4: View Current IP Addresses
To check the current IP addresses of all interfaces, use the ip
command:
ip addr
Conclusion
Both ip
and nmcli
are essential tools for managing networks in Linux, but they serve different purposes. If you need precise, low-level control, go with the ip
command. If you want a more user-friendly, high-level approach, nmcli
is the way to go.
By understanding the strengths of each tool, you can choose the right one for your specific networking needs. Whether you’re a Linux beginner or an experienced sysadmin, mastering both tools will make you a networking pro!