The ip
command in Linux is a powerful utility for network configuration and management. It allows users to interact with various networking components such as network interfaces, routing tables, addresses, and more. Here, we will look into the 'ip'
command, covering each aspect with examples, code, and detailed explanations.
The 'ip'
command is part of the iproute2
package and serves as a versatile replacement for older networking tools like `ifconfig
`
and `route
`
. It provides a unified interface for configuring and managing network settings in modern Linux distributions.
The basic syntax of the 'ip'
command is as follows:
ip [OPTIONS] OBJECT {COMMAND | help}
Where:
To view information about network interfaces and their associated IP addresses, use the following command:
ip addr showdisplaying network interface
This command displays details such as interface names (`eth0`
, `wlan0`
), MAC addresses, IPv4 and IPv6 addresses, subnet masks, and more.
To configure a network interface, you can use the `ip link`
command followed by the action (e.g., `set`
, `add`
, `delete`
).
For example: to set the IP address of an interface:
sudo ip addr add 192.168.1.100/24 dev eth0
This command assigns the IP address `192.168.1.100`
with a subnet mask of `24`
(equivalent to 255.255.255.0
) to the eth0
interface.
To delete an existing route from the routing table, you can use the `ip route delete`
command. For example:
sudo ip route delete 10.0.0.0/24 via 192.168.1.1 dev eth0
This command removes the route to the `10.0.0.0/24`
network via the gateway `192.168.1.1`
through the `eth0`
interface.
To change the default gateway for outgoing traffic, you can modify the default route using the `ip route`
command. For instance:
sudo ip route add default via 192.168.1.254 dev eth0
This command sets `192.168.1.254`
as the new default gateway through the `eth0`
interface.
To bring an interface up (activate it), you can use the `ip link`
command with the `set`
action. For example:
sudo ip link set eth0 up
This command brings the `eth0`
interface up, enabling it to send and receive network traffic.
To change the MTU (maximum transmission unit) of a network interface, you can use the `ip
link`
command with the `set`
action and the `mtu`
parameter. For instance:
sudo ip link set eth0 mtu 1500
This command sets the MTU of the `eth0`
interface to `1500`
bytes.
To monitor real-time network traffic on a specific interface, you can use the `ip -s link`
command in combination with tools like `watch
`
or `grep
`
to filter the output. For example:
watch -n 1 "ip -s link show eth0 | grep 'RX bytes'"
This command continuously monitors the receive (RX) traffic on the `eth0`
interface, updating every second.
To identify potential issues with a network interface, you can use the ip -s link
command to display detailed statistics, including error counts. For instance:
ip -s link show eth0 | grep -E 'errors|dropped'
This command shows statistics related to packet errors and dropped packets on the eth0
interface.
Options
Description
Example Usage
address
Show all IP addresses associated with all network devices.
ip address
Show information related to a specific interface.
ip address show (interface)
link
Display link layer information, including characteristics of link layer devices currently available.
ip link
Show statistics of various network interfaces.
ip -s link
Show statistics of a specific network interface.
ip -s link show (interface)
route
Display routing table, showing the route packets your network will take.
ip route
add
Assign an IP address to an interface.
ip a add (ip_address) dev (interface)
del
Delete an assigned IP address from an interface.
ip a del (ip_address) dev (interface)
up
Enable a network interface.
ip link set (interface) up
down
Disable a network interface.
ip link set (interface) down
monitor
Monitor and display the state of devices, addresses, and routes continuously.
ip monitor
help
Display help information about the `ip`
command.
ip help
neighbour
View MAC address of devices connected to the system.
ip neighbour
Delete an ARP entry.
ip neighbour del (ip_address) dev (interface)
Add an ARP entry.
ip neighbour add (ip_address) dev (interface)
1. addressThis option is used to show all IP addresses associated with all network devices.
ip addressip address
This will show the information related to all interfaces available on our system.
2. linkIt is used to display link layer information; it will fetch characteristics of the link layer devices currently available. Any networking device which has a driver loaded can be classified as an available device.
ip linkip link
This link option when used with -s option is used to show the statistics of the various network interfaces.
ip -s linkip -s link
And, to get information about a particular network interface, add an option show followed by the name of the particular network interface.
ip -s link show (interface)
For Example:
ip -s link show enp3s0ip -s link show enp3s0 3. monitor
This command can monitor and display the state of devices, addresses and routes continuously.
ip monitorip monitor 4. neighbour
This command is used to view the MAC address of the devices connected to your system.
ip neighbourip neighbour
ip neighbour del (ip_address) dev interface
For Example:
ip neighbour del 192.168.0.200 dev enp3s0
Add an ARP entry:
ip neighbour add (ip_address) dev interface
For Example:
ip neighbour add 192.168.0.200 dev enp3s0Conclusion
The `ip` command in Linux is a powerful tool that is used for performing administrative tasks. We can say that this command is the improved version of the deprecated `ifconfig` command. As we discussed, this command can be used to manipulate devices, routing and tunnels. This `ip` command can also monitor the state of devices, routes and addresses. Overall, we can say that this command is a versatile tool that can be helpful network administrators manage their networks more efficiently.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4