Signup/Sign In

Ifconfig Command in Linux

Posted in Programming   LAST UPDATED: OCTOBER 5, 2021

    Ifconfig command is used in Unix and Linux operating systems used for interface configuration. This command is used to configure, control the queries from CLI (command-line interface) and to enable or disable the IP address, view all network interfaces. It can be used to set up any/all the network interfaces such as Ethernet, wireless, modem and so on that are connected to your computer.

    We Use the Ifconfig command in the following areas of Linux:

    1. To View All Network Setting

    The ifconfig command with no arguments is used to display all the active network interface details.

    It is also used to check the assigned IP address of a server. The following is an example

    1. [root@tecmint ~]# ifconfig 
    
    2.    
    
    3. eth0 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A 
    
    4. inet addr: 198.15.28.73 Bcast:172.16.25.63 Mask:255.255.255.224 
    
    5. inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link 
    
    6. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
    
    7. RX packets:2341604 errors:0 dropped:0 overruns:0 frame:0 
    
    8. TX packets:2217673 errors:0 dropped:0 overruns:0 carrier:0 
    
    9. collisions:0 txqueuelen:1000 
    
    10. RX bytes:293460932 (279.8 MiB) TX bytes:1042006549 (993.7 MiB) 
    
    11. Interrupt:185 Memory:f7fe0000-f7ff0000 
    
    12.   
    
    13. lo Link encap:Local Loopback 
    
    14. inet addr:127.0.0.1 Mask:255.0.0.0 
    
    15. inet6 addr: ::1/128 Scope:Host 
    
    16. UP LOOPBACK RUNNING MTU:16436 Metric:1 
    
    17. RX packets:5019066 errors:0 dropped:0 overruns:0 frame:0 
    
    18. TX packets:5019066 errors:0 dropped:0 overruns:0 carrier:0 
    
    19. collisions:0 txqueuelen:0 
    
    20. RX bytes:2174522634 (2.0 GiB) TX bytes:2174522634 (2.0 GiB) 
    
    21.   
    
    22. tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
    
    23. inet addr:10.1.1.1 P-t-P:10.1.1.2 Mask:255.255.255.255 
    
    24. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 
    
    25. RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
    
    26. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
    
    27. collisions:0 txqueuelen:100 
    
    28. RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 

    2. Display Information of All Network Interfaces

    The following ifconfig command with a -a argument will display information of all active or inactive network interfaces on the server.

    1. [root@tecmint ~]# ifconfig -a 
    
    2.    
    
    3. eth0 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A 
    
    4. inet addr:172.16.25.126 Bcast:172.16.25.63 Mask:255.255.255.224 
    
    5. inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link 
    
    6. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
    
    7. RX packets:2344927 errors:0 dropped:0 overruns:0 frame:0 
    
    8. TX packets:2220777 errors:0 dropped:0 overruns:0 carrier:0 
    
    9. collisions:0 txqueuelen:1000 
    
    10. RX bytes:293839516 (280.2 MiB) TX bytes:1043722206 (995.3 MiB) 
    
    11. Interrupt:185 Memory:f7fe0000-f7ff0000 
    
    12.   
    
    13. lo Link encap:Local Loopback 
    
    14. inet addr:127.0.0.1 Mask:255.0.0.0 
    
    15. inet6 addr: ::1/128 Scope:Host 
    
    16. UP LOOPBACK RUNNING MTU:16436 Metric:1 
    
    17. RX packets:5022927 errors:0 dropped:0 overruns:0 frame:0 
    
    18. TX packets:5022927 errors:0 dropped:0 overruns:0 carrier:0 
    
    19. collisions:0 txqueuelen:0 
    
    20. RX bytes:2175739488 (2.0 GiB) TX bytes:2175739488 (2.0 GiB) 
    
    21.   
    
    22. sit0 Link encap:IPv6-in-IPv4 
    
    23. NOARP MTU:1480 Metric:1 
    
    24. RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
    
    25. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
    
    26. collisions:0 txqueuelen:0 
    
    27. RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 
    
    28.   
    
    29. tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
    
    30. inet addr:10.1.1.1 P-t-P:10.1.1.2 Mask:255.255.255.255 
    
    31. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 
    
    32. RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
    
    33. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
    
    34. collisions:0 txqueuelen:100 
    
    35. RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 

    3. To View Network Settings of Specific Interface

    Using interface name (eth0) as an argument with ifconfig command displays the details of the specific network interface.

    1. [root@tecmint ~]# ifconfig eth0 
    
    2.    
    
    3. eth0 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A 
    
    4. inet addr: 198.15.28.73 Bcast:172.16.25.63 Mask:255.255.255.224 
    
    5. inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link 
    
    6. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
    
    7. RX packets:2345583 errors:0 dropped:0 overruns:0 frame:0 
    
    8. TX packets:2221421 errors:0 dropped:0 overruns:0 carrier:0 
    
    9. collisions:0 txqueuelen:1000 
    
    10. RX bytes:293912265 (280.2 MiB) TX bytes:1044100408 (995.7 MiB) 
    
    11. Interrupt:185 Memory:f7fe0000-f7ff0000 

    4. To Assign an IP Address to Network Interface

    We use the ifconfig command to assign an IP address to a specific interface.

    The command with an interface name (eth0) and IP address that you want to assign helps in assigning the Ip address to the interface.

    1. [root@tecmint ~]# ifconfig eth0 198.15.28.73 

    5. To Assign a Netmask to Network Interface

    We use the ifconfig command with the netmask argument and interface name as (eth0) to assign a netmask to a specific interface.

    The command with an interface name (eth0) and netmask argument that you want to assign helps in assigning the netmask to the interface.

    1. [root@tecmint ~]# ifconfig eth0 netmask 255.255.255.224 

    6. To Assign a Broadcast to Network Interface

    Using the broadcast argument with an interface name will set the broadcast address for the given interface.

    ifconfig eth0 broadcast 172.16.25.63 command sets the broadcast address to an interface eth0.

    1. [root@tecmint ~]# ifconfig eth0 broadcast 198.15.28.73 
    
     

    7. To Assign an IP, Netmask, and Broadcast to Network Interface

    To assign an IP address, Netmask address, and Broadcast address all at once using the ifconfig command with all arguments we need to assign it as given in the below argument

    1. [root@tecmint ~]# ifconfig eth0 198.15.28.73 netmask 255.255.255.224 broadcast 198.15.28.73 
    
     

    8. To Change MTU for a Network Interface

    The MTU stands for maximum transmission unit. The MTU allows you to set the packet size limit that is transmitted through an interface.

    You can set the Mtu in the following manner, ifconfig eth0 MTU 1000 will set the maximum transmission unit where only packets below or equal to 1000 can pass through the network.

    Note: not all network interfaces support MTU settings.

    1. [root@tecmint ~]# ifconfig eth0 MTU 1000 

    9. To Enable Promiscuous Mode

    When a packet is received by a network card in the normal mode, it verifies whether the packet belongs to its network. If not, it drops the packet or discards sending discarded messages to the sender.

    The promiscuous mode is used to accept all the packets that flow through the network card. Many of the present network tools use the promiscuous mode to capture and analyze the packets that flow through the network interface so that there will be no packet loss and very few retransmissions. To set the promiscuous mode, use the following command.

    1. [root@tecmint ~]# ifconfig eth0 promisc 

    10. To Disable Promiscuous Mode

    To disable promiscuous mode, use the promisc then it goes back to the network interface in normal mode.

    1. [root@tecmint ~]# ifconfig eth0 -promisc 

    11. To Add New Alias to Network Interface

    This allows you to configure additional network interfaces using the alias feature. To add the alias network interface of eth0, we use the following command.

    1. [root@tecmint ~]# ifconfig eth0:0 172.16.25.127 

    We can verify the newly created alias network interface address, by using the ifconfig eth0:0 command.

    1. [root@tecmint ~]# ifconfig eth0:0 
    
    2.    
    
    3. eth0:0 Link encap:Ethernet HWaddr 00:01:6C:99:14:68 
    
    4. inet addr:172.16.25.123 Bcast:172.16.25.63 Mask:255.255.255.240 
    
    5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
    
    6. Interrupt:17 
    
    To Remove Alias to

    12. To remove Network Interface

    If you no longer required an alias network interface or you incorrectly configured it, you can remove it by using the following command.

    1. [root@tecmint ~]# ifconfig eth0:0 down 

    To change the MAC address of the Network Interface

    To change the MAC (Media Access Control) address of an eth0 network interface, use the below command with the argument “hw ether“.

    1. [root@tecmint ~]# ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF 

    Conclusion:

    Ifconfig is generally used in all the computer networking system, but in the computing system, IP is giving as many commands as if and works more efficiently, so now at most of the places ifconfig is replaced by IP command.

    You may also like:

    About the author:
    Tags:NetworksLinuxifconfig
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS