The ip Command – A Replacement for ifconfig

The Linuxipcommand andifconfigare similar, but ip is more powerful and designed to replace ifconfig. With ip, you can easily perform network management tasks. ifconfig is deprecated from net-tools, unmaintained for years. The iproute2 suite provides enhanced commands, with ip being one of them.

Net tools vs Iproute2

To install ip,click heredownloadthe iproute2 suite . However, most Linux distributions come with iproute2 pre-installed.

You can also download the latest source with git:


  1. $ git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/iproute2.git

iproute2 git clone

Set and Delete IP Addresses

To set an IP address, use this command:


  1. $ sudo ip addr add 192.168.0.193/24 dev wlan0

Note the IP has a suffix like /24 (CIDR notation). In this example, the subnet mask is 255.255.255.0.

After setting the IP, verify it has taken effect:


  1. $ ip addr show wlan0

set ip address

Delete an IP by using del instead of add:


  1. $ sudo ip addr del 192.168.0.193/24 dev wlan0

delete ip address

List Routing Table Entries

The ip route object helps you view and set routing data. The first entry is the default route.

This example shows multiple routes across different interfaces including WiFi, Ethernet, and a point-to-point connection.


  1. $ ip route show

ip route show

To find which route a packet takes from an IP, use:


  1. $ ip route get 10.42.0.47

ip route get

Change Default Route

To change the default route:


  1. $ sudo ip route add default via 192.168.0.196

default route

Show Network Statistics

Display statistics for different network interfaces:

ip statistics all interfaces

To get info on a specific interface, add thelsoption. Using multiple-sgives more detailed info, useful for troubleshooting.


  1. $ ip s s link ls p2p1

ip link statistics

ARP Entries

ARP converts IP addresses to MAC addresses. Use ip neigh or ip neighbour to view devices on your LAN.


  1. $ ip neighbour

ip neighbour

Monitor netlink Messages

The monitor option lets you view network device status, classifying devices as REACHABLE or STALE:


  1. $ ip monitor all

ip monitor all

Activate and Deactivate Network Interfaces

Use ip link set dev up/down to activate/deactivate an interface, similar to ifconfig.

This example shows routing table entries when ppp0 is activated, stopped, and reactivated.


  1. $ sudo ip link set ppp0 down
  2.  
  3. $ sudo ip link set ppp0 up

ip link set up and down

Get Help

When stuck on a specific option, use help. The man page lacks usage examples, so help is your friend.

For example, to learn more about route:


  1. $ ip route help

ip route help

Summary

For network admins and Linux users, the ip command is essential. It is time to abandon ifconfig, especially when writing scripts.


via: http://linoxide.com/linux-command/use-ip-command-linux/

Leave a Comment

Your email address will not be published.