ifconfig – Configure and display the network parameters of the network card of the Linux system

The ifconfig command is used to configure and display the network parameters of the network card of the Linux system. It is a powerful command that allows you to view and change the network settings of your system.

Overview

The basic syntax of the ifconfig command is as follows:

ifconfig [interface] [options]

Here, the interface parameter specifies the name of the network interface that you want to configure or display information for. If no interface is specified, ifconfig will display information for all active interfaces.

The options parameter specifies the various options that you can use with the ifconfig command. Some common options include:

  • up – Brings the specified interface up.
  • down – Brings the specified interface down.
  • inet addr – Specifies the IPv4 address of the interface.
  • netmask – Specifies the subnet mask of the interface.
  • broadcast – Specifies the broadcast address of the interface.
  • hw addr – Specifies the MAC address of the interface.
  • mtu – Specifies the Maximum Transmission Unit (MTU) of the interface.

Examples

To display information for all active interfaces, simply run the ifconfig command with no parameters:

ifconfig

To display information for a specific interface, specify the interface name as a parameter:

ifconfig eth0

To bring an interface up or down, use the up or down options:

ifconfig eth0 up
ifconfig eth0 down

To assign an IP address to an interface, use the inet option followed by the IP address and subnet mask:

ifconfig eth0 inet 192.168.0.2 netmask 255.255.255.0

To change the MTU of an interface, use the mtu option followed by the desired MTU value:

ifconfig eth0 mtu 1500

Options

The following table lists the available options for the ifconfig command:

Option Description
up Brings the specified interface up.
down Brings the specified interface down.
inet addr Specifies the IPv4 address of the interface.
netmask Specifies the subnet mask of the interface.
broadcast Specifies the broadcast address of the interface.
hw addr Specifies the MAC address of the interface.
mtu Specifies the Maximum Transmission Unit (MTU) of the interface.

Troubleshooting tips

Here are some common issues that you may encounter when using the ifconfig command, along with troubleshooting tips:

  • “ifconfig: command not found” error: This error occurs when the ifconfig command is not installed on your system. To fix this, you can install the net-tools package using your system’s package manager.
  • “SIOCSIFADDR: No such device” error: This error occurs when you specify an interface that does not exist. Make sure that you are specifying the correct interface name.
  • “SIOCSIFNETMASK: Invalid argument” error: This error occurs when you specify an invalid subnet mask. Make sure that you are specifying a valid subnet mask for your network.

Notes

  • The ifconfig command is deprecated in newer versions of Linux, and has been replaced by the ip command. However, ifconfig is still widely used and is included in most Linux distributions.
  • When changing the network settings of an interface using the ifconfig command, the changes are not persistent and will be lost when the system is rebooted. To make changes persistent, you will need to modify your system’s network configuration files.