Logo

Linux ifconfig Command Explained With 19 Examples

Try this guide with our instant dedicated server for as low as 40 Euros

Linux ifconfig Command

Configuring and managing network interfaces (the pathways that connect your computer to a network or the internet) is a critical aspect of keeping your infrastructure operational. 

And, when things go sideways, you need a tool that helps you manage and configure network interfaces and associated operations. 

For many years, Linux admins have used the ifconfig command. However, many Linux distributions have started using the newer IP configuration command that offer similar capabilities. Still, many users prefer ifconfig due to its simplicity and familiarity. 

This command may not have all the fancy features, but it gets the job done in a pretty straightforward way.

With ifconfig, you can easily carry out essential system administration activities like assigning an IP address to your network interface or checking its status. While it may not offer as many features for internet interface configuration or processing network addresses as the IP command, its simplicity, and ease of use make it a popular choice for many users.

In this article, we’ll describe the Linux ifconfig command and then go into the details of applying this utility in 19 scenarios to resolve common network issues. 

Table Of Contents

  1. The Syntax of the ifconfig in Linux
    1. Linux ifconfig Command Options
  2. Examples of ifconfig in Linux
    1. Use Case #1: Display Settings of Active Network Interfaces
    2. Use Case #2: Show the Summary of Working Network Connections
    3. Use Case #3: Show the Verbose Output
    4. Use Case #4: Display All Network Interface Settings
    5. Use Case #5: Find Details of a Specific Network Interface
    6. Use Case #6: Switch a Network Interface Off
    7. Use Case #7: Switch a Network Interface On
    8. Use Case #8: List the IP Addresses
    9. Use Case #9: Set an IP Address for a Network Interface
    10. Use Case #10: See Network Interface Masks
    11. Use Case #11: Set a Netmask to an Interface
    12. Use Case #12: See the Broadcast Address of Network Interfaces
    13. Use Case #13: Set a Different Broadcast IP for a Network Interface
    14. Use Case #14: Set Up Several Network Settings Using a Single Command
    15. Use Case #15: Configure an Interface’s MTU
    16. Use Case #16: Configure an Alias IP
    17. Use Case #17: Turn on Promiscuous Mode
    18. Use Case #18: Turn off Promiscuous Mode
    19. Use Case #19: Look at Transmission Errors
  3. Conclusion
  4. FAQs

The Syntax of the ifconfig in Linux

The basic syntax of ifconfig is as follows:

# ifconfig  [interface_name_optional]  [arguments_optional]

When you run the ifconfig command without arguments, it displays information about all active network interfaces on your system. If you specify an interface name, it shows details only for that particular interface.

However, when you include additional arguments along with the interface name, it might not display any output. This is because certain configurations or operations may not result in visible output, but they still affect the specified network interface.

Linux ifconfig Command Options

The ifconfig command is versatile, and you can use several flags and modifiers to achieve specific results. Here are some commonly used ones:

linux ifconfig common options

Examples of ifconfig in Linux

The ifconfig command is used to view and manage network interface configuration information. As a result, you can use the command to achieve a wide range of practical results.

Let’s run through several examples of applying the command to extract information and manage and troubleshoot network issues.

Use Case #1: Display Settings of Active Network Interfaces

Run ifconfig in the terminal without any additional parameters to see key details about all active network interfaces:

# ifconfig

ethernet network ip details

 

 

 

 

 

 

 

The result displays essential information about the network connections, such as:

  • Names of the active network interfaces, like “eno0” and “lo” (the loopback interface).
  • The hardware’s MAC names of the working network interfaces.[a]
  • The IP address (inet addr), netmask, and broadcast address.
  • The MTU (Maximum Transmission Unit) value.

Also Read: lsof Command in Linux with Examples

Use Case #2: Show the Summary of Working Network Connections

The ifconfig command without arguments, prints a rather detailed output about all active interfaces.

Add the -s flag to get a summary of each working network interface:

# ifconfig -s

network interface summary

 

Use Case #3: Show the Verbose Output

Use the verbose option (-v) with ifconfig to see a more detailed report of the network interfaces. Depending on your Linux distribution, the level of detail can be similar to or greater than the default ifconfig output.

ifconfig verbos

 

 

 

 

 

 

 

On our test system, ifconfig with the verbose option (-v) provides the same information as running the command without any arguments.

Use Case #4: Display All Network Interface Settings

If you use ifconfig without any options, you’ll only see the active network interfaces. To see information about active and inactive network interfaces, use the -a option:

# ifconfig -a

Display All Network Interface Settings

 

 

 

 

 

 

 

 

 

 

Our test system has no inactive networks so the result is the same as using the command without any arguments.

Use Case #5: Find Details of a Specific Network Interface

You can provide the interface’s name to the command to see details about a specific network interface:

ifconfig [interface_name]

For instance, you would run the following command to show the settings of the eno0 interface:

# ifconfig eno0

Find Details of a Specific Network Interface

Use Case #6: Switch a Network Interface Off

When active, a network interface sends and receives data.

If you wish to switch off a specific network interface, use the ifconfig command with the down option.

# ifconfig [interface_name] down

For example, run this command in your terminal to disable the eno0 interface:

# ifconfig eno0 down

The command doesn’t display a status, and you need to verify that the interface is indeed inactive. For this, run the ifconfig command with no arguments.

Use Case #7: Switch a Network Interface On

You can also use the ifconfig command to switch a network interface on. For this, use ifconfig with the up argument.

Here’s the command that switches eno0 interface on:

# ifconfig eno0 up

Check that the interface is operational by rerunning ifconfig.

# ifconfig

network card switch output

The result indicates that the network connection is currently active and functioning properly.

Use Case #8: List the IP Addresses

You can combine Ifconfig with grep to filter out the IP addresses for network interfaces on a device:

# ifconfig | grep inet

List with IP addresses

 

 

 

The output will show each line containing an IP address.

Use Case #9: Set an IP Address for a Network Interface

Use the ifconfig command followed by the name of the interface and the IP address you want to assign to set the IP address for the interface.

Here’s the syntax:

# ifconfig [interface_name] [IP_address]

Let’s see a basic example where we assign the IP address 10.0.2.12 to eno0: 

# ifconfig eno0 10.0.2.12

Set an IP Address for a Network Interface

You will not see any status about the success of the command. As such, we recommend running the ifconfig command to verify if the IP address has changed.

Use Case #10: See Network Interface Masks

Each network interface has an associated netmask, which divides IP addresses into categories commonly referred to as A, B, and C. Each category has a standard netmask. For instance:

  • Class A IP addresses use the 255.0.0.0 netmask. 
  • Class B networks use the 255.255.0.0 netmask. 
  • Class C networks use the 255.255.255.0 netmask.

Sometimes, an IP class doesn’t match its usual netmask.

To see the netmasks for active network connections, use grep to drill down to the essential information:

# ifconfig | grep netmask

get the netmast details

 

 

 

The result shows a list of IP addresses and their corresponding netmasks. Here, the netmask shown in the output is 255.0.0.0.

Use Case #11: Set a Netmask to an Interface

If you want to set a netmask for a network interface, choose the interface and use the netmask option.

# ifconfig [interface_name] netmask [netmask_IP]

For example, use the following command to set the netmask 255.255.255.0 for the interface eno0:

# ifconfig eno0 netmask 255.255.255.0

Check the results with ifconfig:

# ifconfig

ifconfig netmast check

 

 

 

 

 

The result will display that the netmask has been changed to 255.255.255.0.

Use Case #12: See the Broadcast Address of Network Interfaces

The broadcast setting is a unique address used to send messages to every device on a network. In most cases, the system sets it up by itself.

We recommend using the grep command to show the broadcast addresses of the network interfaces. The syntax of the command is as follows:

# ifconfig | grep broadcast

brodcast ip check

 

 

 

The output shows the broadcast address mentioned in the ifconfig output.

Use Case #13: Set a Different Broadcast IP for a Network Interface

To set a new broadcast IP, choose the network interface and use the broadcast option.

# ifconfig [interface_name] broadcast [broadcast_IP]

For instance, use the following command to set 10.0.2.251 as the new broadcast IP for the interface eno0:

# ifconfig eno0 broadcast 10.0.2.251

Check the changes using the command ifconfig, as there is no direct output to show the result.

Set a Different Broadcast IP for a Network Interface

Use Case #14: Set Up Several Network Settings Using a Single Command

You can change the IP address, netmask, and broadcast address for a network interface with the following command:

# ifconfig [interface_name] [IP] netmask [netmask_addresss] broadcast [broadcast_address]

For eno0, we’ll:

  • Set the netmask to 255.0.0.0.
  • Set the broadcast to 10.0.2.250.

# ifconfig eno0 84.16.226.173 netmask 255.0.0.0 broadcast 10.0.2.250

Verify the results using ifconfig:

# ifconfig

Several Network Settings Using a Single Command

Use Case #15: Configure an Interface’s MTU

The maximum transmission unit (MTU) restricts the size of packets that can be sent via an interface. Use the mtu argument with the ifconfig command to specify a value.

# ifconfig [interface_name] mtu [mtu_value]

For instance, use the following command to set the MTU for eno0 to 2000:

# ifconfig eno0 mtu 2000

Configure an Interface's MTU

Use Case #16: Configure an Alias IP

You can link one interface to many IP addresses using an IP alias. The following command syntax sets this alias:

# ifconfig [interface_name]:[alias_number] [alias_IP]

Make sure the alternate IP address is in the same network range.

Consider the scenario where the IP address for eno0 is 84.16.226.173. This type A IP is part of the 255.0.0.0 network range. Keep the first two numbers the same to make a similar IP address in the 255.0.0.0 range.

To do so, use the following command to make a new IP address, called eno0:2:

# ifconfig eno0:2 10.0.2.14

Check the result by using the following command:

# ifconfig

ethernet 2 ip details

 

 

 

 

 

 

 

 

 

 

The list shows the alias eno0:2 and its assigned IP address.

To delete an alias IP, use this command:

# ifconfig eno0:2 down

Use Case #17: Turn on Promiscuous Mode

The promiscuous mode lets a network device receive all types of packets. It’s commonly used for checking network activities.

To turn on promiscuous mode for a network interface, use the promisc argument:

# ifconfig [interface_name] promisc

Here’s an example:

Promiscuous Mode

Use Case #18: Turn off Promiscuous Mode

Turn off promiscuous mode using the -promisc flag:

# ifconfig eno0 -promisc

Check the results using the ifconfig command.

Ethernet Promiscuous Mode

 

 

 

 

 

If the PROMISC flag doesn’t show in the output, the interface is in normal mode.

Use Case #19: Look at Transmission Errors

You can pipe the output of the ifconfig command to the grep utility to see all lines containing the word error.

# ifconfig | grep error

Ifconfig Transmission Errors

 

 

 

 

 

 

This command displays lines that have errors, which are zero in this case.

Also Read: 6 Simple Examples of Using the Linux watch Command

Also Read: Mastering the Linux tee Command for Redirecting Output In 9 Examples

Conclusion

This article introduced ifconfig as a versatile tool for viewing detailed information about the active and inactive network interfaces. We discussed 19 use cases where you can use the command to get information about the network interfaces and change several options and associated IP addresses. 

RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. What is the ifconfig command in Linux?

The ifconfig command in Linux is used to set up and show details about network interfaces. It helps assign an IP address, manage the MTU, and configure various network settings.

Q. How can I use the ifconfig command for practical applications?

To use the ifconfig command in Linux with practical examples, you can configure a specific network interface like eth0. For instance, you can assign an IP address, bring the interface up or down, and check detailed information about its parameters. These examples demonstrate how ifconfig is a handy tool to configure network interfaces, adjust settings, and check status. It’s a fundamental tool for analyzing and troubleshooting network configurations in Linux environments.

Q. What are some essential commands related to ifconfig in Linux?

Some essential commands related to ifconfig in Linux include configuring a network interface using ifconfig eth0, managing IPv6 addresses, setting up a tunnel interface, and viewing the routing table for the system’s network interfaces.

Q. Is ifconfig still used in newer Linux distributions?

In newer Linux distributions, the ifconfig command has been somewhat replaced by the IP command, but it’s still widely used and available in many distributions. It works by taking an interface name after the command, allowing users to view or modify settings for that specific interface. Even without additional parameters, ifconfig displays the status of network interfaces, making it a valuable tool for network diagnostics and configuration.

Q. How do you assign an IP address using ifconfig?

To assign an IP address to a network interface in Linux using the ifconfig command, you can use the following syntax:

# ifconfig eth0

Q. What network interface parameters can be configured using ifconfig?

With Ifconfig in Linux, you can configure parameters like MTU, interface metric, physical address, and wireless settings. Simply specify the interface name after the command for precise control over network configurations, from basic tasks like changing IP addresses to advanced adjustments like managing wireless parameters.

Q. What is the difference between the ifconfig and IP commands in Linux?

The IP command in Linux is a modern replacement for ifconfig, offering advanced features for configuring network interfaces. It goes beyond the basic capabilities of ifconfig, providing more intricate control over interfaces, including the ability to bring them down and up. This command is part of the iproute2 suite and is considered more powerful for networking tasks on Linux systems.

Q. Can ifconfig command be used to view the IP address and option with netmask settings for a network interface?

Yes, the ifconfig command (networking command) can display the IP address, netmask address, and other network configuration details for a specific network interface in Linux.

Q. How to use the ifconfig command with no arguments?

When used without arguments, the ifconfig command in Linux displays information about all active network interfaces on the system, including their IP addresses, MAC addresses, and other relevant details.

Q. Where can I learn more about the ifconfig command and its usage in Linux?

You can delve into the usage of the ifconfig command in Linux by exploring the official documentation for your specific Linux distribution, referring to online tutorials and guides, or experimenting with the command in a practical environment to understand its functionality at a deeper level. Understanding the differences and functionalities of the IPconfig Linux and ifconfig commands can enhance your ability to manage and troubleshoot network interfaces on Linux operating systems effectively.

Try this guide with our instant dedicated server for as low as 40 Euros