ip Command
The ip command in Linux is used to display and manipulate routing, network devices, interfaces, and tunnels. It is a powerful utility provided by the iproute2 package and is considered a replacement for the older ifconfig and route commands.
Common Usage
ip [OPTIONS] OBJECT { COMMAND | help }OBJECT: Specifies the type of object to manipulate or view (e.g.,
address,link,route).COMMAND: The action to be performed on the object (e.g.,
add,delete,show).
Common OBJECTs
link: Manage network interfaces.addr: Display and configure IP addresses.route: Manipulate the routing table.neigh: Display and manipulate ARP entries (neighbor cache).maddr: Manage multicast addresses.rule: Manage rule-based routing.tunnel: Configure tunnel interfaces (e.g., GRE, IPIP).
Basic Examples
1. Display Network Interfaces (Link)
To view the status of all network interfaces:
This will show a list of all network interfaces, including their statuses (up, down), and other information like MTU (Maximum Transmission Unit).
To view a specific interface:
2. Display IP Addresses
To view all IP addresses configured on the system:
This shows IP addresses for all interfaces, including IPv4 and IPv6 addresses. To view details for a specific interface:
3. Assign IP Address to Interface
To assign an IP address to an interface, use the following syntax:
This command assigns the IP 192.168.1.100 with a subnet mask of 255.255.255.0 to the eth0 interface.
4. Delete an IP Address from Interface
To remove an IP address from an interface:
5. Bring Interface Up or Down
To bring an interface up (enable it):
To bring an interface down (disable it):
6. Display Routing Table
To view the system's routing table:
This will display the routing table entries, including default gateways and other routes.
7. Add a Static Route
To add a new static route to a network:
This adds a route to the 192.168.2.0/24 network through the gateway 192.168.1.1 using the eth0 interface.
8. Delete a Static Route
To delete a static route:
9. Configure a Default Gateway
To set a default gateway:
This configures 192.168.1.1 as the default gateway for all outbound traffic.
10. Display ARP Cache (Neighbor Entries)
To display the ARP (Address Resolution Protocol) cache:
11. Flush IP Addresses
To flush all IP addresses on an interface:
Advanced Examples
1. View Multicast Group Memberships
To view the multicast group memberships on an interface:
2. Configure Policy Routing
To add a rule that routes traffic from a specific source IP through a specific table:
Then, configure the routes for table 100:
3. Configure Tunnels
To configure a GRE tunnel:
This sets up a GRE tunnel between 192.168.1.100 (local) and 192.168.2.1 (remote).
IP Command Syntax Overview
ip link: Manage network interfaces (view, up/down, configure).ip addr: Manage IP addresses (view, add, delete).ip route: Manage the routing table (view, add, delete, change).ip neigh: Manage neighbor cache (ARP entries).ip maddr: Manage multicast addresses.
Conclusion
The ip command provides a versatile and modern way to manage network configurations in Linux. By replacing older utilities such as ifconfig and route, it offers a more consistent and extensible way to handle network interfaces, IP addresses, routes, and tunnels. It is a crucial tool for Linux system administrators and network engineers.
Last updated