Start using the modern method for configuring a Linux network interface.
![Tips and gears turning][1]
For a long time, the `ifconfig` command was the default method for configuring a network interface. It served Linux users well, but networking is complex, and the commands to configure it must be robust. The `ip` command is the new default networking command for modern systems, and in this article, I'll show youhow to use it.
The `ip` command is functionally organized on two layers of the [OSI networking stack][2]: Layer 2 (data link layer) and Layer 3 (network or IP layer). It does all the work in the old `net-tools` package.
### Installing ip
The `ip` command is included in the `iproute2util` package. It's probably already included in your Linux distribution. If it's not, you can install it from your distro's software repository.
### Comparing ipconfig and ip usage
The `ip` and `ipconfic` commands can be used to configure a network interface, but they do things differently. I'll compare how to do common tasks withthe old (`ipconfig`) and new (`ip`) commands.
#### View network interface and IP address
If you want to see the IP address of a host or view network interface information, the old`ifconfig` command, with no arguments, provides a good summary:
inet 10.1.1.6/27 brd 10.1.1.31 scope global dynamic wlan0
valid_lft 83490sec preferred_lft 83490sec
inet6 fdb4:f58e:49f:4900:d46d:146b:b16:7212/64 scope global noprefixroute dynamic
valid_lft 6909sec preferred_lft 3309sec
inet6 fe80::8eb3:4bc0:7cbb:59e8/64 scope link
valid_lft forever preferred_lft forever
```
#### Add IP address
To add an IP address to an interface with `ifconfig`, the command is:
```
`$ ifconfig eth0 add 192.9.203.21`
```
The command is similar for `ip`:
```
`$ ip address add 192.9.203.21 dev eth0`
```
Subcommands in `ip` can be shortened, so this command is equally valid:
```
`$ ip addr add 192.9.203.21 dev eth0`
```
You can make it even shorter:
```
`$ ip a add 192.9.203.21 dev eth0`
```
#### Remove an IP address
The inverse of adding an IP address is to remove one.
With `ifconfig`, the syntax is:
```
`$ ifconfig eth0 del 192.9.203.21`
```
The `ip` commandsyntax is:
```
`$ ip a del 192.9.203.21 dev eth0`
```
#### Enable or disable multicast
Enabling (or disabling) [multicast][3] on an interface with `ifconfig` happens with the `multicast` argument:
```
`# ifconfig eth0 multicast`
```
With `ip`,use the `set` subcommand with the device (`dev`) and a Boolean or toggle `multicast` option:
```
`# ip link set dev eth0 multicast on`
```
#### Enable or disable a network
Every sysadmin is familiar with the old "turn it off and then on again" trick to fix a problem. In terms of networking interfaces, that translates to bringing a network up or down.
The `ifconfig` command does this with the `up` or `down` keywords:
```
`# ifconfig eth0 up`
```
Or you could use a dedicated command:
```
`# ifup eth0`
```
The `ip` command uses the `set` subcommand to set the interface to an `up` or `down` state:
```
`# ip link set eth0 up`
```
#### Enable or disable the Address Resolution Protocol (ARP)
With `ifconfig`, you enable ARP by declaring it:
```
`# ifconfig eth0 arp`
```
With `ip`, you _set_ the `arp` property as `on` or `off`:
```
`# ip link set dev eth0 arp on`
```
### Pros and cons of ip and ipconfig
The `ip` command is more versatile and technically more efficient than `ifconfig` because it uses `Netlink` sockets rather than `ioctl` system calls.
The `ip` command may appear more verbose and more complex than `ifconfig`, but that's one reason it's more versatile. Once you start using it, you'll get a feel for its internal logic (for instance, using `set` instead of a seemingly arbitrary mix of declarations or settings).
Ultimately, `ifconfig` is outdated (for instance, it lacks full support for network namespaces), and `ip` is designed for the modern network. Try it out, learn it, use it. You'll be glad you did!