From ifconfig to ip Command: Modern Linux Network Configuration
From ifconfig to ip Command: Modern Linux Network Configuration#
While setting up a server recently, I noticed many tutorials still use ifconfig, but running it shows “command not found”. Turns out ifconfig is deprecated—modern Linux distributions use the ip command instead. Let’s discuss the correct usage of ip and its advantages over ifconfig.
Why ifconfig Was Deprecated#
ifconfig comes from the net-tools package, which hasn’t been maintained in years. Its main issues:
- Incomplete network interface display - New naming conventions (enp3s0, wlp2s0) sometimes don’t show fully
- No support for advanced network features - Like network namespaces, policy routing
- Outdated architecture - Code from the 90s, hard to extend with new features
The ip command comes from iproute2 package, the official userspace tool for Linux kernel network subsystem. It’s more powerful with consistent syntax.
Core Syntax of ip Command#
The ip command uses an “object + operation” structure:
ip [OPTIONS] OBJECT {COMMAND}
Common objects:
- addr - IP address management
- link - Network device management
- route - Routing table management
- neigh - ARP/neighbor table management
Viewing Network Configuration#
Show All IP Addresses#
ip addr show
# Shorthand
ip a
Sample output:
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP
link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global enp3s0
valid_lft forever preferred_lft forever
Key information:
- state UP - Interface is enabled
- inet 192.168.1.100/24 - IPv4 address and subnet mask
- valid_lft - Address valid time (forever means static configuration)
Show IPv4 Addresses Only#
ip -4 addr show
Show Network Device Details#
ip link show
# View specific device
ip link show enp3s0
# Show statistics (packets, errors)
ip -s link show enp3s0
Statistics output:
RX: bytes packets errors dropped overrun mcast
1.2G 800K 0 0 0 0
TX: bytes packets errors dropped carrier collsns
500M 400K 0 0 0 0
- RX/TX - Receive/Transmit
- errors - Transmission errors (should be 0)
- dropped - Dropped packets (possibly due to buffer overflow)
Configuring IP Addresses#
Add IP Address#
# Add primary IP
ip addr add 192.168.1.100/24 dev enp3s0
# Add secondary IP (multiple IPs on same interface)
ip addr add 10.0.0.100/24 dev enp3s0
# View result
ip addr show enp3s0
Delete IP Address#
ip addr del 192.168.1.100/24 dev enp3s0
Flush All IPs from Interface#
ip addr flush dev enp3s0
Managing Network Interfaces#
Enable/Disable Interface#
# Enable
ip link set enp3s0 up
# Disable
ip link set enp3s0 down
Modify MTU#
ip link set enp3s0 mtu 9000
MTU (Maximum Transmission Unit) affects network performance:
- Ethernet default is 1500 bytes
- Jumbo frame can reach 9000 bytes (requires switch support)
- VPN tunnels may need smaller values (e.g., 1400)
Modify MAC Address#
# First disable interface
ip link set enp3s0 down
# Change MAC
ip link set enp3s0 address 00:11:22:33:44:66
# Re-enable
ip link set enp3s0 up
Note: Modifying MAC address requires disabling the interface first, otherwise it will error.
Route Management#
View Routing Table#
ip route show
# Shorthand
ip r
Sample output:
default via 192.168.1.1 dev enp3s0
192.168.1.0/24 dev enp3s0 proto kernel scope link src 192.168.1.100
- default - Default route
- via - Next hop gateway
- proto kernel - Automatically generated by kernel
- scope link - Directly connected route
Add Route#
# Add default route
ip route add default via 192.168.1.1
# Add static route
ip route add 10.0.0.0/8 via 192.168.1.254
# Specify outgoing device
ip route add 192.168.2.0/24 dev enp3s0
Delete Route#
ip route del default via 192.168.1.1
ip route del 10.0.0.0/8
Check Route to an IP#
ip route get 8.8.8.8
Output:
8.8.8.8 via 192.168.1.1 dev enp3s0 src 192.168.1.100 uid 0
This confirms routing correctness faster than traceroute.
ARP Table Management#
View ARP Table#
ip neigh show
# Shorthand
ip n
Output:
192.168.1.1 dev enp3s0 lladdr 00:11:22:33:44:55 REACHABLE
- lladdr - MAC address
- REACHABLE - Reachable state (also STALE, DELAY, etc.)
Add Static ARP Entry#
ip neigh add 192.168.1.200 lladdr 00:11:22:33:44:77 dev enp3s0
Delete ARP Entry#
ip neigh del 192.168.1.200 dev enp3s0
Flush ARP Cache#
ip neigh flush dev enp3s0
Practical Tips#
Color Output#
ip -c addr show
Color output makes different information types easier to distinguish:
- IP addresses - Cyan
- MAC addresses - Green
- Interface names - Yellow
JSON Format Output#
ip -j addr show | jq
JSON output is convenient for script parsing, suitable for automation scenarios.
Persistent Configuration#
ip command configurations are temporary and lost after reboot. Persistence methods:
Ubuntu/Debian - Use netplan:
# /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
enp3s0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Apply configuration:
netplan apply
CentOS/RHEL - Use nmcli:
nmcli con add type ethernet ifname enp3s0 \
ip4 192.168.1.100/24 gw4 192.168.1.1
nmcli con up enp3s0
ifconfig vs ip Comparison#
| Operation | ifconfig | ip Command |
|---|---|---|
| View all interfaces | ifconfig -a | ip a |
| View IP address | ifconfig eth0 | ip a show eth0 |
| Configure IP | ifconfig eth0 192.168.1.100 | ip a add 192.168.1.100/24 dev eth0 |
| Enable interface | ifconfig eth0 up | ip link set eth0 up |
| Disable interface | ifconfig eth0 down | ip link set eth0 down |
| View routes | route -n | ip r |
| Add default route | route add default gw 192.168.1.1 | ip r add default via 192.168.1.1 |
| View ARP | arp -a | ip n |
Common Troubleshooting#
1. Interface Has No IP Address#
Check DHCP service or configure manually:
# Manual configuration
ip a add 192.168.1.100/24 dev enp3s0
ip link set enp3s0 up
2. Cannot Access Internet#
Step-by-step troubleshooting:
# 1. Check interface status
ip link show
# 2. Check IP address
ip addr show
# 3. Check routing
ip route show
# 4. Test connectivity
ping 192.168.1.1
ping 8.8.8.8
3. IP Conflict#
Check ARP table:
ip neigh show | grep <conflicting-IP>
If you see multiple MAC addresses for the same IP, there’s a conflict.
Summary#
The ip command has clear advantages over ifconfig:
- More features (supports network namespaces, policy routing, etc.)
- Cleaner output (JSON and color output)
- Consistent syntax (object + operation pattern)
While the learning curve is steeper, it becomes more efficient once mastered. I recommend using ip command for new projects and gradually replacing ifconfig in old scripts.
On my tool website JsonKit, there’s a Linux Command Reference with complete parameter documentation and examples for the ip command—useful for quick reference during development.
Related Tools: Linux Command Reference | IP Address Lookup | Port Checker