Best Linux ifconfig Command With Examples

In this article, we are going to discuss on Linux ifconfig command. Ifconfig is a simple command-line utility in Linux used to check and configure network interfaces. Hence the full form of ifconfig is Interface Configuration. By using this command you can get network information like IP Address (both IPV4 & IPV6), Physical Address (MAC Address), Subnet Mask, Broadcast address, MTU, Metric, Packets, Drops, lists all connected network interface cards (eg: eth0, eth1, lo, WLANs), etc.

Best Linux Ifconfig Command With Examples
Best Linux Ifconfig Command With Examples

Best Linux ifconfig Command With Examples:

In this article, I will show you the 10 most important ifconfig command which is usable for every Linux administrator.

Configure IP address using ifconfig command

You can configure IP Addresses in Linux using ifconfig command. Here I have an Ethernet connection i.e. ens33. So let’s configure the IP Address 10.40.234.150 in ens33. Refer to the command below.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 10.40.234.150   # Configure IP Address

Configure IP Address & Subnet Mask

To configure IP Address and Subnet Mask use the below command.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 10.40.234.150 netmask 255.255.0.0   # Configure IP Address & Subnet Mask

Configure IP Address, Subnet Mask & Broadcast Address at a time using Linux ifconfig command

We can use ifconfig command to configure IP Address, Subnet Mask & broadcast address at a time using a single command. Here we used the syntax netmask to set the Subnet Mask address & the syntax broadcast to set the broadcast address. Refer to the command below.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 10.40.234.150 netmask 255.255.0.0 broadcast 10.40.234.255

Check Network Information of all connected Network Interfaces

Check network information of all currently connected network interfaces using the below command. This includes the different interfaces like ens33, lo (Loopback), WLAN (Wireless LAN)…etc…

itsmarttricks@ubuntu:~$ ifconfig   # List all Network Interfaces
ens33     Link encap:Ethernet  HWaddr 00:0c:29:ff:cd:2e  
          inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::b396:d285:b5b3:81c3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:851 errors:0 dropped:0 overruns:0 frame:0
          TX packets:525 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:710566 (710.5 KB)  TX bytes:50788 (50.7 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:266 errors:0 dropped:0 overruns:0 frame:0
          TX packets:266 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:21250 (21.2 KB)  TX bytes:21250 (21.2 KB)

You can also use the ifconfig command with argument -a to check the details of all connected/available network connections.

itsmarttricks@ubuntu:~$ ifconfig -a

Also Read : Complete Unix Commands And Basic Linux Commands With Examples For Beginners

We have two more commands in Linux to check IP Addresses. Here below I have mentioned both commands.

Command 1 :

itsmarttricks@ubuntu:~$ ip a   # To check IP Address

Command 2 :

itsmarttricks@ubuntu:~$ ip addr   # To check IP Address

Check IP Address with other Information’s of a particular Ethernet Connection

We can use ifconfig command to check IP Addresses and other network-related information of a particular Ethernet connection. Here I am going to check the configuration of ens33. Refer to the command below

itsmarttricks@ubuntu:~$ ifconfig ens33   # Check IP Address of a Particular Interface
ens33     Link encap:Ethernet  HWaddr 00:0c:29:ff:cd:2e  
          inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::b396:d285:b5b3:81c3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:851 errors:0 dropped:0 overruns:0 frame:0
          TX packets:525 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:710566 (710.5 KB)  TX bytes:50788 (50.7 KB)

Create a shortlist of currently connected Ethernet Connections

To show the shortlist of current Ethernet connections you can use ifconfig command with argument -s. Here I have two Ethernet connections i.e. ens33 & lo (Localhost) Refer to the command below.

itsmarttricks@ubuntu:~$ ifconfig -s   # Short List of current Ethernet Connections
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33      1500 0       862      0      0 0           530      0      0      0 BMRU
lo        65536 0       268      0      0 0           268      0      0      0 LRU

Configure Maximum Transfer Unit (MTU) for an Ethernet Connection

MTU stands for Maximum Transfer Unit which defines how much packets an interface can transfer. You can decide and configure MTU for an Ethernet connection using ifconfig command. Here I am going to set the MTU value as 1200 for my interface ens33. Refer to the command below.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 mtu 1200    # Configure MTU for a Interface

Enable Ethernet connection using Linux ifconfig command

The ifconfig command will enable or activate an Ethernet connection. You can also use ifup ens33 command to do the same.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 up   # Enable/Activate the Ethernet Connection

Disable Ethernet connection using ifconfig command

To disable or deactivate the Ethernet connection you can use the below command. You can also use ifdown ens33 command to do the same.

itsmarttricks@ubuntu:~$ sudo ifconfig ens33 down   # Disable/Deactivate the Ethernet Connection

Also Read : How to Find Your IP Address (Public IP Address) in Ubuntu

Help commands & Manuals for Linux ifconfig command

For more information’s on ifconfig command with its arguments you can use the below command.

itsmarttricks@ubuntu:~$ ifconfig --help   # for more commands & arguments on ifconfig

OR you can read the manual page of ifconfig command using the below command.

itsmarttricks@ubuntu:~$ man ifconfig   # Manual page of ifconfig

That’s all, In this article, we have explained Best Linux Ifconfig Command With Examples. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.