How does ifconfig vs ip command work internally in Linux?

The ifconfig and ip commands in Linux are used for network interface configuration, but they operate differently and serve distinct purposes. The ifconfig command is part of the net-tools package, which is deprecated in many Linux distributions. It is primarily used for configuring network interfaces, viewing their statuses, and setting IP addresses. On the other hand, the ip command is part of the iproute2 package and provides a more comprehensive and modern set of tools for networking tasks, including managing routing, devices, policy routing, and tunneling.

Internally, ifconfig interacts with the kernel through system calls to retrieve and modify network interface configurations. It uses ioctl (input/output control) system calls, which directly interface with the kernel's networking subsystem. The ip command communicates with the kernel using the netlink socket interface, which is more efficient and versatile, allowing for better handling of advanced networking features.

As a result, while both commands can be used to display and configure network interfaces, the ip command is recommended for use in modern systems due to its extensibility and continued updates. Here are some examples of how both commands work:

# Using ifconfig to view network interfaces ifconfig # Using ip to view network interfaces ip addr show # Using ifconfig to assign an IP address ifconfig eth0 192.168.1.10 # Using ip to assign an IP address ip addr add 192.168.1.10/24 dev eth0

ifconfig ip command network configuration Linux networking net-tools iproute2 network management system calls ioctl netlink socket