Welcome to ifconfig vs ip usage guide on Linux. ifconfig and ip commands are mostly useful when managing networking on Linux/Unix systems. The ip command has been there for a while now but most people still stick to ifconfig for daily network configurations and troubleshooting on Linux. In this article, I’ll try to give you the basics you need to master ip command and show a comparison between the two.
In a nutshell, ip tool should be the replacement of ifconfig since ifconfig is considered deprecated and no active development on it is going on.On recent Linux systems, the ifconfig command is missing and can be installed from net-tools package. Installation on various OS is as below.
Installing ifconfig on Arch
On Arch Linux, the ifconfig tool is provided by the net-tools package which can be installed using the commands below.
$ sudo pacman -S net-tools $ sudo pacman -Qi net-tools Name : net-tools Version : 1.60.20160710git-1 Description : Configuration tools for Linux networking Architecture : x86_64 URL : http://net-tools.sourceforge.net/ Licenses : GPL2 .....
To confirm that the tool is installed, just issue the command ifconfig on the terminal.
Installing ifconfig on Ubuntu
If your version of Ubuntu is missing the ifconfig command, you can install it by:
sudo apt-get install net-tools
Installing ifconfig on Fedora / CentOS
### CentOS ###
sudo yum install net-tools
### Fedora ###
sudo dnf install net-tools
For ip command, if missing for any reason, you can install it as well.
Install ip command on Ubuntu
ip command on Ubuntu is provided by iproute2 package installable from apt-get.
sudo apt-get install iproute2
Install ip command on CentOS / Fedora
The package that provides ip command is iproute, which can be installed or updated using yum/dnf
sudo yum -y install iproute
Comparison of ip and ifconfig commands
For this comparison, we’ll use a number of examples to demonstrate how things are done with ip command and similar commands used with ifconfig. Since both commands are available on all Linux distributions, you can stick with what you’re comfortable with. If you’ve been an ifconfig user for a long time now, this guide will introduce you to commands enough to get you started with ip tool.
In all examples, any command with prefix ifconfig is specific to the ifconfig tool and any command starting with ip is specific to the ip network management tool. So keep this in mind as you proceed.
Display network interfaces and ip address information
To get all IP address related information using ip/ifconfig, these commands are used.
$ ifconfig
$ ip addr
Take down/up network interface:
If you would like to take down or bring up an interface, this is often done when modifying network configurations, you can use below commands. The interface eth0 can be replaced with any other interface name.
sudo ifconfig eth0 {up|down}
sudo ip link set dev eth0 {up|down}
Set a static IP and netmask:
Static IP setting can be done using ip or ifconfig. But note that changes made with these commands are not persistent against reboots. Explore setting static ip using the nmcli tool or by modifying network configuration file on your distribution for permanent changes. Some guides available on this blog are:
Example:
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
sudo ip addr add 192.168.1.10/34 dev eth0
Remove static IP address:
To clear ip address information for an interface commands syntax is as below for both tools:
sudo ifconfig eth0 del 192.168.1.10
sudo ip addr del 192.168.1.10/24 dev eth0
Set network MTU
MTU is an abbreviation for maximum transmission unit. In networking, this is the size of the largest network layer protocol data unit that can be communicated in a single network transaction. In this example, mtu size of 1500 bytes is set. Larger MTU values is common for storage servers/systems.
sudo ifconfig eth0 mtu 1500
sudo ip link set dev eth0 mtu 1500
Enable Promiscuous Mode
Promiscuous mode is a mode of operation in networking whereby every data packet transmitted can be received and read by a network adapter. This is often used to monitor network activity.
sudo ifconfig eth0 promisc
sudo ip link set dev eth0 promisc on
Enable ARP
The Address Resolution Protocol is a communication protocol used for discovering the link layer address associated with a given IPv4 address, a critical function in Internet Protocol computer networks. To enable it to run the commands:
sudo ifconfig eth0 arp
sudo ip link set dev eth0 arp on
Set MAC address
ip and ifconfig commands can do runtime change of MAC address. In this example, we’re setting MAC address to aa:bb:cc:dd:ee:ff. Note that each NIC has fixed mac address which cannot be changed, changing mac address is not recommended since it can cause issues on layer 2 network communication if any collision exists.
sudo ifconfig eth0 hw ether aa:bb:cc:dd:ee:ff
sudo ip link set dev eth0 address aa:bb:cc:dd:ee:ff
Add default route via gateway IP
A default route can be set using ip and ifconfig commands for destinations without static routes defined.
sudo route add default gw 192.168.1.1
sudo ip route add default via 192.168.1.1
Set Static route
Static route defines a destination to a specific network. In this example, we’re specifying that all packets destined for 192.168.3.0/24 network must go through 192.168.1.1 gateway. The network interface to the default gateway is eth0.
sudo route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1
sudo ip route add 192.168.3.0/24 via 192.168.1.1 dev eth0
A different guide to Setting up Static routes on Linux is available on this blog. Please read it to strengthen the knowledge already accumulated here.
View neighbors (using ARP and NDP):
To check ARP table, run:
$ ip neighbor show
Display the current default route.
$ ip route show | head -n 1
Remove default gw
If you no longer need the default gateway set and would like to change, you can delete currently set using:
$ ip route del default via 62.12.113.1 dev eth1
Conclusion
Hope this guide- ifconfig vs ip usage guide on Linux has been helpful in getting familiar with ip and ifconfig command line tools used to manage networking on Linux. If you’ve additional commands that could be beneficial and not listed in this tutorial, please post them in the comments section. I’ll be happy to update them here.
More guides: