Linux ip command
The ip
command in Linux is a versatile and powerful tool used for managing and configuring network interfaces, routing, and IP addresses. It is considered the successor to older networking tools like ifconfig
, route
, and netstat
, offering a more modern and unified approach to network management.
Basic Syntax of the ip
Command
- OBJECT: The type of object you want to manage (e.g.,
link
,addr
,route
, etc.). - COMMAND: The action you want to perform on the object (e.g.,
show
,add
,del
). - help: Displays help for the
ip
command.
Common Objects and Commands
- link: Manage network interfaces (similar to
ifconfig
). - addr: Manage IP addresses (IPv4 and IPv6).
- route: Manage routing tables.
- neigh: Manage ARP (Address Resolution Protocol) cache.
- maddr: Manage multicast addresses.
- tunnel: Manage IP tunnels.
Examples of Using the ip
Command
1. Display Network Interfaces
- To display all network interfaces and their configurations:
- Example Output:
- Explanation:
lo
: The loopback interface (for internal communication).eth0
: The first Ethernet interface.UP
: Indicates that the interface is up and active.mtu
: Maximum transmission unit size for the interface.
2. Display IP Addresses
- To display the IP addresses of all interfaces:
- Example Output:
- Explanation:
inet
: Displays the IPv4 address assigned to the interface.inet6
: Displays the IPv6 address assigned to the interface (not shown in the above output, but would be listed if assigned)./24
: The subnet mask in CIDR notation (255.255.255.0 in this case).
3. Bring an Interface Up or Down
- To bring an interface up (activate it):
- To bring an interface down (deactivate it):
4. Assign an IP Address to an Interface
- To assign a static IP address to an interface:
- Explanation:
- This command assigns the IP address
192.168.1.100
with a subnet mask of255.255.255.0
(CIDR notation/24
) to the interfaceeth0
.
- This command assigns the IP address
5. Delete an IP Address from an Interface
- To delete an IP address from an interface:
6. Show Routing Table
- To display the routing table:
- Example Output:
- Explanation:
- default: The default route for traffic that doesn’t match any other route.
- via 192.168.1.1: Traffic should be forwarded through the gateway
192.168.1.1
. - 192.168.1.0/24: This network is directly reachable via
eth0
.
7. Add a Route
- To add a static route:
- Explanation:
- This adds a route to the network
10.0.0.0/24
via the gateway192.168.1.1
using the interfaceeth0
.
- This adds a route to the network
8. Delete a Route
- To delete a route:
9. View ARP Cache
- To display the ARP cache (which maps IP addresses to MAC addresses):
- Example Output:
Summary of Common ip
Command Options
Command | Description |
---|---|
ip link show | Display network interfaces |
ip addr show | Show IP addresses for all interfaces |
ip addr add [IP] dev [interface] | Assign an IP address to an interface |
ip addr del [IP] dev [interface] | Remove an IP address from an interface |
ip link set [interface] up | Bring an interface up |
ip link set [interface] down | Bring an interface down |
ip route show | Display the routing table |
ip route add [network] via [gateway] | Add a new route |
ip route del [network] via [gateway] | Delete a route |
ip neigh show | Display ARP cache |
ip
vs ifconfig
ip
command is more powerful and modern compared toifconfig
. It integrates multiple network functions (address management, route management, link management) into one tool, whileifconfig
is mainly for displaying and configuring interfaces.ip
uses more flexible and intuitive syntax, supporting both IPv4 and IPv6, whileifconfig
was limited to IPv4.
The ip
command is widely used in modern Linux systems for its robustness and flexibility.