Ifconfig Command in Linux

FREE Online Courses: Elevate Your Skills, Zero Cost Attached - Enroll Now!

In this article, you will learn about the command ifconfig and the different options used with the ifconfig command. We will also be looking into how to configure networks using the ifconfig command.

What is ifconfig?

Ifconfig is a Linux / UNIX command used to configure the kernel-resident network interfaces. If config is the abbreviation for InterFace Configuration. Through the command line, ifconfig can display current network configuration information, netmask, set up an IP address, create an alias for the network interface, broadcast address to the network interface, set up hardware address and so many more things.

If config is used at boot time to set up the interfaces as required. After rebooting, it is only required when debugging or when tuning the system.

Installing Ifconfig

New versions of Linux may or may not have ifconfig preinstalled in them as it is slowly being replaced by IP. So if you find an error while running the command: “ifconfig” in the terminal, it means that it is not installed in your system.

Installing ifconfig is very easy, you just have to enter the following command, depending on your Linux OS:

1. Installing in Debian based Linux distros

To install ifconfig in Debian based Linux distributions like Ubuntu, Kali, PureOS, Mint, Deepin, etc enter the following command:

sudo apt-get install net-tools

2. Installing in RHEL based Linux distros

To install ifconfig in RHEL (Red Hat Enterprise Linux) based Linux distributions like fedora, Rocky. Clear OS, CentOS, Alma Linux, Oracle Linux, Euro Linux, Fermi Linux, etc enter the following command:

yum install net-tools

Starting Ifconfig

Once you install the ifconfig tool, you can simply start it by typing the command: “ifconfig” in the terminal (It will give you a list of all the interfaces being used). You can also type any other option that comes with the ifconfig tool to get deserted results.

The general syntax for the ifconfig tool is:

ifconfig [options] interface [addressfamily [address [destination address] ] [parameters] ]

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

Let us look at what each field actually means:

1. Options

The options field is used to narrow down or give specific search requests of the interfaces. For example, providing verbose, listing the interfaces, etc.

2. Address

This field specifies the network address for the network interface.

3. Address family

This field specifies which network address family to change.

4. Destination address

This field specifies the address of the correspondent on the remote end of the point-to-point link.

5. Interface

This field specifies the network interface configuration values to show or change. For example – en for Ethernet, at for ATM (Automated transfer Mode), tr for token ring, xt for X.25, etc. You must also include a number after the abbreviation to identify the specific interface, (for example, et2).

6. Parameters

This field specifies the action that has to be done on the selected interface or interfaces. For example, shutting down, or making as active.

You can play with the different combinations of the interfaces and options to get specific results.

In general, in most systems, if you run the standard “ifconfig” command with no interfaces or options, you will get this output:

 

Here, eth0, lo, and wlan0 are the active network interfaces on your system. Let us take a brief look at each of them:

1. etho

This is the name of the first ethernet interface, first because additional ethernet interfaces will be named as eth1, eth2, and so on.

2. lo

This is the loopback interface. It is a special network interface that the system uses to communicate with itself.

3. wlan0

This is the name of the first wireless network interface, additional ethernet interfaces will be named as eth1, eth2, and so on.

Options with ifconfig Command in Linux

In typical Linux fashion, just like every command had lots and lots of options to use, which help us get desired results, ifconfig also has many options. Let us first look at them, before we see how to use them cumulatively.

The options used with ifconfig are of 3 types: flags and parameters which can be used in the syntax to give desired outputs.

1. Flags

a. -a

This flag displays information for all network interfaces.

b. -d

This flag displays the interfaces which are down (shut down)

c. -u

This flag displays the interfaces which are up (active and running)

d. -l

This flag lists all available interfaces on the system, with no other additional information.

e. -v

This flag runs the command in verbose mode. It gives more details about the execution.

f. -s

This flag displays a shortlist of the interfaces instead of the details.

2. Parameters

a. alias

This parameter establishes an additional network address for the interface.

b. allcast

This parameter sets the Token-Ring interface to broadcast to all the rings on the network.

c. -allcast

This parameter confines the Token-Ring interface to broadcast only to the local ring.

d. arp

This parameter enables the ifconfig command to use the ARP (Adress Resolution protocol). ARP is used in mapping between network-level addresses and link-level addresses.

e. -arp

This parameter disables the use of ARP (Adress Resolution protocol).

f. -dad

This parameter does not perform duplicate IPv6 address detection.

g. -debug

This parameter disables driver dependent debug code.

h. delete

This parameter removes the specified network address.

i. detach

This parameter removes any interface from the network interface list.

j. down

This parameter marks an interface as inactive. Which keeps the system from trying to transmit messages through that interface.

k. first

This parameter puts an IPv6 address at the first place on an interface in order to select it as the source for unbound sockets.

l. group ID

This parameter adds a group ID to the group ID list for the interface.

m. -group ID

This parameter removes a group ID from the group ID list for the interface.

n. hwloop

This parameter enables hardware loopback. This module specifies that the locally addressed packets handled by an interfaced should be sent out using the associated adapter.

o. -hwloop

This parameter disables hardware loopback.

p. ipdst

This parameter specifies an internet host willing to recessive IP packets encapsulating ns packets bound for a remote network.

q. ipv6dst

This parameter is used to specify an IPv6 node that is willing to receive IPv6 packets through a tunnel.

r. link <0 – 2>

This parameter enables special processing of the link level (you specify, 3 values ranging from 0 to 2) of the interface.

s. -link <0 – 2>

This parameter disables special processing of the link level (you specify, 3 values ranging from 0 to 2) of the interface.

t. metric <number>

This parameter sets the routing metric of the interface to the value specified by the <number> you enter. Note that the default value is zero.

u. mtu <value>

This parameter sets the maximum IP packet size for this system (value is the number you enter).

v. netmask <Mask>

This parameter specifies how much of the address to reserve for subdividing networks into subnetworks. (can only be used with the address family of inet which is ‘et’)

w. site6

This parameter sets the IPv6 site number. The default value is zero.

x. tcp_nocksum

This parameter enables verification of the checksum of TCP data for local traffic to the subnet attached to the interface.

y. -tcp_nocksum

This parameter disables verification of the checksum of TCP data for local traffic to the subnet attached to the interface.

PHEW! That’s a lot of options! Don’t worry, not all of them are used frequently and if at all you get stuck, you can always use the “–help” option to get information about any option related to ifconfig.

Anyway, here are a few screenshots of some of the options:

ifconfig -a

ifconfig a

ifconfig -s

ifconfig s

ifconfig lo

ifconfig lo

ifconfig -v

ifconfig v

ifconfig –help

ifconfig help

Examples using ifconfig Command

Now that we have seen the basic terminologies, syntax, flags, and options, let us see how to put them in actual commands.

1. Assigning a netmask to a network interface

ifconfig eth0 netmask 255.255.255.224

The above command sets the network mask to a given interface eth0.

2. Disabling a network interface

ifconfig eth0 down

The above command deactivates the eth0 network interface.

3. Enabling a network interface

ifconfig eth0 up

The above command deactivates the eth0 network interface.

4. Assigning IP address to a network

ifconfig eth0 172.16.25.125

The above command sets the “172.16.25.125” Ip address to the eth0 network interface.

5. Viewing network settings of a specific interface

ifconfig eth0

The above command displays the details of only the eth0 network interface.

6. Assigning IP address and Netmask to an interface

ifconfig etho 192.167.98.211 netmask 255.255.0.0

The above command assigns the IP address “192.167.98.211” and netmask “255.255.0.0” to the “etho” network interface.

7. Enabling promiscuous mode

This mode allows a network interface to access and view all packets in the network.

ifconfig eth0 promisc

The above command enables the Promiscuous mode on the eth0 network interface.

8. Disabling promiscuous mode

ifconfig eth0 -promisc

The above command disables the Promiscuous mode on the eth0 network interface.

9. Canginging MTU of an interface

MTU stands for Maximum Transmission Unit. It allows you to limit the size of the packets on an interface.

ifconfig eth0 mtu 500

The above command sets the MTU value of the eth0 network interface to 500.

10. Changing the MAC address of an interface

MAC stands for Media Acess Control. It is the physical address that uniquely identifies the devices on a network.

ifconfig eth0 hw ether 00:00:2d:3a:28

The above command changes the MAC address of the eth0 network interface, by using the ‘hw’ flag to the new address “00:00:2d:3a:28”

Summary

As you have seen, ifconfig is a decent tool with a lot of option which allows you to configure network interfaces. Nowadays, the newer distributions of Linux, are replacing ifconfig with a more powerful tool called ip. Nonetheless, you have learned the different options, syntax, terminologies, and a few examples of how to use ifconfig.

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *