How to use ifconfig command in Linux with examples

ifconfig (interface configuration utility) can be used for managing network and configuring network. also you can query current network to get current network settings.

Syntax

ifconfig

This is basic use of ifconfig  command, this will display current network interface details (ip address).

Where there are parameters like eth0, wlan0 and lo – eth0 is first ethernet network interface additional ethernet network will be shown as eth1, eth2 and so on. Similarly wlan0 is first wireless network connection. lo is loopback interface which is used by system for communicating with itself.

Display details for all network interface using ifconfig command

When using ifconfig without any argument you are presented with details of only active network interface. To view details of all network interface including inactive interface use switch -a with ifconfig.

Syntax

ifconfig -a

Display details of only specific network interface using ifconfig command

To view details of only specific network interface use interface name along with ifconfig command as an argument.

Syntax

ifconfig wlan0

Configure IP, Netmask and Broadcast address of a Network Interface using ifconfig command

ifconfig command can be used configure network interface, to configure a network interface use ifconfig followed by argument for IP, Netmask and Broadcast address.

Syntax

ifconfig eth0 [IP address] netmask [netmask address] broadcast [broadcast address]

Example

ifconfig eth0 192.168.42.129 netmask 255.255.255.254 broadcast 192.168.42.45

Above ethernet card 1 has been configured for IP

Configure IP address of a Network Interface using ifconfig command

You can configure only IP address also with ifconfig command. In this case you have to provide network interface you want to configure followed by IP address.

Syntax

ifconfig eth0 [IP address]

Example

ifconfig wlan0 192.168.42.128

Configure netmask address of a Network Interface using ifconfig command

You can configure only netmask address also with ifconfig command. In this case you have to provide network interface you want to configure followed by netmask argument and then netmask address.

Syntax

ifconfig eth0 netmask [netmask address]

Example

ifconfig wlan0 netmask 255.255.255.254

Configure broadcast address of a Network Interface using ifconfig command

You can configure broadcast address with ifconfig command. In this case you have to provide network interface you want to configure followed by broadcast argument and then broadcast address.

Syntax

ifconfig eth0 broadcast [broadcast address]

Example

ifconfig wlan0 broadcast 255.255.255.254

Enable a network interface using ifconfig command

To enable a network interface you can use ifconfig command specifying network interface you want to enable followed by argument ‘up’.

Syntax

ifconfig eth0 up

Example

ifconfig wlan0 up

Disable a network interface using ifconfig command

To disable a network interface you can use ifconfig command specifying network interface you want to disable followed by argument ‘down’.

Syntax

ifconfig eth0 down

Example

ifconfig wlan0 down