IP Address Management (IPAM) is crucial for configuring and managing IP addresses within a network. Understanding how to add, delete, and manage IP addresses using command-line tools is essential for any network administrator. This blog post will cover key IP address management commands, providing syntax, examples, and practical applications.
Table of Contents
1. ip addr add [IP address]/[CIDR] dev [interface]
Description: This command adds a specified IP address to a network interface.
Usage:
To add an IP address to an interface, use:
sudo ip addr add 192.168.1.100/24 dev eth0
This command assigns the IP address 192.168.1.100
with a subnet mask of 255.255.255.0
to the eth0
interface.
2. ip addr del [IP address]/[CIDR] dev [interface]
Description: This command removes a specified IP address from a network interface.
Usage:
To delete an IP address from an interface, use:
sudo ip addr del 192.168.1.100/24 dev eth0
This command removes the IP address 192.168.1.100
from the eth0
interface.
3. ip route add [destination] via [gateway]
Description: This command adds a new route to the routing table, directing traffic to a specified destination via a designated gateway.
Usage:
To add a route, use:
sudo ip route add 10.0.0.0/24 via 192.168.1.1
This command routes traffic destined for the 10.0.0.0/24
network through the gateway 192.168.1.1
.
4. ip route del [destination]
Description: This command removes a specified route from the routing table.
Usage:
To delete a route, use:
sudo ip route del 10.0.0.0/24
This command removes the route to the 10.0.0.0/24
network from the routing table.
5. ip addr flush dev [interface]
Description: This command removes all IP addresses assigned to a specified network interface.
Usage:
To flush all addresses from an interface, use:
sudo ip addr flush dev eth0
This command removes all IP addresses assigned to the eth0
interface, effectively resetting its configuration.
Conclusion
Effective IP address management is vital for maintaining a well-organized network. By mastering these commands, you can efficiently manage IP addresses, routes, and network interfaces in Linux. For more resources and insights on Linux networking, feel free to explore GeekersHub.
FAQs
1. What is the difference between ip addr
and ifconfig
?
The ip addr
command is part of the iproute2
suite and is the modern replacement for ifconfig
, which is deprecated. ip addr
offers more features and better handling of IP addresses.
2. Can I use these commands without superuser privileges?
Most of these commands require superuser privileges. Use sudo
to execute them.
3. How do I check current IP addresses on an interface?
You can check the current IP addresses by using:
ip addr show
For further reading, check the official documentation for the ip
command: Linux Man Pages.