Introduction
The Linux operating system provides a powerful command line interface (CLI) tool called ifconfig that can be used to configure network interfaces. This tool is used to configure, manage, and query network interface parameters such as IP address, subnet mask, broadcast address, and more. In this article, we will discuss 15 useful ifconfig commands that can be used to configure network interfaces in Linux. We will also discuss how to use these commands to troubleshoot network issues.
15 Useful “ifconfig” Commands to Configure Network Interface in Linux
1. ifconfig: Display all network interfaces and their configuration.
2. ifconfig eth0: Display the configuration of the eth0 interface.
3. ifconfig eth0 up: Activate the eth0 interface.
4. ifconfig eth0 down: Deactivate the eth0 interface.
5. ifconfig eth0 192.168.1.10: Assign the IP address 192.168.1.10 to the eth0 interface.
6. ifconfig eth0 netmask 255.255.255.0: Assign the netmask 255.255.255.0 to the eth0 interface.
7. ifconfig eth0 broadcast 192.168.1.255: Assign the broadcast address 192.168.1.255 to the eth0 interface.
8. ifconfig eth0 mtu 1500: Assign the MTU size 1500 to the eth0 interface.
9. ifconfig eth0 hw ether 00:11:22:33:44:55: Assign the MAC address 00:11:22:33:44:55 to the eth0 interface.
10. ifconfig eth0 promisc: Enable promiscuous mode on the eth0 interface.
11. ifconfig eth0 -promisc: Disable promiscuous mode on the eth0 interface.
12. ifconfig eth0 txqueuelen 1000: Set the transmit queue length to 1000 for the eth0 interface.
13. ifconfig eth0 -arp: Disable ARP on the eth0 interface.
14. ifconfig eth0 arp: Enable ARP on the eth0 interface.
15. ifconfig eth0 -allmulti: Disable all multicast on the eth0 interface.
ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage, and query network interface parameters via command-line interface or in a system configuration scripts.
The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask, or broadcast address to a network interface, creating an alias for the network interface, setting up hardware address, and enabling or disabling network interfaces.
This article covers 15 useful “ifconfig” commands with their practical examples, which might be very helpful to you in managing and configuring network interfaces in Linux systems.
1. List Network Interfaces in Linux
The “ifconfig” command with no arguments will display all the active network interface configuration details that includes their assigned IP addresses, netmasks, and other relevant information.
$ ifconfig
Sample Output:
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 will display information on all active or inactive network interfaces on the server. It displays the results for eth0, lo, sit0, and tun0.
# 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 Network Settings of Specific Interface
Using interface name (eth0) as an argument with the “ifconfig” command will display details of the specific network interface.
# 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 Enable a Network Interface
The “up” or “ifup” flag with interface name (eth0) activates a network interface if it is not inactive state and allows to send and receive information.
For example, “ifconfig eth0 up” or “ifup eth0” will activate the eth0 interface.
# ifconfig eth0 up OR # ifup eth0
5. How to Disable a Network Interface
The “down” 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 if it is in an inactive state.
# ifconfig eth0 down OR # ifdown eth0
6. How to Assign an IP Address to Network Interface
To assign an IP address to a specific interface, use the following command with an interface name (eth0) and ip address that you want to set. For example, “ifconfig eth0 172.16.25.125” will set the IP address to interface eth0.
# ifconfig eth0 172.16.25.125
7. How to Assign a Netmask to Network Interface
Using the “ifconfig” command with the “netmask” argument and interface name as (eth0) allows you to define a netmask to a given interface. For example, “ifconfig eth0 netmask 255.255.255.224” will set the network mask to a given interface eth0.
[[email protected] ~]# ifconfig eth0 netmask 255.255.255.224
8. How to Assign a Broadcast to Network Interface
Using the “broadcast” argument with an interface name will set the broadcast address for the given interface. For example, the “ifconfig eth0 broadcast 172.16.25.63” command sets the broadcast address to an interface eth0.
# ifconfig eth0 broadcast 172.16.25.63
9. How 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 as given below.
# ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63
10. How to Change MTU for a Network Interface
The “mtu” argument sets the maximum transmission unit to an interface. The MTU allows you to set the limit size of packets that are transmitted on an interface. The MTU is able to handle a maximum number of octets to an interface in one single transaction.
For example, “ifconfig eth0 mtu 1000” will set the maximum transmission unit to a given set (i.e. 1000). Not all network interfaces support MTU settings.
# ifconfig eth0 mtu 1000
11. How to Enable Promiscuous Mode
What happens in normal mode, is when a packet is received by a network card, it verifies that it belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is used to accept all the packets that flow through the network card.
Today’s network tools use the promiscuous mode to capture and analyze the packets that flow through the network interface. To set the promiscuous mode, use the following command.
# ifconfig eth0 promisc
12. How to Disable Promiscuous Mode
To disable promiscuous mode, use the “-promisc” switch that drops back the network interface to normal mode.
# ifconfig eth0 -promisc
13. How to Add New Alias to Network Interface
The ifconfig utility allows you to configure additional network interfaces using the alias feature. To add the alias network interface of 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.
# ifconfig eth0:0 172.16.25.127
Next, verify the newly created alias network interface address, by using the “ifconfig eth0:0” command.
# 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 Alias to 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.
# ifconfig eth0:0 down
15. How to Change the MAC address of Network Interface
To change the MAC (Media Access Control) address of an eth0 network interface, use the following command with the argument “hw ether“. For example, see below.
# 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 usage of the ifconfig command use the manpages like “man ifconfig” at the terminal. Check out some other networking utilities below.
Other Networking Utilities
- nmcli – a command-line client that is used to control NetworkManager and report network information.
- Tcmpdump – is a command-line packet capture and analyzer tool for monitoring network traffic.
- Netstat – is an open-source command-line network monitoring tool that monitors incoming and outgoing network packet traffic.
- ss (socket statistics) – a tool that prints network socket-related information on a Linux system.
- Wireshark – is an open-source network protocol analyzer that is used to troubleshoot network-related issues.
- Munin – is a web-based network and system monitoring application that is used to display results in graphs using rrdtool.
- Cacti – is a complete web-based monitoring and graphing application for network monitoring.
To get more information and options for any of the above tools, see the man pages by entering “man toolname” at the command prompt. For example, to get the information for the “netstat” tool, use the command “man netstat“.
15 Useful “ifconfig” Commands to Configure Network Interface in Linux
The ifconfig command is a powerful tool for configuring network interfaces in Linux. It is used to view and change the configuration of the network interfaces on your system. In this article, we will discuss some of the most commonly used ifconfig commands.
1. Display Network Interface Configuration
The most basic use of ifconfig is to display the configuration of all network interfaces on the system. To do this, simply run the command without any arguments:
$ ifconfig
2. Display Specific Network Interface Configuration
You can also use ifconfig to display the configuration of a specific network interface. To do this, simply specify the name of the interface as an argument:
$ ifconfig eth0
3. Enable a Network Interface
If a network interface is disabled, you can use ifconfig to enable it. To do this, use the “up” flag:
$ ifconfig eth0 up
4. Disable a Network Interface
You can also use ifconfig to disable a network interface. To do this, use the “down” flag:
$ ifconfig eth0 down
5. Set an IP Address
You can use ifconfig to set an IP address for a network interface. To do this, use the “inet” flag:
$ ifconfig eth0 inet 192.168.1.100
6. Set a Netmask
You can also use ifconfig to set a netmask for a network interface. To do this, use the “netmask” flag:
$ ifconfig eth0 netmask 255.255.255.0
7. Set a Broadcast Address
You can use ifconfig to set a broadcast address for a network interface. To do this, use the “broadcast” flag:
$ ifconfig eth0 broadcast 192.168.1.255
8. Set a Destination Address
You can also use ifconfig to set a destination address for a network interface. To do this, use the “destination” flag:
$ ifconfig eth0 destination 192.168.1.1
9. Set a Network Interface MTU
You can use ifconfig to set the Maximum Transmission Unit (MTU) for a network interface. To do this, use the “mtu” flag:
$ ifconfig eth0 mtu 1500
10. Set a Network Interface Metric
You can also use ifconfig to set the metric for a network interface. To do this, use the “metric” flag:
$ ifconfig eth0 metric 1
11. Set a Network Interface Flags
You can use ifconfig to set flags for a network interface. To do this, use the “flags” flag:
$ ifconfig eth0 flags 0x10
12. Set a Network Interface HW Address
You can also use ifconfig to set the hardware address (MAC address) for a network interface. To do this, use the “hw” flag:
$ ifconfig eth0 hw ether 00:11:22:33:44:55
13. Set a Network Interface MTU Lock
You can use ifconfig to lock the MTU for a network interface. To do this, use the “mtu_lock” flag:
$ ifconfig eth0 mtu_lock on
14. Set a Network Interface ARP Lock
You can also use ifconfig to lock the ARP for a network interface. To do this, use the “arp_lock” flag:
$ ifconfig eth0 arp_lock on
15. Set a Network Interface Promiscuous Mode
You can use ifconfig to enable promiscuous mode for a network interface. To do this, use the “promisc” flag:
$ ifconfig eth0 promisc
These are just some of the most commonly used ifconfig commands. For more information, consult the ifconfig man page.