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

Leave a Reply

Your email address will not be published.