ifconfig Command in Linux

Learn via video courses
Topics Covered

Overview

The ifconfig command is a versatile command-line utility in Linux, used primarily for network configuration and management. It allows users to view and modify network interface parameters such as IP addresses, netmasks, and broadcast addresses.

Linux ifconfig Command Syntax

The syntax for the ifconfig command is as follows:

Where:

  • INTERFACE: The name of the network interface you want to configure, like eth0 or wlan0.
  • FLAGS: Flags are used to modify the behavior of the command, such as enabling or disabling an interface.
  • OPTIONS: Options are used to set specific parameters for the network interface, such as IP addresses, netmasks, and broadcast addresses.

ifconfig Command Options:

  • up: Enable a network interface.
  • down: Disable a network interface.
  • add: Add an IP address to the network interface.
  • del: Delete an IP address from the network interface.

Example Usages

  • Display network interface information.:

    Output:

    Explanation: This command provides an overview of all available network interfaces and their current settings, including IP addresses, netmasks, and broadcast addresses.

  • Enable a network interface.:

    Output:

    Explanation: This command enables the eth0 network interface, allowing it to transmit and receive data.

Tips

  • Always use 'sudo' when modifying network interface settings to ensure you have the necessary privileges.

  • Use 'man ifconfig' to view the complete list of options and their descriptions.

Advanced Use Cases of ifconfig Command in Linux

  • Configure a static IP address.:

    Output:

    Explanation: This command assigns the static IP address 192.168.1.10 with a netmask of 255.255.255.0 to the eth0 network interface.

  • Configure multiple IP addresses on a single network interface.:

    Output:

    Explanation: This command adds a secondary IP address 192.168.1.11 to the eth0 network interface.

  • Remove an IP address from a network interface.:

    Output:

    Explanation: This command removes the secondary IP address 192.168.1.11 from the eth0 network interface.

Conclusion

  • ifconfig is a powerful command-line utility for network configuration and management in Linux.

  • It allows users to view and modify network interface parameters such as IP addresses, netmasks, and broadcast addresses.

  • Always use 'sudo' when modifying network interface settings to ensure you have the necessary privileges.