Introduction
The ip command is a powerful and modern tool for network configuration and diagnosis on Linux systems. It has replaced the old ifconfig and provides granular control over interfaces, addresses, routes, and other components of the network stack.
Basic syntax
The general format is ip [options] object {command | help}. The most used objects are link, address, route and neighbour.
Displaying interfaces and addresses
To list all network interfaces:
ip link show
To view assigned IP addresses:
ip address show
Or its abbreviated form:
ip a
Configuring interfaces
Bring up or down an interface:
ip link set dev eth0 up
ip link set dev eth0 down
Assign a static IP address:
ip address add 192.168.1.10/24 dev eth0
Delete an address:
ip address del 192.168.1.10/24 dev eth0
Managing routes
Show the routing table:
ip route show
Add a static route:
ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0
Delete a route:
ip route del 10.0.0.0/24 via 192.168.1.1 dev eth0
Advanced features
- Network namespaces: They allow creating isolated network stacks. Example:
ip netns add testnsand thenip netns exec testns ip a. - VLANs: Configure a VLAN interface with
ip link add link eth0 name eth0.10 type vlan id 10. - Bonding and teams: Create a bond
ip link add name bond0 type bondand assign slaves. - Routing policies: Use
ip ruleandip routefor multiple routing tables.
Practical example: configuring an interface with a static IP and gateway
- Bring up the interface:
ip link set dev eth0 up - Assign IP:
ip address add 192.168.0.50/24 dev eth0 - Add default gateway:
ip route add default via 192.168.0.1 dev eth0 - Verify connectivity:
ping -c 3 8.8.8.8
Best practices and troubleshooting
- Always use
-brieffor a concise output:ip -brief address show - Use
ip monitorto observe changes in real time. - Persist configurations via files in
/etc/network/interfacesor tools likenetplanorNetworkManagerdepending on the distribution. - Check the kernel log with
dmesgif an operation fails.
Conclusion
Mastering the ip command allows administrators and advanced users to have total control over the network of their Linux systems. Its unified syntax and ability to work with namespaces, VLANs, and bonding make it indispensable in modern server and cloud environments.
This post is also available in ESPAÑOL.