Using the ip command

The ip command is a handy tool that can replace much of ifconfig and route. Unfortunately, the man page lacks examples, and so this page is an effort to rectify that. I'm only going to cover some of the basic uses of the command, doing what I used to do with ifconfig.

As far as I know, the ip command is Linux only. I know that it's not in FreeBSD.

To give an interface an address with netmask, ip uses what is sometimes called slash notation. Instead of ifconfig's netmask it will use For networks with the common subnet of we use /24. For networks with a netmask of we use /16. For networks using the mask we use /8. If your network uses something else, the chances are that you know how to figure out the slash notation. I'm not going to go into it here, though I have another page on subnetting. You count the number of 1's in the netmask, after putting it into binary. That's covered on the other page.

So if we have a typical home network address, it might have a router that has an address of That's the gateway. We'll give the interface an address of The syntax would be
ip addr add dev eth0

Hopefully, this is clear. addr is address, add is add. dev is the device, in this case eth0.

The equivalent of route add -net netmask eth0 would be
ip route add dev eth0

Then, add a gateway. (As if typing route add default gw
ip route add default via

To see your IP address, rather than typing ifconfig you use
ip addr show dev eth0

If you leave out the dev eth0 it will show the IP information for all interfaces.

To bring an interface up
ip link set eth0 up

That's it for now. The ip command has many different abilities, detailed in the man page. I'll add other examples as I run into them. In RH based systems, at least, there are also some .ps (postscript) documents giving more details and examples. These are located in /usr/share/doc/iproute-<version_number> on RedHat based systems. As they are in postscript format, they have to be read with evince, gv, or another document viewer capable of viewing ps.

This is a pretty good cheatsheet.