

ifconfig vs ip usage guide on Linux
source link: https://computingforgeeks.com/ifconfig-vs-ip-usage-guide-on-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:
Setting Static IP Address on Ubuntu
Setting Static IP Address on CentOS
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:
How To Create and Configure Bridge Networking For KVM in Linux
Recommend
-
29
导读 Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者。使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务。ifconfig是net-tools中已被废弃使用的一个命令,许多年前就已经没有维...
-
41
作者简介: 大家好,我叫张昺华,中间那个字和“饼”字一个读音。 2014年我毕业于广东省惠州学院,我从小酷爱理科,当看到陈莉君老师在《Linux内核之旅》上发的学生在课堂上用课本剧的方式来诠释技术时,想到了自己初中的时候老...
-
10
Linux maintains bugs: The real reason ifconfig on Linux is deprecated
-
7
ifconfig(interface configuration)是一种网络管理工具。它用于在 Linux 操作系统中配置和查看网络接口的状态。使用ifconfig,您可以分配 IP 地址、启用或禁用网络接口、管理ARP 缓存、路由等。在本文中,我们将探讨如何使...
-
11
How To Install Ifconfig on RHEL 8Do you get 'Ifconfig' Command Not Found in your RHEL 8 / CentOS 8 minimal server installation?. The minimal installation of RHEL 8 / CentOS 8 doesn’t come with the ifconfig comman...
-
13
How To Install ifconfig on Ubuntu 20.04 (Focal Fossa)I discovered that Ubuntu 20.04 (Focal Fossa) Server edition doesn’t have ifconfig command pre-installed. How then can you install ifconfig on Ubuntu 20.04 (Focal Fossa)?. if you get a messa...
-
7
How to Fix the "ifconfig: command not found" Error in Linux By Debarshi Das Published 10 hours ago If you encounter the co...
-
6
迷途小书童的Note ifconfig 命令用于查看和配置网络参数。使用 ifconfig 命令配置...
-
6
【踩坑】安装ifconfig命令 2023-02-07 ...
-
13
Linux 中如何启用和禁用网卡?|ifconfig|ifdown/up|ip|nmcli|nmtui|NetworkManager VPS小白 >
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK