ip(including-relevant-subcommands)
The ip
command in Linux is a powerful and flexible tool for network configuration and management. It is used for a wide range of tasks related to networking, such as assigning IP addresses, routing, managing network interfaces, and controlling network devices. The ip
command is part of the iproute2
package, which is the preferred set of utilities for network management on Linux.
Overview of the ip
Command
ip
CommandThe basic syntax of the ip
command is:
Where:
OPTIONS: Optional flags and parameters to modify the behavior of the command.
OBJECT: The type of object to operate on (e.g.,
link
,addr
,route
).COMMAND: The action to perform on the object (e.g.,
add
,delete
,show
).
Common Subcommands and Use Cases
1. ip link
- Manage Network Interfaces
The ip link
command is used to manage network interfaces. This includes actions like bringing interfaces up or down, setting interface parameters, and viewing interface details.
Show all network interfaces:
Bring an interface up:
Bring an interface down:
Change interface MTU (Maximum Transmission Unit):
Rename a network interface:
2. ip addr
- Manage IP Addresses
The ip addr
command is used to show and configure IP addresses assigned to network interfaces.
Show IP addresses for all interfaces:
Assign an IP address to an interface:
Delete an IP address from an interface:
Assign an alias (secondary IP address):
3. ip route
- Manage Routing Table
The ip route
command is used to view and modify the system's routing table. This is useful for controlling how network traffic is directed.
Show the routing table:
Add a new route:
Delete a route:
Add a default route:
4. ip link set
- Change Link Parameters
This command allows you to modify the configuration of a network interface.
Set the interface to promisc mode (for packet sniffing):
Disable promiscuous mode:
5. ip addr flush
- Remove IP Addresses
This command is used to remove all IP addresses from a network interface.
Flush all IP addresses from an interface:
6. ip link set
- Change Interface MTU
You can adjust the Maximum Transmission Unit (MTU) size for network interfaces.
Set MTU size for an interface:
7. ip maddr
- Manage Multicast Addresses
The ip maddr
command is used to show and configure multicast addresses for network interfaces.
Show multicast addresses:
Add a multicast address to an interface:
Delete a multicast address from an interface:
8. ip tunnel
- Manage Tunnels
Tunnels allow network packets to be encapsulated for transmission over a network.
Create a new GRE tunnel:
Bring up a tunnel interface:
Delete a tunnel:
9. ip netns
- Manage Network Namespaces
Network namespaces allow the creation of isolated network environments.
Create a new network namespace:
Assign a network interface to a namespace:
List all network namespaces:
10. ip link set dev
- Change Interface States
Set interface to up:
Set interface to down:
Advanced Examples
Show all IP addresses for a specific interface:
Set the default route to a new gateway:
Add a static route to a network:
Change the MTU of an interface:
Remove an interface's IP address:
Conclusion
The ip
command is an essential tool for network management on Linux systems. It offers a broad range of functionalities, including managing network interfaces, routing, and IP addresses. Mastering this tool is crucial for anyone managing Linux network configurations, whether for personal use or in large-scale enterprise environments.
Last updated