The ifconfig command configures network interfaces in the computer's kernel. It is used during boot time to set up the interfaces as needed. Afterward, it is commonly used for debugging or system tuning and can assign IP addresses or enable/disable interfaces.
To Install ifconfig:
Please note that the ifconfig command is deprecated and replaced with 'ip' on newer Linux distributions. It may not be included in those newer versions.
If you encounter an error message saying "ifconfig: command not found," it indicates that the package containing the command is not installed on your system.
To install ifconfig on Ubuntu/Debian-based Linux distributions, use this command:
# apt install net-tools -y
To install ifconfig on CentOS and other RHEL-based Linux distros, type the following:
# dnf install net-tools -y
ifconfig Syntax
The ifconfig tool's general syntax is as follows:
ifconfig [options] interface [addressfamily [address [destination address] ] [parameters] ]
Let's explore the meaning of each field:
Options - Use the options field to narrow down or specify search requests for interfaces, such as enabling verbose output or listing the interfaces.
Address - This field indicates the network address assigned to the network interface.
Address family - Specify the network address family to be modified.
Destination address - Designate the address of the remote correspondent on the point-to-point link.
Interface - Provide the network interface configuration values to display or modify, like "en" for Ethernet, "at" for ATM, "tr" for token ring, "xt" for X.25, etc. Include a number after the abbreviation to identify the specific interface (e.g., et2).
Parameters - Indicate the action to be performed on the selected interface(s), such as shutting down or activating.
By experimenting with various interfaces and option combinations, you can achieve specific results.
The configurations made using the ifconfig command are not retained after a system restart; they are temporary. To ensure the changes persist across reboots, you must edit the distribution-specific configuration files or include the commands in a startup script.
Network interface configuration can only be performed by the root user or by users with sudo privileges.
Linux ifconfig Command Examples
The ifconfig command is utilized for managing network interface parameters, making it highly practical. The following sections present some common examples of its usage.
1. Display Network Interface Information
To obtain the configuration details of all network interfaces, simply run the following command without any options:
# ifconfig -a
This command will provide information about both active and inactive interfaces. If you wish to view the configuration of a specific network interface, just specify the interface name after the command:
# ifconfig eno1
The output will resemble this:
2. Assign IP Address and Netmask to a Network Interface
You can easily assign an IP address and netmask to a network interface using the ifconfig command. Follow this syntax:
ifconfig [interface-name] [ip-address] netmask [subnet-mask]
For instance, to set the IP address 192.168.3.155 and netmask 255.255.0.0 to the eno1 interface, use:
# ifconfig eno1 192.168.3.155 netmask 255.255.0.0
Moreover, you can assign a secondary IP address to a network interface using aliasing:
# ifconfig eno1:0 192.168.3.156 netmask 255.255.0.0
3. Enable or Disable a Network Interface
The ifconfig command is also useful for enabling or disabling a network interface. To disable an active interface, employ the down flag after the device name:
# ifconfig eno1 down
To enable an inactive interface, utilize the up flag:
# ifconfig eno1 up
4. Enable or Disable Promiscuous Mode
Promiscuous mode allows a network interface to observe all packets in a network. To enable promiscuous mode on a specific network device, use the promisc flag:
# ifconfig eno1 promisc
To disable promiscuous mode, use the -promisc flag:
# ifconfig eno1 -promisc
5. Change MTU of a Network Interface
The MTU (Maximum Transmission Unit) determines the maximum packet size transmitted on an interface. To modify the MTU value, use this syntax:
# ifconfig [interface-name] mtu [mtu-value]
For instance, to set the MTU value of eth0 to 500, execute:
# ifconfig eno1 mtu 500
6. Change MAC Address of a Network Interface
The MAC (Media Access Control) address uniquely identifies devices on a network. You can change the MAC address of a network interface using the hw ether flag:
# ifconfig eno1 hw ether 00:00:2d:3a:2a:28
Conclusion:
In summary, ifconfig is a useful tool with various options for configuring network interfaces. Although newer Linux distributions now prefer the ip command, understanding ifconfig provides valuable knowledge of network configuration options and terminologies.