Sunday, September 25, 2022

How To Use ifconfig command on Linux

In this article, we want to teach you How To Use the ifconfig command on Linux.

The ifconfig command can be used from the command line either to assign an address to a network interface or to configure or display the current network interface configuration information.

It must be used at system startup to define the network address of each interface present on a machine.

Also, it can be used at a later time to redefine an interface’s address or other operating parameters.

The network interface configuration is held on the running system and must be reset at each system restart.

How To Use ifconfig command on Linux

To use the ifconfig command, you need to log in to your Linux server as a root user or a non-root user with sudo privileges.

Now follow the steps below to learn the usage of the ifconfig command on Linux.

Usage of the ifconfig command on Linux

To view all the active interfaces details and check the assigned IP address of a server, you can use the following command with no arguments:

ifconfig

In your output you will see something similar to this:

Output
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet  netmask  broadcast 
inet6 2a04:9dc0:c1:144:0:1:907:c40b prefixlen 26 scopeid 0x0<global>
inet6 fe80::216:3eff:fe76:a15a prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:76:a1:5a txqueuelen 1000 (Ethernet)
RX packets 1586380 bytes 222116758 (211.8 MiB)
RX errors 26061 dropped 0 overruns 0 frame 26061
TX packets 206445 bytes 32345008 (30.8 MiB)
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 19 bytes 2360 (2.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19 bytes 2360 (2.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Also, you can use the ifconfig command on Linux with the -a option to view information of all active or inactive network interfaces on the server:

ifconfig -a

Now, you can use the command below to display details of a specific network interface. For example:

ifconfig eth0

To enable a network interface, you can use the following command with the “up” or “ifup” options. For example:

# ifconfig eth0 up
Or
# ifup eth0

This command will activate the eth0 network interface.

On the other hand, you can use the ifconfig command on Linux to disable a network interface with the “down” or “ifdown” options:

# ifconfig eth0 down
Or
# ifdown eth0

Next, you can assign an IP address to a network interface. For example:

ifconfig eth0 172.16.25.125

This will set the IP address to the eth0 network interface.

Also, you can assign a Netmask to a network interface. For example, you can set a netmask to a given interface eth0:

ifconfig eth0 netmask 255.255.255.224

You can assign a broadcast to a network interface too. For example, you can use the ifconfig command on Linux to set the broadcast address to an interface eth0:

ifconfig eth0 broadcast 172.16.25.63

At this point, you can use three commands in a single command to assign an IP, a Netmask, and broadcast to a network interface. For example:

ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63

To change the MAC address of a network interface you can use the following command with the “hw ether“ option. For example:

ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF

Change MTU for a Network Interface with the ifconfig command

The maximum transmission unit (MTU) is the largest size frame or packet — in bytes or octets (eight-bit bytes) — that can be transmitted across a data link. It is mostly used in reference to packet size on an Ethernet network using the Internet Protocol (IP).

For example, you can use the ifconfig command on Linux to set the MTU to a given set (i.e. 1000):

ifconfig eth0 mtu 1000

Enable Promiscuous Mode with the ifconfig command

Promiscuous mode is a type of computer networking operational mode in which all network data packets can be accessed and viewed by all network adapters operating in this mode. It is a network security, monitoring, and administration technique that enables access to entire network data packets by any configured network adapter on a host system.

For example, to set the promiscuous mode for the eth0 network interface, use the following command:

ifconfig eth0 promisc

Also, you can disable the promiscuous mode with the command below:

ifconfig eth0 -promisc

Add New Alias to Network Interface

The ifconfig command allows you to configure additional network interfaces using the alias feature.

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

For example, if your eth0 network ip address is 172.16.25.125, then the alias ip address must be 172.16.25.127.

To add the alias network interface of eth0, use the following command:

ifconfig eth0:0 172.16.25.127

You can verify your new alias network interface address with the command below:

ifconfig eth0:0

Also, you can remove it with the command below:

ifconfig eth0:0 down

Conclusion

At this point, you learn How to Use the ifconfig command on Linux.

With the Linux commands you learn to assign an IP address, netmask, broadcast to a network interface and etc.

Hope you enjoy it.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular