The ip addr command is an essential tool for network management in Linux, offering a versatile set of features for configuring and troubleshooting network interfaces. As the successor to the now-deprecated ifconfig command, ip addr provides a more powerful and flexible way to handle network configurations on modern Linux systems. The ip addr command is a versatile tool in Linux, used for displaying and manipulating IP addresses associated with network interfaces.
The ip addr command is a powerful tool for managing network interfaces and their associated IP addresses in Linux systems. It provides a comprehensive way to view, add, modify, and delete IP addresses, as well as other network configuration details.
Here’s a professional guide to understanding and using the ip addr command in Linux with examples:
Table of Content
Understanding the ip addr Command in Linux
The ip addr command is a powerful ally for Linux users, providing a comprehensive set of features for network interface management. When executed without any additional parameters, ip addr displays all network interfaces on the system along with their associated IP addresses, network masks, and other relevant details.
This command is part of the iproute2 package, which is installed on all modern Linux distributions. The ip addr command replaces older tools like ifconfig, offering more features and better control over network interfaces and IP addresses.
Basic Usage:
To display information about all network interfaces and their IP addresses, simply run:
ip addr
This outputs a detailed list of interfaces, their states (up/down), hardware addresses, and associated IP addresses (both IPv4 and IPv6).
Examples of ip addr Command in Linux
The ip addr command replaces the older ifconfig command. It provides a more flexible and comprehensive way to manage network interfaces. Use it to view, add, modify, and delete IP addresses.
Let’s find the available options to customize the output.
Example 1: Displaying IP Addresses
As Linux continues to evolve, the ip addr command remains a fundamental component for efficient network management. To display all IP addresses on all network interfaces, the command is given below:
ip addr show
This lists all the network interfaces on the system along with their IP addresses, both IPv4 and IPv6. This targeted approach helps in pinpointing issues related to a particular interface.
Example 2: Displaying Information About a Specific Interface
To display information about a specific network interface, you can use the ip addr show [interface] command. This provides detailed information about the chosen interface, such as its current state (up or down), MAC address, IP addresses, and more.
To view details about a particular interface, such as enp0s3, use:
ip addr show eth0
Example 3: Adding an IP Address
One of the primary functions of ip addr is to manage IP addresses assigned to network interfaces. Users can add new IP addresses to an interface or remove existing ones without the need for a system reboot.
To add an IP address to an interface, use the add option: To assign an IP address to a network interface, the syntax is:
sudo ip addr add [IP_ADDRESS]/[PREFIX] dev [INTERFACE_NAME]
For example, to assign the IP address 192.168.0.124 with a subnet mask of 255.255.255.0 (which is equivalent to a prefix of /24) to the interface enp0s3, the command would be:
sudo ip addr add 192.168.0.124/24 dev enp0s3
It adds the IP address 192.168.0.124 to the enp0s3 interface along with a netmask of 24.
Example 4: Deleting an IP Address
Its ability to make immediate changes without rebooting the system makes it an indispensable tool for network administrators. For removing the IP address from an interface, use:
sudo ip addr del [IP_ADDRESS]/[PREFIX] dev [INTERFACE_NAME]
For instance, to remove the IP address 192.168.0.124/24 from enp0s3, the command is:
sudo ip addr del 192.168.0.124/24 dev enp0s3
Note: While directly modifying an IP address is not recommended, you can effectively achieve this by deleting the old address and adding a new one.
Example 5: Displaying IP Addresses in a Simplified Format
The ip addr command is an essential part of a Linux user’s toolkit, enabling precise control over network interfaces and IP management tasks. If you need information about a specific network interface, you can specify the device name:
ip addr show dev [INTERFACE_NAME]
Replace [INTERFACE_NAME] with the actual name of your network interface, such as enp0s3.
To get a concise overview of IP addresses:
ip addr show dev enp0s3 | grep inet
Example 6: Configuring Network Interfaces
In Linux, the ip addr command offers users to modify network interfaces. For instance, to bring an interface up or down, use the below commands:
sudo ip link set enp0s3 down
sudo ip link set enp0s3 up
Example 7: Managing Routing Tables
The ip route subcommand is used to manage the kernel routing tables. For example, to add a default gateway, the command is:
sudo ip route add default via 192.168.0.1 dev enp0s3
And to delete a route:
sudo ip route add default via 192.168.0.1 dev enp0s3
Additional Options:
Beyond basic address management, ip addr also supports advanced features like setting the maximum transmission unit (MTU) and managing broadcast addresses. These capabilities allow for fine-tuning of network performance and behavior, catering to the needs of complex network environments.
The ip addr command offers various options to fine-tune its output:
- o: Output in a more human-readable format.
- 4: Display only IPv4 addresses.
- 6: Display only IPv6 addresses.
- j: Output in JSON format.
By understanding the ip addr command and its options, you can efficiently manage network interfaces and their IP addresses on your Linux system.
Conclusion
The ip addr command is a powerful tool for network administrators and users who need to manage network interfaces and IP addresses on Linux systems. It provides a unified interface to handle various networking tasks efficiently. Remember, the configurations set with the ip command are not persistent across reboots. To make changes permanent, you need to edit the network configuration files specific to your Linux distribution or include the commands in a startup script.
Whether you’re a seasoned system administrator or a curious Linux enthusiast, mastering the ip addr command can significantly enhance your ability to manage and troubleshoot network configurations on Linux systems.