Network configuration in Linux: ifconfig (net-tools) vs ip (iproute2)

In Linux ifconfig is a part of the net-tools package which is deprecated and replaced by iproute2 while in BSD Unix ifconfig is in active development. This tutorial is a brief introduction to the ip command versus the replaced commands. iproute2 is in active development, supports the most modern network technologies including traffic shaping and tunneling, it’s a powerful tool, let’s see how it works.

Overview of examples
Legacy Replacement
net-tools other iproute2 other
ifconfig ip -s link, ip -s address
route ip route
arp ip neigh
nameif ip link
ipmaddr ip maddress
iptunnel ip tunnel
netstat ss, nstat
mii-tool ethtool
plipconfig
slattach
vconfig ip link
examples, not covered in the tutorial

Print help

ifconfig -h
ip

Display all interfaces

ifconfig -a
ip -s addr

Display single interface

ifconfig eth0
ip addr show dev eth0

Shutdown and activate interface

ifconfig eth0 down
ifconfig eth0 up
ip link set dev eth0 down
ip link set dev eth0 up

Display ARP cache

arp -n
ip neigh

Change MAC address

ifconfig eth0 hw ether 00:00:00:00:00:01
ip link set dev eth0 address 00:00:00:00:00:01

Rename interface eth0 (00:00:00:00:00:01) to eth1

ifconfig eth0 down
nameif eth1 00:00:00:00:00:01
ifconfig eth1 up
ip link set dev eth0 down
ip link set dev eth0 name eth1
ip link set dev eth1 up

Create an alias in net-tools vs add IP address in iproute2 with label

ifconfig eth0:0 192.168.0.254 netmask 255.255.255.0
ip addr add 192.168.0.254/24 dev eth0 label eth0:0

Delete an alias in net-tools vs delete IP address in iproute2

ifconfig eth0:0 down
ip addr del 192.168.0.254/24 dev eth0

Change IP address, in iproute2 you need to delete the old and add the new IP address

ifconfig eth0 192.168.0.253 netmask 255.255.255.0
ip addr del 192.168.0.254/24 dev eth0
ip addr add 192.168.0.253/24 dev eth0

Remove IP address

ifconfig eth0 0.0.0.0
ip addr del 192.168.0.254/24 dev eth0

Display routing table

route -n
ip route

Set default gateway

route add default gw 192.168.0.1
ip route add default via 192.168.0.1

Delete default gateway

route del default gw 192.168.0.1
ip route del default via 192.168.0.1

Add static route

route add -net 192.168.150.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth1
ip route add 192.168.150.0/24 via 192.168.0.1 dev eth1

Remove static route

route del -net 192.168.150.0 netmask 255.255.255.0
ip route del 192.168.150.0/24

Create VLAN interface

vconfig add eth0 10
ip link add eth0.10 link eth0 type vlan id 10

Remove VLAN interface

vconfig rem eth0.10
ip link del dev eth0.10

Change the MTU (Maximum Transfer Unit)

ifconfig eth0 mtu 1500
ip link set dev eth0 mtu 1500

Enable and disable ARP protocol

ifconfig eth0 arp
ifconfig eth0 -arp
ip link set dev eth0 arp on
ip link set dev eth0 arp off

Enable and disable promiscuous mode. If enabled all packets on the network will be received by the interface.

ifconfig eth0 promisc
ifconfig eth0 -promisc
ip link set dev eth0 promisc on
ip link set dev eth0 promisc off

Enable and disable multicast

ifconfig eth0 multicast
ifconfig eth0 -multicast
ip link set dev eth0 multicast on
ip link set dev eth0 multicast off

Enable and disable all-multicast mode. If enabled, all multicast packets on the network will be received by the interface.

ifconfig eth0 allmulti
ifconfig eth0 -allmulti
ip link set dev eth0 allmulticast on
ip link set dev eth0 allmulticast off

Restore classic network interface naming scheme (eth0, eth1.. ethx) in Linux

Starting with systemd/udev v197, predictable network interface naming is enabled by default and it’s recommended. The names of the network interfaces are incorporating the physical location of the hardware. Example of predictable interface name is enp0s3, where enp stands for Ethernet Network Peripheral, 0 is the #bus_id and 3 is the #device_id.

lspci | grep -i eth
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)

This new naming scheme is harder to read but is more stable ( read more ). If you want to name your network devices the old-fashioned way, you need to create new udev rules with higher priority or disable predictable naming scheme.

Tested on Debian 9.2 and CentOS 7.3

Method 1 – New udev rules

Create /etc/udev/rules.d/10-persistent-net.rules with your favorite text editor, add the network devices by their MAC addresses and reboot the system.

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:01", NAME="eth0"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:02", NAME="eth1"

Method 2 – Disable predictable naming scheme

1. Edit /etc/default/grub and add net.ifnames=0 to GRUB_CMDLINE_LINUX=””.

Example:

GRUB_CMDLINE_LINUX="quiet net.ifnames=0"

2. Update the GRUB configuration file.

a.) Debian

grub-mkconfig -o /boot/grub/grub.cfg

b.) CentOS

grub2-mkconfig -o /boot/grub2/grub.cfg

3. Reboot