How To Use IP (Replacement For ifconfig) Command on Linux

IP command is similar to ifconfig, which is very familiar for assigning Static IP Address, Route & Default Gateway, etc.,.

ifconfig command was deprecated due to no maintenance since so many years, even though it is still available on most Linux distributions.

ifconfig command has been replaced by IP command which is very powerful and performing several network administration tasks with one command.

IP command utility bundled with iproute2 package. By default iproute2 utility pre-installed all the major Linux distribution. If no, you can install it by issuing iproute2 on your terminal with help of package manager.

Syntax
$ ip OBJECT COMMAND
$ ip [options] OBJECT COMMAND
$ ip OBJECT help
$ ip [options] object command [parameters]

Before going into depth, you should understand the OBJECTS and purpose which will play major role on IP commands activity.
ip-command-example-objects-1

Show information about all network interfaces

Basically we should know about interface name and IP Address information to work on further with IP command. Simply fire below commands to get IP Address and associated network interfaces.

$ ip a
or
$ ip addr
or
$ ip address
or
$ ip addr show

1: lo:  mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc mq state UNKNOWN qlen 1000
    link/ether 00:50:56:8a:6e:84 brd ff:ff:ff:ff:ff:ff
    inet 10.20.0.14/24 brd 10.30.0.255 scope global eth0
    inet6 fe80::250:56ff:fe8a:6e84/64 scope link
       valid_lft forever preferred_lft forever

In my case network interface name eth0 and associated IP address 10.20.0.14.

Show information about IPv4 or IPv6

If you want to show only about IPv4 or IPv6 info, you can do by adding 4 or 6 follwed by ip command.

$ ip -4 addr
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
2: eth0:  mtu 1500 qdisc mq state UNKNOWN qlen 1000
    inet 10.20.0.14/24 brd 10.30.0.255 scope global eth0

$ ip -6 addr
1: lo:  mtu 16436
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qlen 1000
    inet6 fe80::250:56ff:fe8a:6e84/64 scope link
       valid_lft forever preferred_lft forever

Show information about particular network interfaces

Use the below commands to list particular interface details.

$ ip addr show eth0
or
$ ip addr list eth0
or
$ ip addr show dev eth0

2: eth0:  mtu 1500 qdisc mq state UNKNOWN qlen 1000
    link/ether 00:50:56:8a:6e:84 brd ff:ff:ff:ff:ff:ff
    inet 10.20.0.14/24 brd 10.30.0.255 scope global eth0
    inet6 fe80::250:56ff:fe8a:6e84/64 scope link
       valid_lft forever preferred_lft forever

Assign a IP Address to Interface

Use the following format to assign a IP address to particular interface. Replace your IP address.

$ sudo ip addr add 10.20.0.15/24 dev eth1

Remove the IP address from the interface

Use the following format to Remove the IP address from the interface. Replace your IP address.

$ sudo ip addr del 10.20.0.15/24 dev eth1

Enable the Network Interface

Use the following format to enable the Network Interface. In my case i’m going to enable eth1

$ sudo ip link set dev eth1 up

Down the Network Interface

Use the following format to down the Network Interface. In my case i’m going to down eth1

$ sudo ip link set dev eth1 down

Print Routing Table

Add route object with ip command to see the route packets. Run the following command to check the routing table information of the system.

$ip r
or
$ ip route
or
$ ip route show
or
$ ip route list

default via 10.20.0.1 dev eth0
10.20.0.0/24 dev eth0  proto kernel  scope link  src 10.20.0.14

Delete a Default route

Use the following command to delete default gateway.

$ sudo ip route del default

Change the Default route

Use the following command to chnage the default route.

$ sudo ip route add default via 192.168.1.100

Add a new route

Use the following command to add a new route, which will transfer the traffic from default route to new.

$ sudo ip route add 10.20.0.0/24 via 192.168.1.100 dev eth1

Show Network Statistics

IP command is not limited to do IP manipulation, also shows network statistics, Use the following command to check network statistics.

$ ip -s link

Show specific Network interface Statistics

Add the desired network interface name to Show specific Network interface Statistics.

$ ip -s link ls eth0

You may also like...