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.
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 Linux system.
- Access to the terminal.
- Sudo privileges when making updates to network interface settings.
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
ifconfig syntax looks like this:
ifconfig [interface_name_optional] [arguments_optional]
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
ifconfig command works with arguments to achieve different results. Below is a list of common
ifconfig command options:
|Prints the configuration for all interfaces, not just the active ones.|
|Displays only a shortlist of all interfaces.|
|Prints a more detailed configuration for all interfaces.|
|Represents the interface's name and is accompanied by a unit number. Prints the configuration for a specific interface.|
|Deactivates the interface.|
|Activates the interface.|
|Assigns an IP address to a specified interface.|
|Changes the network mask for a specific interface.|
|Sets the broadcast address for a specific interface.|
|Sets the Maximum Transfer Unit (MTU) of an interface.|
|Enables promiscuous mode in which the interface receives all packets.|
|Disables promiscuous mode.|
|Enables the ARP protocol on a specific interface.|
|Disables the ARP protocol on a specific interface.|
|Enables the all-multicast mode in which the interface receives all multicast packets.|
|Disables the all-multicast mode.|
Linux ifconfig Command Examples
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
The output shows crucial data about the network interfaces, like:
- The names of the active network interfaces. This system includes enp0s3 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 vibr0 interface as well.
2. Display a Shortlist of Active Interfaces
ifconfig command without any arguments prints a rather detailed output about all active interfaces.
-s flag with
ifconfig to display a concise summary of every active interface:
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.
In this case, the output is the same as when running
ifconfig without arguments.
Note: Learn how to deactivate a network interface using ifdown command.
4. Show Every Network Interface Configuration
ifconfig displays active interfaces only. To get info about both active and inactive network interfaces, run
ifconfig with the
The system has no inactive networks, so the output is the same as without the
-a argument. The output from CentOS, however, shows three active and one inactive interfaces:
The output shows the vibr0-nic interface as an inactive one.
5. Get Information About a Specific Network Interface
To get information about a single specific network interface, use :
For instance, to display enp0s3's settings, execute:
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 enp0s3 run:
sudo ifconfig enp0s3 down
The command doesn't print any output. Run
ifconfig without any arguments to verify that enp0s3 is not active anymore:
7. Enable a Network Interface
To reactivate a network interface, use the
up flag with
sudo. For example, to enable the enp0s3 interface run:
sudo ifconfig enp0s3 up
Verify that the enp0s3 interface is active again:
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
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.
sudo ifconfig [interface_name] [IP_address]
For instance, to assign 10.0.2.20 to enp0s3, run:
sudo ifconfig enp0s3 10.0.2.20
The command doesn't have any output. Run
ifconfig with no arguments to confirm the IP address change:
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 255.0.0.0 netmask.
- Class B networks belong to the 255.255.0.0 netmask.
- Class C networks use the 255.255.255.0 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
ifconfig | grep netmask
The output prints a list of IPs and netmasks they belong to. The netmask, in this case, is 255.0.0.0
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 255.255.255.0 to enp0s3:
sudo ifconfig enp0s3 netmask 255.255.255.0
Verify the results with:
The output shows that the netmask is changed to 255.255.255.0
12. View the Broadcast Address of Interfaces
broadcast setting is the address that sends messages to all hosts in a network. It is assigned automatically by the system.
grep to list the broadcast addresses of the interfaces:
ifconfig | grep broadcast
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 10.0.2.250 as the new broadcast IP to enp0s3 with:
sudo ifconfig enp0s3 broadcast 10.0.2.250
Since there is no output, verify the change by running
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:
sudo ifconfig [interface_name] [IP] netmask [netmask_addresss] broadcast [broadcast_address]
For example, for enp0s3 we'll set:
- The IP to 10.0.2.15
- The netmask to 255.0.0.0
- The broadcast to 10.0.2.255
sudo ifconfig enp0s3 10.0.2.15 netmask 255.0.0.0 broadcast 10.0.2.255
Verify the results:
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:
sudo ifconfig enp0s3 mtu 2000
Note: Please note that not all network interfaces allow the MTU to be changed.
16. Set an Alias IP
ifconfig command allows users to associate additional IP addresses with an interface using an IP alias.
Create an alias IP with the following command:
sudo 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 10.0.2.15. This is a type A IP and belongs to the 255.0.0.0 netmask. To create an alias IP under the 255.0.0.0 netmask, do not change the first two numbers. For instance, run the following command to create an alias enp0s3:0:
sudo ifconfig enp0s3:0 10.0.2.30
Verify the outcome:
The alias enp0s3:0 and the assigned IP are listed.
To remove an alias IP, run:
sudo 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
sudo ifconfig [interface_name] promisc
18. Disable Promiscuous Mode
Disable promiscuous mode with the
sudo ifconfig enp0s3 -promisc
Verify the results with
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
ifconfig | grep errors
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.
For more tutorials on
ifconfig command, refer to our tutorial
ifconfig command not found and learn how to fix this error.
Next, learn different ways to configure CentOS network settings.