The ip command in Linux: advanced network management

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 testns and then ip 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 bond and assign slaves.
  • Routing policies: Use ip rule and ip route for multiple routing tables.

Practical example: configuring an interface with a static IP and gateway

  1. Bring up the interface: ip link set dev eth0 up
  2. Assign IP: ip address add 192.168.0.50/24 dev eth0
  3. Add default gateway: ip route add default via 192.168.0.1 dev eth0
  4. Verify connectivity: ping -c 3 8.8.8.8

Best practices and troubleshooting

  • Always use -brief for a concise output: ip -brief address show
  • Use ip monitor to observe changes in real time.
  • Persist configurations via files in /etc/network/interfaces or tools like netplan or NetworkManager depending on the distribution.
  • Check the kernel log with dmesg if 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .