Linux networking commands are provided by two packages iproute2 and net-tools. You would have probably used commands like ifconfig, route, arp, hostname etc if you have done networking with linux devices. These commands are part of the package net-tools which has been part of all linux distributions for a long time. Though popular, most of the linux distributions are slowly trying replace these with the networking commands present in new package iproute2.
Iproute2 package contain commands for linux kernal’s advanced networking features like tunneling, traffic controlling, packet encryption along with commands for doing familiar tasks like configuration of interfaces (IP addresses, MAC addresses, MTU, Link status etc) , routing table, multicast addressing, arp table etc.
Networking commands which are part of of the iproute2 package are ip , tc , arpd , ss , bridge , devlink , rtmon, nstat, routef, routel, ctstat and lnstat.
This tutorial describes how to use “ip” command for configuring IP address, MAC address, routing table , ARP table etc.
“ip” command is the SwissKnife for networking included in the iproute2 package. “ip” can be used for configuring interfaces, multicast address, arp table, routes, NAT, packet encryption, tunneling, routing policies etc. This command can also be used for monitoring the status of interfaces, routes, addresses continuously.
ip -brief address
(You can also use the command in abbreviated form as “ip -bri addr” or just “ip -bri a” )
For those who like a fancy output, use “-c” option to get the output in color
If you need more detailed information about interfaces like MAC address, MTU size, broadcast address etc, use
ip address show
or in short
ip a
“ip -bri a” will show both IPv4 and IPv6 addresses, If you want to filter only IPv4 addresses use
ip -bri -4 a
and to show only IPv6 addresses use
ip -bri -6 a
“ip addr” can be used to add, delete, replace and show IP address of an interface.
sudo ip addr add [ip-address] dev [interface-name]
Example:
sudo ip addr add 192.168.1.1/24 dev enp2s0f0
To delete ip address replace the option “add” with “del” in the above command
Usage:
sudo ip addr del [ip-address] dev [interface-name]
Example:
sudo ip addr del 192.168.1.1/24 dev enp2s0f0
Note: “ip” command allows configuring multiple ip address in one interface.
If multiple ip addresses are configured , you can delete all address using “flush”
sudo ip address flush dev enp2s0f0
You can use the option “-6” with the above command to configure or delete IPv6 address.
Usage:
sudo ip -6 addr add [ipv6-address] dev [interface-name]
Example:
sudo ip -6 addr add fc00::1/64 dev wlp3s0
To delete IPv6 address, use
sudo ip -6 addr del [ipv6-address] dev [interface-name]
You can configure interface parameters like MAC, MTU, status etc using “ip link”
sudo ip link set dev [interface-name] up
Example:
sudo ip link set dev enp2s0f0 down
sudo ip link set dev enp2s0f0 up
sudo ip link set [MAC-address] dev [interface-name]
Example:
sudo ip link set addr 00:11:22:33:44:55 dev enp2s0f0
sudo ip link set mtu [MTU-size] dev [interface-name]
Example:
sudo ip link set mtu 1000 dev enp2s0f0
sudo ip link set name [new-int-name] dev [current-int-name]
Example:
sudo ip link set name eth0 dev enp2s0f0
You might get the error “RTNETLINK answers: Device or resource busy” when trying to change the features of a interface, trying the command after making interface “down will work
ip neighbor command provides options to work with ARP table. You can add, delete, replace or flush entries in the ARP table using this command.
ip neighbor show
or in short,
ip n
sudo ip neighbor add [nbr-ip-address] lladdr [nbr-mac-address] dev [int-name]
Example:
sudo ip neighbor add 192.168.0.150 lladdr 00:11:22:33:44:55 dev wlp3s0
To delete an ARP entry, replace the option “add” with “del” in the above command.
sudo ip neighbor del 192.168.0.150 lladdr 00:11:22:33:44:55 dev wlp3s0
sudo ip neighbor flush dev [int-name]
“ip route” can be used to check the routing table, manipulate routes and default gateway.
ip route show
or in short,
ip r
ip -6 route show
or in short,
ip -6 r
sudo ip route add [Network-address] via [NextHop-IP]
Example:
sudo ip route add 192.168.2.0/24 via 192.168.0.2
To delete a route, use
sudo ip route del [Network-address]
Example
sudo ip route del 192.168.2.0/24
sudo ip route add default via [gateway-ip]
Example:
sudo ip route add default via 192.168.0.3
ip route get [destination-ip]