Linux ifconfig command
The ifconfig
command in Linux is used to configure, display, and manage network interfaces. While it is deprecated in favor of the ip
command on modern systems, ifconfig
is still widely used and available on many Linux distributions. Below is an explanation of the ifconfig
command with commonly used options and examples of its output.
Basic Syntax of ifconfig
interface
: The name of the network interface (e.g.,eth0
,wlan0
,lo
).options
: Specific flags or arguments to modify or display certain network interface settings.
Common Options for ifconfig
1. Display Network Interfaces
- To display all active network interfaces on your system:
- Example Output:
- Explanation of fields:
flags
: Indicates the status and features of the interface (e.g., UP, RUNNING, BROADCAST, etc.).inet
: The IPv4 address assigned to the interface.netmask
: The subnet mask.broadcast
: The broadcast address for the network.ether
: The MAC address of the network interface.RX packets
: Number of received packets.TX packets
: Number of transmitted packets.
2. Display Specific Interface Information
- To display the information for a specific interface (e.g.,
eth0
): - Example Output:
3. Enable/Disable an Interface
- To enable or bring up a network interface (e.g.,
eth0
): - To disable or bring down a network interface:
4. Assign an IP Address to an Interface
- To assign a static IP address to a network interface (
eth0
in this case): - This assigns the IP
192.168.1.100
toeth0
and brings the interface up.
5. Change the MAC Address
- To change the MAC address of an interface:
- This changes the MAC address of
eth0
to00:11:22:33:44:55
.
6. Set the MTU (Maximum Transmission Unit)
- To change the MTU for an interface (e.g.,
eth0
): - This sets the MTU of
eth0
to1500
bytes, which is typical for Ethernet connections.
7. View or Change Network Settings (Broadcast Address, IP, Netmask, etc.)
- To change the broadcast address of an interface:
- To change the netmask:
8. View the ARP Cache
- To view the ARP (Address Resolution Protocol) cache, which maps IP addresses to MAC addresses:
9. Display Interface Statistics
- To display additional statistics about network interfaces, including packet counts, errors, and collisions:
- Example Output:
10. Set a Network Interface to DHCP
- To configure a network interface (
eth0
) to obtain an IP address automatically using DHCP:
Example of Using ifconfig
Let’s go through an example where we configure a network interface.
1. Display the Current Network Interfaces
- Output:
2. Assign a New IP Address
- After executing the command, the
eth0
interface will have the new IP address192.168.1.200
.
3. Verify the Change
- Output (new IP):
4. Disable the Interface
Summary of Common ifconfig
Options:
Option | Description |
---|---|
ifconfig | Display all active interfaces |
ifconfig [interface] | Display details of a specific interface |
ifconfig [interface] up | Enable a specific network interface |
ifconfig [interface] down | Disable a specific network interface |
ifconfig [interface] [IP] | Assign a static IP address to an interface |
ifconfig [interface] mtu [size] | Set the Maximum Transmission Unit (MTU) |
ifconfig -a | Show all interfaces (including inactive ones) |
ifconfig -s | Show summary statistics for all interfaces |
While ifconfig
is widely used, remember that it is being replaced by the more powerful ip
command on many modern Linux systems. However, ifconfig
is still an important tool for understanding and managing basic network configurations.