Useful IP Commands

In recent Linux distributions, traditional route and ifconfig commands are deprecated and mostly cannot be found. They are replaced by a very neat tool “ip”.

Show, Set or Delete IP Addresses:

Instead of ifconfig you can use the following ip command:

# ip addr show

The output would be something like this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: ...

You can assign an IP address to the previously shown interface using ip command :

# ip addr add dev eth0

Now you must change the interface status to up by :

# ip link set eth0 up

You might want to add your recently assigned IP address afterwards:

# ip addr del dev eth0

Show, Set or Delete Routes:

Similarly, instead of ancient route command you can use ip as follows:

# ip route show

The result would something like this:

default via dev eth0 proto static metric 100 dev eth0 proto kernel scope link src metric 100

In order to add a static route, you can use the following command:

# ip route add via dev eth0

Or somehow, you might want to delete the route you just added:

# ip route del

Set Default Route:

In the past, we used to issue the command route add default gw, but the ip-way is as follows:

# ip route add default via

Good Luck! Reference: TechMint