Home Learn Linux How to use ifconfig command in Linux

How to use ifconfig command in Linux

The ifconfig command in Linux is a powerful tool for network interface configuration and management. This guide provides an in-depth look at ifconfig, including how to use it to set IP addresses, enable/disable interfaces, and troubleshoot network issues, complete with practical examples.

by John Horan
ifconfig command linux

In the dive­rse world of Linux networking tools, the “ifconfig” command stands out as a classic and re­liable tool, despite more­ comprehensive alte­rnatives like the “ip” command gaining popularity. Many use­rs continue using ifconfig due to its simplicity and ease­ of use. This guide will revisit the­ essential functions of ifconfig, as well as provide­ a cheat sheet, comparisons, and usage­ scenarios.

Whether trouble­shooting network configurations or wanting to view a system’s ne­tworking setup, ifconfig remains a reliable­ and familiar tool in the Linux community. By exploring its capabilities, we­ can appreciate its legacy while­ also gaining practical knowledge in managing network comple­xities. This guide will provide both nostalgia and practical e­xpertise using ifconfig.

ifconfig command in Linux

ifconfig, short for “interface configuration,” is a traditional command-line utility in Unix-like operating systems that allows users to configure, manage, and query network interface parameters from the command line. While it’s been somewhat overshadowed by the more modern ip command, ifconfig remains a popular and beloved tool for 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’s a typical example from a Ubuntu terminal:

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet netmask broadcast
        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<UP,LOOPBACK,RUNNING> mtu 65536
        inet netmask
        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 the eth0 interface, which is a typical Ethernet connection, and the lo interface, which is the loopback interface.

Configuring network interfaces

One of the primary uses of ifconfig is to configure network interfaces. Let’s say 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 netmask

This command sets the IP address of eth0 to and the netmask to Remember, you’ll need superuser privileges to make changes to network configurations, hence the sudo.

Enabling and disabling network interfaces

To disable an interface, you can run:

$ sudo ifconfig eth0 down

And to bring it back up:

$ sudo ifconfig eth0 up

Simple, right? That’s what I love about ifconfig. It doesn’t require memorizing complex syntax for performing basic network operations.

Checking the MAC address

Finding the MAC address of your network interface is as simple as running ifconfig without any options. The MAC address is displayed as part of the standard output, listed under ether. Here’s the snippet from the previous example:

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

Advanced configuration: Adding and removing aliases

A lesser-known feature of ifconfig is its ability to manage multiple IP addresses on a single network interface through the use of aliases. This can be particularly useful for hosting multiple services on a single server. Here’s how you can add an IP address as an alias to an existing interface (eth0, in this instance):

$ sudo ifconfig eth0:0 netmask
This command assigns the IP address to the alias eth0:0. To remove this alias, simply bring it down:

$ sudo ifconfig eth0:0 down

Monitoring network traffic

While 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 transmitted and received packets, errors, and more.

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

Troubleshooting network issues

ifconfig is pretty much your go-to buddy when it comes to sorting out network hiccups. Think you’ve got an issue with your network link? ifconfig lets you peek at your network interfaces’ status to see what’s up. Noticed an interface that’s taking an unexpected nap? A quick nudge with ifconfig can wake it right up. And if you’re tangled in some network configuration snarls, ifconfig is your handy toolkit for tweaking those settings back into shape.

Pro tip: Mash up ifconfig with buddies like ping or traceroute, and you’ve got yourself a powerful combo to track down and nail those pesky network gremlins.

The move towards ip

So, ifconfig has been riding into the sunset for a while now, with the Linux crowd leaning more towards the ip command. Why? Simply put, ip brings a lot more to the table, meshing better with the Linux Networking Stack and offering a beefier set of tools for managing the network’s ins and outs.

But, hey, change isn’t always a walk in the park. Moving from the comfort zone of ifconfig to the vast landscapes of ip can feel like learning to bike all over again, thanks to its intricate syntax. For those of us who’ve spent years in a committed relationship with ifconfig, it’s not just a tool; it’s an old friend. Yet, embracing ip opens up a whole new world of network management prowess—think of it as upgrading to a high-performance bike. Yes, there’s a bit of a learning curve, but the places you’ll go and the speed you’ll get there? Totally worth the effort.

ifconfig command cheat sheet

This cheat sheet covers a variety of basic ifconfig commands for managing network interfaces on Linux systems.

Command Explanation
ifconfig Display all active interfaces with their current configuration.
ifconfig -a Display all interfaces, including those that are down.
sudo ifconfig eth0 up Enable (bring up) the interface eth0.
sudo ifconfig eth0 down Disable (bring down) the interface eth0.
sudo ifconfig eth0 netmask Assign IP address and netmask to eth0.
sudo ifconfig eth0:0 netmask Add an alias with a new IP address to eth0.
sudo ifconfig eth0 mtu 1500 Change the MTU (Maximum Transmission Unit) for eth0.
ifconfig eth0 promisc Enable promiscuous mode on eth0, allowing it to receive all packets on the network.
sudo ifconfig eth0 -promisc Disable promiscuous mode on eth0.
ifconfig eth0 txqueuelen 1000 Set the transmit queue length for eth0.

Let’s walk through a real-world example where ifconfig can be extremely useful: changing the IP address of a network interface on a Ubuntu server to configure a static IP, and then verifying the change.

Practical example – setting up local server

Imagine you’re setting up a local web server that requires a static IP address to ensure it’s consistently accessible at the same address. We’ll use ifconfig to assign a static IP address to the eth0 network interface.

Step 1: Check current network interface configuration

First, let’s check the current configuration of our network interfaces.

$ ifconfig

You might see output similar to this for eth0:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        ether 02:01:02:03:04:05  txqueuelen 1000  (Ethernet)
        RX packets 368598  bytes 314159265  (314.1 MB)
        TX packets 123456  bytes 654321  (654.3 KB)

Step 2: Assign a static IP address

Assuming you’ve agreed on using as the static IP for the server, and the network mask is, the command would be:

$ sudo ifconfig eth0 netmask

Step 3: Verify the new configuration

To ensure the IP address has been successfully assigned, run ifconfig again:

$ ifconfig eth0

Look for the inet line, which should now reflect the new IP address:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        ether 02:01:02:03:04:05  txqueuelen 1000  (Ethernet)

Step 4: Testing the configuration

Finally, it’s a good practice to test the new configuration. You can ping the gateway of your network (usually the router’s IP, say to ensure connectivity:

$ ping -c 4

If the ping is successful, your server is correctly configured with its new static IP and can communicate with other devices on the network.

Final thoughts

Wrapping up our article with ifconfig, it’s clear this old-timer has still got it. Its mix of no-fuss functionality and handy-dandy utility means it’s hanging in there, even as the shiny new ip command struts its stuff. Our deep dive—from the ABCs to a nifty cheat sheet—has painted ifconfig as the trusty command for going through network setups and solving issues on the fly.

You may also like

Leave a Comment



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us


©2016-2023 FOSS LINUX



“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.