ifconfig vs ip

The command /bin/ip has been around for some time now. But people continue using the older command /sbin/ifconfig. Let's be clear: ifconfig will not go away any time soon, but its newer version, ip, is more powerful and will eventually replace it.

The man page of ip may look intimidating at first, but once you get familiar with the command syntax, it is an easy read. This page will not introduce the new features of ip. It rather compares the ifconfig and ip commands to get a quick understanding of the command syntax.

Show network devices and configuration

ifconfig
ip addr show
ip link show

Enable a network interface

ifconfig eth0 up
ip link set eth0 up

A network interface is disabled in a similar way:

ifconfig eth0 down
ip link set eth0 down

Set IP address

ifconfig eth0 192.168.0.77
ip address add 192.168.0.77 dev eth0

This was the simple version of the command. Often, also the network mask or the broadcast address need to be specified. The following examples show the ifconfig and ip variants.

Needless to say that the netmask can also be given in CIDR notation, e.g. as 192.168.0.77/24.

ifconfig eth0 192.168.0.77 netmask 255.255.255.0 broadcast 192.168.0.255
ip addr add 192.168.0.77/24 broadcast 192.168.0.255 dev eth0

Delete an IP address

With ip it is also possible to delete an address:

ip addr del 192.168.0.77/24 dev eth0

Add alias interface

ifconfig eth0:1 10.0.0.1/8
ip addr add 10.0.0.1/8 dev eth0 label eth0:1

ARP protocol

Add an entry in your ARP table.

arp -i eth0 -s 192.168.0.1 00:11:22:33:44:55
ip neigh add 192.168.0.1 lladdr 00:11:22:33:44:55 nud permanent dev eth0

Switch ARP resolution off on one device

ifconfig -arp eth0
ip link set dev eth0 arp off

Show the routing table

route
ip route show

A nice feature of the ip route is that one can query which interface (and gateway) a packet to a given IP address would be routed to.

ip route get 192.168.88.77

Changing the routing table

The commands to add a route on an interface are very similar:

route add -net 192.168.3.0/24 dev eth3
ip route add 192.168.3.0/24 dev eth3

The same applies to removing entries from a routing table:

route del -net 192.168.3.0/24 dev eth3
ip route del 192.168.3.0/24 dev eth3

For completeness, the command to add a gateway:

route add -net 192.168.4.0/24 gw 192.168.4.1
ip route add 192.168.4.0/24 via 192.168.4.1

This can also be combined with a dev eth3 interface.

Add a VLAN interface

The command to add a VLAN is slightly longer than the equivalent using the legacy vconfig tool, but does not require installing an additional tool.

vconfig add eth3 42
ip link add link eth3 name eth3.42 type vlan id 42

Updates

25 February 2020
Add an example how to create a VLAN interface.
12 December 2016
Added more ip route commands. Thanks to Will van Gulik.
27 June 2016
Added ip route command.
11 June 2013
Fixed a mismatch in a IP address and its netmask. Thanks to Jeffrey Ross.
19 December 2010
Added ip addr del command.
19 June 2010
Added arp command.