How to use ifconfig command in Linux

This guide will review the essential functions of ifconfig, as well as provide a summary, comparison, and usage scenarios.

In the diverse world of Linux networking tools, the 'ifconfig' command stands out as a classic and reliable tool, although more comprehensive alternatives such as the 'ip' command are gaining popularity. Many users continue to use ifconfig due to its simplicity and ease of use. This guide will review the essential functions of ifconfig, as well as provide summaries, comparisons, and usage scenarios.

Whether troubleshooting network configuration issues or wanting to view your system's network settings, ifconfig remains a trusted and familiar tool in the Linux community. By exploring its capabilities, we can make an accurate assessment of this command while gaining practical knowledge in managing network complexity.

ifconfig command in Linux

ifconfig, short for 'interface configuration', is a traditional command line utility in Unix-like operating systems, allowing users to configure, manage and query network interface parameters from the command line. Although it has been overshadowed by the more modern ip command, ifconfig remains a popular tool and is loved by many due to its simplicity and ease of use.

Basic usage

At its core, ifconfig can be used without any options to display the current network configuration for all active interfaces. Here is a typical example from the Ubuntu terminal:

$ ifconfig eth0: flags=4163  mtu 1500 inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:1b:fc:2a:bc:12 txqueuelen 1000 (Ethernet) RX packets 1023 bytes 811234 (811.2 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 829 bytes 123456 (123.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73  mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 160 bytes 17680 (17.6 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 160 bytes 17680 (17.6 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 

In this output, you can see details about interface eth0, which is a regular Ethernet connection, and interface lo, which is a loopback interface.

Configure network interface

One of the main uses of ifconfig is network interface configuration. Suppose you want to assign a static IP address to an interface (eth0, in this case). You would use a command like this:

$ sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0

This command sets eth0's IP address to 192.168.1.10 and netmask to 255.255.255.0. Remember, you will need superuser privileges to make changes to the network configuration, hence the need for sudo.

Enable and disable network interfaces

To disable an interface, you can run:

$ sudo ifconfig eth0 down

And to bring it back:

$ sudo ifconfig eth0 up

Simple, right? That's what many people love about ifconfig. Does not require memorizing complex syntax to perform basic network operations.

Check MAC address

Finding the MAC address of a network interface is as simple as running ifconfig without any options. MAC addresses are displayed as part of the standard output, listed as ether. Here is an excerpt from the previous example:

ether 00:1b:fc:2a:bc:12 txqueuelen 1000 (Ethernet)

Advanced configuration: Add and remove alias

A little-known feature of ifconfig is the ability to manage multiple IP addresses on a network interface through the use of aliases. This can be especially useful when hosting multiple services on one server. Here's how to add an IP address as an alias to an existing interface (in this case eth0):

$ sudo ifconfig eth0:0 192.168.1.11 netmask 255.255.255.0

This command assigns the IP address 192.168.1.11 to alias eth0:0. To remove this alias, simply execute the following command:

$ sudo ifconfig eth0:0 down

Monitor network traffic

Although ifconfig is primarily known for configuring network interfaces, it also provides some basic statistics that can be useful for monitoring network traffic. As shown in the basic usage example, ifconfig displays information about the number of packets transmitted and received, errors, etc.

To get a more detailed view, you can continuously monitor these statistics and observe changes over time. However, for in-depth traffic analysis, tools like iftop or ip -s link are more suitable.

Troubleshoot network problems

ifconfig is almost your companion when it comes to solving network problems. Do you think your network connection has a problem? ifconfig allows you to view the status of your network interface to see what is happening. Noticed an interface falling asleep unexpectedly? ifconfig can wake it up immediately. And if you're having trouble with some network configuration issues, ifconfig is a useful toolkit to get those settings back to normal.

The ifconfig command's combination of simple functionality and convenience means it still holds its own, even though the new ip command has many advantages. This is a reliable command to make network settings and solve problems quickly.

Update 21 April 2024
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile