15 useful “ifconfig” commands for configuring the network interface under Linux

s2 0

ifconfig In summary “Interface configuration”System / Network Management Utility in Unix / Linux Operating systems for configuring, managing, and querying network interface parameters through a command line interface or in a system configuration script.

[ You might also like: 22 Linux Networking Commands for Sysadmin ]

The “ifconfig”Command is used to view current network configuration information, set an IP address, netmask, or broadcast address for a network interface, create an alias for the network interface, set up a hardware address, and enable or disable network interfaces.

15 useful ifconfig commands

This article covers “15 useful “ifconfig” commands“With its practical examples, which can be very helpful for the administration and configuration of network interfaces in Linux systems.

To update: The network command ifconfig is obsolete and is replaced by the ip command (Learn 10 Examples of IP Commands) in most Linux distributions.

[ You might also like: ifconfig vs ip: What’s Difference and Comparing Network Configuration ]

1. Display all network interface settings

The “ifconfig”Command with no arguments shows all the details of the active interfaces. the ifconfig Command is also used to check the assigned IP address of a server.

[[email protected] ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr:172.16.25.126  Bcast:172.16.25.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)

2. Display information on all network interfaces

The following ifconfig Command with the -a -Argument shows information about all active or inactive network interfaces on the server. It shows the results for eth0, it, sit0 and do0.

[[email protected] ~]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr:172.16.25.126  Bcast:172.16.25.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)

3. View the network settings of a specific interface

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

[[email protected] ~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
          inet addr:172.16.25.126  Bcast:172.16.25.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

4. How to activate a network interface

The “high” or “ifup“Flag with interface name (eth0) activates a network interface when it is not inactive and enables information to be sent and received. For example, “ifconfig eth0 up” or “ifup eth0“Activates the eth0 Interface.

[[email protected] ~]# ifconfig eth0 up
OR
[[email protected] ~]# ifup eth0

5. How to disable a network interface

The “Low” or “ifdown“Flag with interface name (eth0) deactivates the specified network interface. For example the “ifconfig eth0 down” or “ifdown eth0”Command deactivates the eth0 Interface when it is in an inactive state.

[[email protected] ~]# ifconfig eth0 down
OR
[[email protected] ~]# ifdown eth0

6. How to assign an IP address to the network interface

To assign an IP address to a specific interface, use the following command with an interface name (eth0) and the IP address you want to set. For example, “ifconfig eth0 172.16.25.125”Sets the IP address to the interface eth0.

[[email protected] ~]# ifconfig eth0 172.16.25.125

[ You might also like: How to Configure IP Network with ‘nmtui’ Tool ]

7. How to assign a netmask to the network interface

Use of “ifconfig”Command with the“Netmask“Argument and interface name as (eth0) allows you to define a netmask for a specific interface. For example, “ifconfig eth0 netmask 255.255.255.224”Sets the network mask to a specific interface eth0.

[[email protected] ~]# ifconfig eth0 netmask 255.255.255.224

8. How to assign a broadcast to a network interface

Use of “transfer”Argument with an interface name sets the broadcast address for the specified interface. For example the “ifconfig eth0 broadcast 172.16.25.63”Command sets the broadcast address to an interface eth0.

[[email protected] ~]# ifconfig eth0 broadcast 172.16.25.63

9. This is how you assign an IP, a network mask and a broadcast to the network interface

To assign an IP address, netmask address and broadcast address at once, use the “ifconfig”Command with all of the arguments given below.

[[email protected] ~]# ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63

10. How to change the MTU for a network interface

The “man”Argument sets the maximum transmission unit on an interface. the MTU allows you to set the limit size of packets that are transmitted on an interface. the MTU is able to process a maximum number of octets to an interface in a single transaction.

For example, “ifconfig eth0 1000 people”Sets the maximum transfer unit to a certain rate (ie 1000). Not all network interfaces support MTU the settings.

[[email protected] ~]# ifconfig eth0 mtu 1000

11. How to enable promiscuous mode

What happens in normal mode, when a packet is received by a network card, it checks whether it belongs to itself. If not, the packet is normally discarded, but in promiscuous mode all packets flowing through the network card are accepted.

Today’s network tools use promiscuous mode to capture and analyze the packets flowing through the network interface. To set promiscuous mode, use the following command.

[[email protected] ~]# ifconfig eth0 promisc

12. How to turn off promiscuous mode

To deactivate promiscuous mode, use the “-promising”Switch that resets the network interface in normal mode.

[[email protected] ~]# ifconfig eth0 -promisc

13. How to add a new alias to the network interface

the ifconfig Utility allows you to configure additional network interfaces with the alias Specialty. How to add the alias network interface of the. added eth0, use the following command. Please note that 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.

[[email protected] ~]# ifconfig eth0:0 172.16.25.127

Next, check the newly created alias network interface address by typing the “ifconfig eth0: 0“Command.

[[email protected] ~]# ifconfig eth0:0

eth0:0    Link encap:Ethernet  HWaddr 00:01:6C:99:14:68
          inet addr:172.16.25.123  Bcast:172.16.25.63  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:17

14. How to remove aliases for the network interface

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

[[email protected] ~]# ifconfig eth0:0 down

15. How to change the MAC address of the network interface

To change it MAC (Media Access Control) Address of a eth0 Network interface use the following command with the argument “like ether“. See for example below.

[[email protected] ~]# ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF

These are the most useful commands for configuring network interfaces in Linux, for more information and how to use the ifconfig Command use the man pages like “Man ifconfig“At the terminal. Check out some other network utilities below.

Other network utilities

  • nmcli – a command line client used to control NetworkManager and report network information.

  • Tcmpdump – is a command line packet capture and analysis tool used to monitor network traffic.

  • Netstat – is an open source command line network monitoring tool that monitors traffic in and out of network packets.

  • ss (Socket Statistics) – a tool that prints network socket-related information on a Linux system.

  • Wireshark – is an open source network protocol analyzer used to troubleshoot network-related issues.

  • Munin – is a web based network and system monitoring application used to display results in graphs with rrdtool.

  • Cacti – is a complete web-based surveillance and graphics application for network monitoring.

For more information and options for any of the above tools, go to the man pages by clicking “Man tool name“At the command prompt. For example, to get the information for the “netstat “ Tool use the command “Man netstat“.

Tags: