Linux ifconfig Command With Examples

Estimated reading: 8 minutes 0 views


The ifconfig command is a part of net-tools, a legacy Linux tool for configuring a network interface. Modern distributions use the IP command, which works in a similar manner.

Even though ifconfig has limited capabilities compared to IP, the command is still commonly used to configure a network interface in Linux.

This tutorial will teach you how to use the Linux ifconfig command through practical examples.

  • A VPS/server running Linux.
  • Full root access
Important: ifconfig used to come preinstalled on all major Linux distributions. However, the tool was deprecated due to lack of maintenance and support for IPv6. The IP command is the preferred alternative.

Linux ifconfig Command Syntax

The basic ifconfig syntax looks like this:

ifconfig [interface_name_optional] [arguments_optional]

The ifconfig command prints an output when executed without arguments or with the interface name only. If used with arguments, there is no output.

Linux ifconfig Command Options

The ifconfig command works with arguments to achieve different results. Below is a list of common ifconfig command options:

Option Description
-a Prints the configuration for all interfaces, not just the active ones.
-s Displays only a shortlist of all interfaces.
-v Prints a more detailed configuration for all interfaces.
interface_name Represents the interface’s name and is accompanied by a unit number. Prints the configuration for a specific interface.
down Deactivates the interface.
up Activates the interface.
[IP_address_number] Assigns an IP address to a specified interface.
netmask [address] Changes the network mask for a specific interface.
broadcast [address] Sets the broadcast address for a specific interface.
mtu [number] Sets the Maximum Transfer Unit (MTU) of an interface.
promisc Enables promiscuous mode in which the interface receives all packets.
[-]promisc Disables promiscuous mode.
arp Enables the ARP protocol on a specific interface.
[-]arp Disables the ARP protocol on a specific interface.
allmulti Enables the all-multicast mode in which the interface receives all multicast packets.
[-]allmulti Disables the all-multicast mode.

Linux ifconfig Command Examples

The ifconfig command manages network interface parameters. Hence, the command has extensive practical usage. The sections below list common examples.

Note: Note that sudo is not required for view operations. However, if you are modifying the current configuration, sudo privileges are required.

1. View Active Network Interface Settings

Run ifconfig with no arguments to print essential information about all active network interfaces:

ifconfig terminal output

The output shows crucial data about the network interfaces, like:

    • The names of the active network interfaces. This system includes eth0 and lo (the loopback interface). Active network interfaces differ from system to system.
    • The hardware MAC address.
    • The IP address (inet), netmask, and broadcast address.
    • The MTU (Maximum Transmission Unit) value.

The same command prints a different output when run on a different Linux distribution. For instance, on CentOS ifconfig shows settings for the interface as well.

2. Display a Shortlist of Active Interfaces

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

Use the -s flag with ifconfig to display a concise summary of every active interface:

ifconfig -s
ifconfig -s terminal output

3. Print the Verbose Output

As opposed to the -s flag, the verbose option (-v) prints a more detailed output. Depending on the system, the outcome is either the same as ifconfig without arguments or slightly more in-depth.

ifconfig -v
ifconfig -v terminal output

In this case, the output is the same as when running ifconfig without arguments.

4. Show Every Network Interface Configuration

Without options, ifconfig displays active interfaces only. To get info about both active and inactive network interfaces, run ifconfig with the -a option:

ifconfig -a
ifconfig -a Ubuntu terminal output

The system has no inactive networks, so the output is the same as without the -a argument.

5. Get Information About a Specific Network Interface

To get information about a single specific network interface, use :

ifconfig [interface_name]

For instance, to display eth0’s settings, execute:

ifconfig eth0
ifconfig enp0s3 terminal output

6. Disable a Network Interface

An active network interface transmits and receives data. To deactivate a specific network interface, run the ifconfig command with the down flag and use sudo:

ifconfig [interface_name] down

For example, to disable eth0 run:

ifconfig eth0 down

The command doesn’t print any output. Run ifconfig without any arguments to verify that lo is not active anymore:

sudo ifconfig enp0s3 down verification terminal output

7. Enable a Network Interface

To reactivate a network interface, use the up flag with sudo. For example, to enable the eth0 interface run:

ifconfig eth0 up

Verify that the eth0 interface is active again:

sudo ifconfig enp0s3 up verification terminal output

The output shows that both interfaces are now active and running.

8. View IP Addresses

List all IP addresses related to the interfaces on the system by piping ifconfig with grep.

ifconfig | grep inet
ifconfig | grep inet terminal output

The output prints all lines that contain IP addresses.

9. Assign an IP Address to an Interface

To define an IP address for a specific interface, run the ifconfig command with the interface name and the IP address.

ifconfig [interface_name] [IP_address]

For instance, to assign to eth0, run:

ifconfig eth0

The command doesn’t have any output. Run ifconfig with no arguments to confirm the IP address change:

Assigning and verifying IP address with ifconfig terminal output

10. View Network Interface Masks

Each interface has its assigned netmask. A netmask (or a subnet mask) refers to ranges of IP addresses divided into classes ( A, B, and C being the most common). Each class belongs to a default subnet mask. For instance:

  • Class A IPs belong to the netmask.
  • Class B networks belong to the netmask.
  • Class C networks use the netmask.

Note that the IP class doesn’t fit into its default netmask in some cases.

To list netmasks used by active network interfaces, pipe the results with grep:

ifconfig | grep netmask
ifconfig | grep netmask terminal output

The output prints a list of IPs and netmasks they belong to. The netmask, in this case, is

11. Assign a Netmask to an Interface

To assign a netmask address to an interface, specify the interface and use the netmask option with sudo.

ifconfig [interface_name] netmask [netmask_IP]

For instance, assign the netmask to eth0:

ifconfig eth0 netmask

Verify the results with:

Assigning and verifying netmask with ifconfig terminal output

The output shows that the netmask is changed to

12. View the Broadcast Address of Interfaces

The broadcast setting is the address that sends messages to all hosts in a network. It is assigned automatically by the system.

Use grep to list the broadcast addresses of the interfaces:

ifconfig | grep broadcast
ifconfig | grep netmask terminal output

The command lists the lines in which the broadcast address is present.

13. Assign a New Broadcast IP to a Network Interface

To assign a new broadcast IP, specify the network interface and use the broadcast argument with sudo.

ifconfig [interface_name] broadcast [broadcast_IP]

For example, assign as the new broadcast IP to eth0 with:

ifconfig eth0 broadcast

Since there is no output, verify the change by running ifconfig:

Assigning and verifying broadcast with ifconfig terminal output

14. Configure Multiple Network Parameters with One Command

The IP address, netmask, and broadcast of an interface can all be modified with one command. The syntax is:

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

For example, for eth0 we’ll set:

  • The IP to
  • The netmask to
  • The broadcast to
ifconfig eth0 netmask broadcast

Verify the results:

Assigning and verifying IP, netmask, and broadcast with ifconfig terminal output

The output shows that all three parameters are changed.

15. Set MTU for an Interface

The MTU stands for the maximum transmission unit and allows users to limit the size of packets transmitted on an interface. Use the mtu argument with the ifconfig command, specify it’s value, and use sudo:

ifconfig [interface_name] mtu [mtu_value]

For example, set the MTU for enp0s3 to 2000 with:

ifconfig enp0s3 mtu 2000
setting MTU with ifconfig terminal output
Note: Please note that not all network interfaces allow the MTU to be changed.

16. Set an Alias IP

The ifconfig command allows users to associate additional IP addresses with an interface using an IP alias.

Create an alias IP with the following command:

ifconfig [interface_name]:[alias_number] [alias_IP]

Note that the alias IP must belong to the same netmask.

For example, the IP address for enp0s3 is This is a type A IP and belongs to the netmask. To create an alias IP under the netmask, do not change the first two numbers. For instance, run the following command to create an alias enp0s3:0:

ifconfig enp0s3:0

Verify the outcome:

Creating an alias with ifconfig terminal-output

The alias enp0s3:0 and the assigned IP are listed.

To remove an alias IP, run:

ifconfig enp0s3:0 down

17. Enable Promiscuous Mode

Promiscuous mode allows a network device to accept all packets. The mode is often used to analyze network activity.

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

ifconfig [interface_name] promisc

For example,

Disabling the promiscuous mode terminal output

18. Disable Promiscuous Mode

Disable promiscuous mode with the -promisc flag:

ifconfig enp0s3 -promisc

Verify the results with ifconfig.

Disabling the promiscuous mode terminal output

The PROMISC flag is not present in the output, meaning that the interface is in normal mode.

19. View Transmission Errors

Print any transmission errors in the interface by filtering the output with grep:

ifconfig | grep errors
ifconfig | grep errors terminal output

This command outputs lines with errors, which in this case is zero.


After reading this article, you know how to use ifconfig to configure network settings. While using the IP is still the popular choice, ifconfig does offer plenty of opportunities.

Next, learn different ways to configure CentOS network settings.

Support 24/24h with coupon code: 1DOLLAROFF 10% discount. Click now! 👆


Leave a Comment