How to use the command 'ifconfig' (with examples)

How to use the command 'ifconfig' (with examples)

The ‘ifconfig’ command, short for Network Interface Configurator, is a command-line tool used to view and configure network interfaces on a system. It allows users to display network settings, enable or disable network interfaces, and assign IP addresses to interfaces. This article will provide examples of different use cases of the ‘ifconfig’ command.

Use case 1: View network settings of an Ethernet adapter

Code:

ifconfig eth0

Motivation: Sometimes it is necessary to view the network settings of a specific Ethernet adapter on a system. This could be useful for troubleshooting purposes or to check the current configurations of the network interface.

Explanation: In this use case, ’eth0’ is the name of the Ethernet adapter. The ‘ifconfig’ command is followed by the name of the network interface for which you want to view the settings.

Example output:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::c0df:92ff:fe48:5198  prefixlen 64  scopeid 0x20<link>
        ether c2:df:92:48:51:98  txqueuelen 1000  (Ethernet)
        RX packets 12689930  bytes 11740986201 (10.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7611278  bytes 1978719598 (1.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Use case 2: Display details of all interfaces, including disabled interfaces

Code:

ifconfig -a

Motivation: Sometimes it is necessary to view the details of all network interfaces, including disabled interfaces. This could be helpful when checking the status of all interfaces on a system.

Explanation: In this use case, the ‘-a’ option is used to display details of all interfaces, including those that are currently disabled.

Example output:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::c0df:92ff:fe48:5198  prefixlen 64  scopeid 0x20<link>
        ether c2:df:92:48:51:98  txqueuelen 1000  (Ethernet)
        RX packets 12689930  bytes 11740986201 (10.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7611278  bytes 1978719598 (1.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 27966  bytes 2884600 (2.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 27966  bytes 2884600 (2.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Use case 3: Disable eth0 interface

Code:

ifconfig eth0 down

Motivation: In certain scenarios, it may be necessary to disable a specific network interface. This could be done to disconnect from a network or troubleshoot issues related to the interface.

Explanation: In this use case, ’eth0’ is the name of the Ethernet adapter. The ‘down’ argument is used with the ‘ifconfig’ command to disable the specified interface.

Example output: (No output is generated when disabling an interface)

Use case 4: Enable eth0 interface

Code:

ifconfig eth0 up

Motivation: After disabling a network interface, it is important to enable it again to resume network connectivity. Enabling the interface is especially useful when troubleshooting connectivity issues or after making changes to the network configurations.

Explanation: In this use case, ’eth0’ is the name of the Ethernet adapter. The ‘up’ argument is used with the ‘ifconfig’ command to enable the specified interface.

Example output: (No output is generated when enabling an interface)

Use case 5: Assign IP address to eth0 interface

Code:

ifconfig eth0 ip_address

Motivation: Assigning an IP address to a network interface is necessary for establishing network connectivity. This use case is applicable when configuring static IP addresses or changing the IP address of a specific interface.

Explanation: In this use case, ’eth0’ is the name of the Ethernet adapter, and ‘ip_address’ represents the desired IP address to be assigned. By specifying the IP address after the ‘ifconfig eth0’ command, the IP address is assigned to the specified interface.

Example output: (No output is generated when assigning an IP address to an interface)

Conclusion:

The ‘ifconfig’ command is a powerful tool for managing network interfaces on a system. It allows users to view and configure network settings, enable or disable interfaces, and assign IP addresses. By utilizing the different use cases mentioned above, users can effectively manage and troubleshoot network-related issues in their systems.

Related Posts

Using the 'top' Command (with examples)

Using the 'top' Command (with examples)

The top command is a powerful tool that allows you to view dynamic real-time information about running processes on your system.

Read More
Using the grap Command (with examples)

Using the grap Command (with examples)

In this article, we will explore different use cases of the grap command, a charting preprocessor for the GNU Troff document formatting system.

Read More
How to use the command lpadmin (with examples)

How to use the command lpadmin (with examples)

The lpadmin command is used to configure CUPS printers and classes.

Read More