Linux ifconfig Command

Linux ifconfig Command

interface configuration, abbreviated as ifconfig, is a tool that provides network management in Unix/Linux operating systems. Through ifconfig, you can configure network interface parameters, check the status of active system interfaces, and define queries for network interface parameters. Also, by using the ifconfigh command, you can assign IP addresses to network interfaces, you will be able to activate and deactivate network interfaces, and also control and manage ARP cache, and routes efficiently.

Using the ifconfig command, you can do the following:

  • Management and configuration of network interfaces
  • Access to network configuration information
  • Hardware address setting
  • Netmask or broadcast address on a network interface
  • Initialization of network interfaces
  • Enable and disable network interfaces
  • IP address settings
  • Viewing the status of network interfaces

When using a Linux VPS, the ifconfig command is often helpful for managing network interfaces when setting up, debugging, and configuring a Linux system. Therefore, getting to know this command and how to use the ifconfig command will make it easier for you to manage and configure the network interface. Be with us to learn how to use the ifconfig command in Linux systems.

Installing  ifconfig

Newer Linux distributions may not support the ifconfig tool by default because the ifconfig command was recently deprecated and ip is used as its replacement.

Displaying the message “ifconfig: command not found” after executing the ifconfig command means that your system does not have the package containing the command, so you must install the package containing the ifconfig command on the system.

  • Installing ifconfig on Ubuntu/Debian

If you want to install ifconfig on Ubuntu/Debian-based distributions, enter the following command:

sudo apt install net-tools –y
  • Installing ifconfig on CentOS

If you want to install ifconfig on RHEL and CentOS-based distributions, run the following command:

sudo dnf install net-tools –y

How to use the ifconfig command

The main syntax of the ifconfigh command is as follows:

ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]

Interface: Place the name of the network interface in this field.

Address: Specify the IP address you intend to assign.

Note: you must have root or sudo user privileges to configure network interfaces. Remember that the settings you make using the ifconfig command are unstable and will return to the initial state when the system is restarted. so if you want your changes to be saved, you need to add commands to the startup script or make changes to the distribution-specific configuration files.

  • Display the general settings of the network interface

If you run the “ifconfig” command without arguments, it will provide complete information about the active network interfaces, and you can also check the IP address associated with a server using the “ifconfig” command.

ifconfig

Output:

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr: 172.18.26.123   Bcast: 172.18.26.63   Mask:255.255.255.224
          inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2341604 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2217673 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:293460932 (279.8 MiB)  TX bytes:1042006549 (993.7 MiB)
          Interrupt:185 Memory:f7fe0000-f7ff0000
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:16436  Metric:1
          RX packets:5019066 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5019066 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2174522634 (2.0 GiB)  TX bytes:2174522634 (2.0 GiB)
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.1.1.1  P-t-P:10.1.1.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  • Display network interface information

To access complete information about network interfaces, both active and inactive on the server, invoke the “ifconfig” command with the -a argument:

ifconfig –a

Output:

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr:172.18.26.123  Bcast:172.18.26.63  Mask:255.255.255.224
          inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2344927 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2220777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:293839516 (280.2 MiB)  TX bytes:1043722206 (995.3 MiB)
          Interrupt:185 Memory:f7fe0000-f7ff0000
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:16436  Metric:1
          RX packets:5022927 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5022927 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2175739488 (2.0 GiB)  TX bytes:2175739488 (2.0 GiB)
sit0      Link encap:IPv6-in-IPv4
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.1.1.1  P-t-P:10.1.1.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  • View the network settings of the specified interface

To have the output of the “ifconfig” command provide configuration information for each network interface, run the “ifconfig” command with the interface name (eg, eth0) as an argument:

ifconfig eth0

Output:

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr: 172.18.26.123   Bcast: 172.18.26.63   Mask:255.255.255.224
          inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2345583 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2221421 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:293912265 (280.2 MiB)  TX bytes:1044100408 (995.7 MiB)
          Interrupt:185 Memory:f7fe0000-f7ff0000
  • Enable and disable the network interface

Next to the name of the specified network interface, if it is inactive, execute flag “up” or “ifup”, the network interface will be activated and the activation of the network interface will enable data transfer. For example, running the following commands will enable the eth0 interface:

ifconfig eth0 up

Or

ifup eth0

And to disable the specified network interface, if the specified interface is active, you must execute the “down” or “ifdown” flag next to the interface name (For example,eth0) as follows :

ifconfig eth0 down

Or

ifdown eth0

In the command we executed, the network interface eth0 is considered as an example.

  • Enable and disable Promiscuous mode

To allow a network interface to access all packets on the network, you must enable promiscuous mode. Promiscuous mode is very efficient for today’s network tools in analyzing the packets flowing through the network interface. The ifconfig command can enable and disable promiscuous mode on a specific network device.

To enable promiscuous mode for a network interface (for example, eth0), run the following command:

ifconfig eth0 promisc

Use the “-promisc” flag to return the specified network interface to normal mode and disable promiscuous mode:

ifconfig eth0 -promisc
  • Assigning an IP address and Netmask to the Network Interface

One of the functions of the ifconfig command is to assign an IP address and Netmask to a specific network interface.

You can assign the IP address and netmask to a specific network interface using the following syntax:

ifconfig [interface-name] [ip-address] netmask [subnet-mask]

For example, to assign an IP address (172.18.26.124) to the network interface (eth0), enter the following command :

ifconfig eth0 172.18.26.124

Or to define the netmask for a specific interface (eth0), consider the following pattern:

ifconfig eth0 netmask 255.255.255.224
  • Assigning a Broadcast to the network interface

To set a broadcast address for a specific network interface (for example, eth0) use the following pattern:

ifconfig eth0 broadcast 172.18.26.63   

If you want to assign an IP Address, Netmask and Broadcast to a network interface, use the following example:

ifconfig eth0172.18.26.124 netmask 255.255.255.224 broadcast 172.18.26.63  
  • Changing the MTU for a network interface

MTU, which stands for Maximum Transmission Unit, is used to limit the size of packets that are sent on a network interface, and also manages the maximum number of octets to an interface in a transaction.

To change the MTU value, use the following syntax:

ifconfig [interface-name] mtu [mtu-value]

For example, if you want to set the MTU value of the eth0 network interface to a specific set (for example, 1000), use the following command:

ifconfig eth0 mtu 1000

Note that it is not possible to set the MTU value for all network interfaces.

  • Changing the MAC address of the network interface

Media Access Control, or MAC for short, is a unique physical address that is assigned to devices connected to the network and identifies devices connected to the network. To change the MAC address to the new address of a network interface, run the following command:

ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF
  • Add and Remove New Alias to the network interface

Using the ifconfig command, you can set additional network interfaces with the Alias feature.

For example, to add the alias network interface of eth0, run the following command:

ifconfig eth0:0 [alias ip address]

Note: the network address of the alias is in the subnet mask.

Then use the “ifconfig eth0:0 down” command to verify the address of the new alias network interface you created.

To remove the network interface alias, if it is not needed, run the following command:

ifconfig eth0:0 down

FAQ

The ifconfig command displays the details of the active and inactive network interfaces of the Linux system, and you can use it to manage and configure the network interfaces. You can also view the device names of the interfaces of a system, the status of active system interfaces, and the IPv4 and IPv6 addresses assigned to the interfaces, in addition, you can enable and disable network interfaces and manage the ARP cache, and route.

To set a new IP for your network interface, run the following command:

ifconfig interface_name IP_address

Replace the name of the network interface you want in the interface_name field and replace the IP you want to assign to the network interface in the IP_address field.

Usually, the information is presented on the right side of the output, and on the left side, eth0, wlan0, and lo are the names of the network interfaces. The eth0 interface is the first Ethernet card in the machine, wlan0 is the wireless interface, and lo is the ring interface.

Summary

In this tutorial, we tried to provide useful commands for configuring network interfaces in a Linux system. We also guided you on how to use the ifconfig command to configure and view network interface information.

We hope our tutorial is Practical for you. If you have any questions in this field, share them with us in the comments section, and you can also get more information about the ifconfig command by referring to the ifconfig command man page or using “man ifconfig” in the terminal environment.

 

Leave a Reply

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