Original link: https://developer.aliyun.com/article/1637555
In Linux systems, the <span>ip</span>
command is a powerful tool for managing network interfaces and routing. Compared to the older <span>ifconfig</span>
command, the <span>ip</span>
command offers more features and finer control. This article will detail the common operations of the <span>ip</span>
command to help users manage and configure networks more effectively.
<span>ip</span>
Command Basics
<span>ip</span>
command is part of the <span>iproute2</span>
package, primarily used to display and manipulate routing tables, network interfaces, and tunnels. Its basic syntax is as follows:
ip [OPTIONS] OBJECT COMMAND
Where <span>OBJECT</span>
can be <span>link</span>
, <span>addr</span>
, <span>route</span>
, etc., and <span>COMMAND</span>
is the operation performed on the OBJECT, such as <span>add</span>
, <span>del</span>
, <span>show</span>
, etc.
Viewing Network Interface Information
To view the status and configuration information of all network interfaces:
ip link show
To view information for a specific network interface:
ip link show dev eth0
Enabling and Disabling Network Interfaces
To enable a network interface:
ip link set dev eth0 up
To disable a network interface:
ip link set dev eth0 down
Configuring IP Addresses
To add an IP address to a network interface:
ip addr add 192.168.1.10/24 dev eth0
To delete an IP address from a network interface:
ip addr del 192.168.1.10/24 dev eth0
To view all IP addresses on network interfaces:
ip addr show
To view the IP address of a specific network interface:
ip addr show dev eth0
Managing Routes
To view the current routing table:
ip route show
To add a route for a specific network:
ip route add 192.168.1.0/24 via 192.168.1.1
To delete a route for a specific network:
ip route del 192.168.1.0/24
To add a default route:
ip route add default via 192.168.1.1
Configuring Network Aliases
To configure an alias for a network interface, which facilitates managing multiple IP address scenarios:
ip addr add 192.168.1.20/24 dev eth0 label eth0:1
To view network aliases:
ip addr show dev eth0
Managing ARP Cache
To view the ARP cache table:
ip neigh show
To add a static ARP entry:
ip neigh add 192.168.1.10 lladdr 00:11:22:33:44:55 dev eth0
To delete an ARP entry:
ip neigh del 192.168.1.10 dev eth0
VLAN Configuration
To create a VLAN interface:
ip link add link eth0 name eth0.100 type vlan id 100
To delete a VLAN interface:
ip link delete eth0.100
Operation Summary Table
Operation Type | Command Example | Description |
---|---|---|
View Network Interfaces | <span>ip link show</span> |
Displays the status and configuration information of all network interfaces |
Enable Network Interface | <span>ip link set dev eth0 up</span> |
Enables the specified network interface |
Disable Network Interface | <span>ip link set dev eth0 down</span> |
Disables the specified network interface |
Configure IP Address | <span>ip addr add 192.168.1.10/24 dev eth0</span> |
Adds an IP address to the network interface |
Delete IP Address | <span>ip addr del 192.168.1.10/24 dev eth0</span> |
Deletes an IP address from the network interface |
View Routing Table | <span>ip route show</span> |
Displays the current routing table |
Add Route | <span>ip route add 192.168.1.0/24 via 192.168.1.1</span> |
Adds a route to the specified network |
Delete Route | <span>ip route del 192.168.1.0/24</span> |
Deletes a route for the specified network |
Configure Network Alias | <span>ip addr add 192.168.1.20/24 dev eth0 label eth0:1</span> |
Configures an alias for the network interface |
View ARP Cache | <span>ip neigh show</span> |
Displays the ARP cache table |
Add ARP Entry | <span>ip neigh add 192.168.1.10 lladdr 00:11:22:33:44:55 dev eth0</span> |
Adds a static ARP entry |
Delete ARP Entry | <span>ip neigh del 192.168.1.10 dev eth0</span> |
Deletes the specified ARP entry |
Create VLAN Interface | <span>ip link add link eth0 name eth0.100 type vlan id 100</span> |
Creates a VLAN interface |
Delete VLAN Interface | <span>ip link delete eth0.100</span> |
Deletes the VLAN interface |
Conclusion
The <span>ip</span>
command in Linux is a powerful and flexible network management tool capable of performing a variety of operations, from basic network interface configuration to advanced routing and VLAN management. By mastering these common operations, users can manage and configure the network environment of Linux systems more efficiently. Whether for daily management or troubleshooting, the <span>ip</span>
command is an indispensable tool.
Previous Recommendations
-
Over 20 Linux commands for log analysis, very comprehensive!
-
Deploying a MySQL cluster on K8s, stable!
-
10 Linux operation taboos!
-
40 common Nginx interview questions (with answers)
-
CPU spiking to 100%, uncovering a 16-year-old Linux kernel bug!
-
Detailed notes on Jenkins in production!
-
Network packet capture tool: Tcpdump practical tips and case analysis
-
Summary of online Linux CPU 100% fault troubleshooting
-
19 common issues with K8s clusters, recommended to bookmark
-
11 Jenkins usage tips that over 90% of people have never used!
-
Detailed summary of Nginx working principles and optimizations
-
Six high-frequency Linux operation troubleshooting notes!
-
17 commonly used operation metrics, 90% of people don’t know!
-
Why does performance drop so much after containerizing applications?
-
Detailed explanation of Nginx rate limiting, coping with traffic surges and malicious attacks
-
How to troubleshoot when the Linux disk is full?
-
What would you do if the CPU spikes to 900%?
-
Nginx performance optimization is covered in this article!
-
Which JDK should be used on K8s? Performance testing of 8 JDKs
-
K8s Pod “OOM Killer”, found the reason
-
17 commonly used operation metrics, frequently asked in interviews!
-
A little-known trick for troubleshooting K8s Pods!
-
Summary of high concurrency performance optimization notes for Nginx from large companies
-
Implementing a gray release system with Nginx+Lua+Redis
-
Building a CI/CD system based on Jenkins
-
Seven major application scenarios of Nginx (with configuration)
-
Summary of CI/CD practices from Zhu Bajie Network
-
16 diagrams explaining Kubernetes networking in detail
- The learning manual for the powerful Nginx (recommended to bookmark)
- 9 practical Shell scripts, recommended to bookmark!
- Essential Kubectl commands for K8S operations
- The most comprehensive explanation of Jenkins Pipeline
- Learning guide for the mainstream monitoring system Prometheus
- 40 common Nginx interview questions
-
Common Linux operation interview questions, a must-read for job seekers!
- 50 common interview questions for Linux operation engineers
-
25 common MySQL interview questions and answers