ip Command on ChromeOS Linux Environment
The ip
command is a modern and robust utility for network configuration and management, replacing legacy tools like ifconfig
. It provides extensive functionality for configuring and monitoring network interfaces, routing tables, and more. On ChromeOS Linux (Crostini), the ip
command is an essential tool for handling networking tasks.
Syntax
The basic syntax of the ip
command is:
ip [options] object [command]
Key Components:
- object: Specifies the network object to interact with (e.g.,
link
,addr
,route
). - command: Defines the action to perform on the object (e.g.,
add
,show
,del
). - options: Modify the behavior or output of the command.
Examples of Usage
Display All Network Interfaces
To list all network interfaces and their details:
ip addr show
Example Output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
inet6 fe80::1e6f:65ff:fe7a:1c21/64 scope link
Enable a Network Interface
To bring a network interface up:
sudo ip link set eth0 up
Disable a Network Interface
To bring a network interface down:
sudo ip link set eth0 down
Assign an IP Address to an Interface
To assign a specific IP address to a network interface:
sudo ip addr add 192.168.1.150/24 dev eth0
Remove an IP Address from an Interface
To remove a specific IP address:
sudo ip addr del 192.168.1.150/24 dev eth0
View Routing Table
To display the current routing table:
ip route show
Add a Default Gateway
To add a default gateway:
sudo ip route add default via 192.168.1.1
Delete a Route
To remove a specific route:
sudo ip route del 192.168.1.0/24 dev eth0
Objects and Their Commands
link
Manages network interfaces.
- Show all links:
ip link show
- Change MTU:
sudo ip link set eth0 mtu 1400
addr
Manages IP addresses.
- Add or remove an address:
sudo ip addr add 192.168.1.150/24 dev eth0 sudo ip addr del 192.168.1.150/24 dev eth0
route
Manages routing tables.
- Add a route:
sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
- Show routes:
ip route show
neigh
Manages ARP (Address Resolution Protocol) entries.
- Show ARP table:
ip neigh show
- Add an entry:
sudo ip neigh add 192.168.1.10 lladdr 00:1a:2b:3c:4d:5e dev eth0
Troubleshooting
Interface Not Found
If a specified interface is not recognized, list all available interfaces:
ip link show
Permission Denied
Some commands require administrative privileges. Use sudo
when necessary:
sudo ip addr add 192.168.1.150/24 dev eth0
Persisting Changes
Changes made with ip
are temporary and reset after a reboot. Use network configuration files or scripts for permanent changes.
Best Practices
- Use Descriptive Commands: The
ip
command’s structure ensures clarity. Combine options and objects for precise operations. - Test Before Automating: Always test commands interactively before adding them to scripts.
- Document Changes: Keep track of network changes for easier debugging and management.
The ip
command is a versatile and modern tool for network configuration and management. By mastering its options and objects, ChromeOS users can efficiently handle networking tasks, ensuring robust and flexible connectivity.