How to use ifconfig command in Linux

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.

4 ★ | 2 Vote

May be interested

  • Instructions for using zforce command on LinuxInstructions for using zforce command on Linux
    the gzip command is a popular tool used to compress / decompress files in linux. tipsmake.com presents the basics of this tool in the article: some basic terminal commands in linux mint 11.
  • How to limit access to su command in LinuxHow to limit access to su command in Linux
    if you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
  • 12 things Linux is easier to do in the command line than graphical software12 things Linux is easier to do in the command line than graphical software
    graphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
  • 11 df commands in Linux (with example)11 df commands in Linux (with example)
    with the df command in linux, you can easily check your system for details about disk space and file size. these 12 examples of df commands will show you how to do them in detail.
  • How to use the Linux command line on Android with TermuxHow to use the Linux command line on Android with Termux
    android is a very operating system 'capacity with more and more desktop accessibility applications. however, sometimes you want to make some things on android that can be as easy as desktop. fortunately, you can use the termux tool, which builds on the existing infrastructure and provides a command line environment that allows you to install real linux applications on your android device.
  • Instructions for using find command in LinuxInstructions for using find command in Linux
    the find command is one of the most important and handy commands on a linux system. as its name suggests, the command can find files on a linux pc based on a variety of conditions and variables you set.
  • How to use the history command in LinuxHow to use the history command in Linux
    as you spend more and more time in terminal sessions, you will constantly find new commands that make everyday tasks more efficient. the gnu history command is one of them.
  • Instructions for using pstree command on LinuxInstructions for using pstree command on Linux
    pstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
  • The dd command in Linux, How to use the dd commandThe dd command in Linux, How to use the dd command
    dd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
  • Use the Top command to see the processes running in LinuxUse the Top command to see the processes running in Linux
    the top command in linux is used to display all processes running in the linux environment. this tutorial shows you how to use the top command through explaining the various parameters available and the content they display.