The ip
command in Linux is used to configure network interfaces. It is part of the net-tools package which provides several network administration utilities on a Unix-based system. Earlier a command i.e. ifconfig
was used that provides the same functionalities as ip
command does. But ip
command posses much more capabilities than ifconfig
command.
In this article, you will see the usage of ip
command in Linux along with some examples.
The syntax of the Linux ip command
The syntax of using ip
command in Linux is given below –
ip [OPTIONS] OBJECT {COMMAND| help}
Where,
OPTIONS – You can find a list of options on ip
command man page
OBJECT – The object is object type some of the most frequently used objects are
link(l)
– Used to display and modify network interfacesaddress (a)
– It is used to modify IP addressesroute (r)
– Used to display and alter routing tableneigh(n)
– Used to manipulate the neighbor object (ARP table)
There are several other objects and commands that you can use. Use the following command to view the detailed list of objects and command –
ip help
This will display the output as given in the image below-
How to display and manage network interfaces
You can show the list of network interfaces using the link object with the ip command. With link objects, you can use the commands like show, set, add, and del. Now if you run the given command it will display –
ip link show
You will see the output of this command something like given in the image –
Get info of a specific network interface
Now if you want to get the information of a specific network interface then use –
ip link show dev wlp1s0
This will display the information of network interface wlp1s0.
Alter the status of a network interface
You can change the status of a network interface using set command with a link object of ip command. For example to make an interface let’s say wlp1s0 online you could use the following command –
ip link set wlp1s0 up
Now if you want to make it offline then use the following command –
ip link set wlp1s0 down
How to display and modify the IP addresses
For displaying and modification of the IP addresses we need to work with addr object. The most frequently used addr commands are show, add, and del.
Now to show the list of network interfaces along with the IP addresses associated with them use –
ip addr show
You can see the output of this command in the image below –
You could use ip -4 addr and ip -6 addr to display the ipv4 and ipv6 addresses respectively.
Get info of a specific network interface
You can use the following command to get information of a specific network interface –
ip addr show dev wlp1s0
How to assign the IP address to a network interface
Use the following command to assign the IP address to a network interface –
ip addr add IP_ADDRESS dev IFNAME
Where IFNAME is the interface name and IP_ADDRESS is the IP address that we are going to assign.
For example –
ip addr add 192.168.121.46/24 dev enp2s0
If you want to assign multiple IP addresses to a network interface then run the same command which is given above with a new IP address.
How to remove the IP address from a network interface
If you want to remove the IP address from a network interface then you can use the following command in your terminal –
ip addr del IP_ADDRESS dev IFNAME
For example –
ip addr del 192.168.121.46/24 dev enp2s0
This command will delete the given IP from the interface of the device enp2s0.
Conclusion
In this article, you have seen a few usages of the ip command for more details you could see its manual page. Now if you have any query then write us in the comments below.