Linux ifconfig Command Examples

The ifconfig command in Linux is used to configure, manage, and display network interface parameters. It allows users to view network interface details, assign IP addresses, enable or disable interfaces, and more. Below are 10 examples demonstrating various uses of the ifconfig command with detailed explanations.

Note: ifconfig is considered deprecated in many modern Linux distributions, replaced by ip commands (e.g., ip addr). However, it is still available in many systems. Install it using sudo apt install net-tools (Debian/Ubuntu) or sudo yum install net-tools (CentOS/RHEL) if needed.
Warning: Some ifconfig commands require root privileges. Use sudo where necessary, and be cautious when modifying network settings to avoid connectivity loss.

Example 1: Display All Network Interfaces

ifconfig

Displays configuration details for all active network interfaces, including IP addresses, MAC addresses, and status.

Sample Output:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICASTGt;  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 00:1a:2b:3c:4d:5e  txqueuelen 1000  (Ethernet)
        RX packets 12345  bytes 9876543 (9.8 MB)
        TX packets 6789  bytes 1234567 (1.2 MB)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)

Explanation: Shows details for eth0 (Ethernet) and lo (loopback), including IP address, netmask, and packet statistics.

Example 2: Display Specific Interface

ifconfig eth0

Shows configuration details for the specified network interface (eth0).

Sample Output:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 00:1a:2b:3c:4d:5e  txqueuelen 1000  (Ethernet)

Explanation: Limits output to the eth0 interface, useful for focusing on a single interface.

Example 3: Enable a Network Interface

sudo ifconfig eth0 up

Activates the eth0 interface, enabling network connectivity.

Sample Output: No output unless an error occurs. The interface status changes to UP.

Explanation: Useful for bringing up an interface that was previously disabled.

Example 4: Disable a Network Interface

sudo ifconfig eth0 down

Disables the eth0 interface, stopping network activity.

Sample Output: No output unless an error occurs. The interface status changes to not include UP.

Explanation: Useful for troubleshooting or temporarily disconnecting an interface.

Warning: Disabling an active interface may disrupt network connectivity.

Example 5: Assign a Static IP Address

sudo ifconfig eth0 192.168.1.150 netmask 255.255.255.0

Assigns the IP address 192.168.1.150 and netmask 255.255.255.0 to the eth0 interface.

Sample Output: No output unless an error occurs. Verify with ifconfig eth0.

Explanation: Sets a static IP temporarily (until reboot or network restart). Persistent changes require editing network configuration files.

Example 6: Display All Interfaces, Including Inactive

ifconfig -a

Lists all network interfaces, including those that are down or inactive.

Sample Output:

eth0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:1a:2b:3c:4d:5e  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)

Explanation: Shows all interfaces, even those without an IP address or not currently active.

Example 7: Change MTU Size

sudo ifconfig eth0 mtu 1400

Sets the Maximum Transmission Unit (MTU) size for eth0 to 1400 bytes.

Sample Output: No output unless an error occurs. Verify with ifconfig eth0, which shows mtu 1400.

Explanation: Adjusting MTU can optimize network performance for specific networks (e.g., to avoid fragmentation).

Example 8: Enable Promiscuous Mode

sudo ifconfig eth0 promisc

Enables promiscuous mode on eth0, allowing the interface to capture all network traffic, not just packets destined for it.

Sample Output: No output. Verify with ifconfig eth0, which includes PROMISC in flags.

Explanation: Useful for network monitoring or packet sniffing (e.g., with tcpdump).

Note: Disable with sudo ifconfig eth0 -promisc.

Example 9: Display Brief Output

ifconfig -s

Shows a short, tabular summary of interface statistics, including MTU, RX/TX packets, and errors.

Sample Output:

Iface   MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0    1500   12345      0      0      0     6789      0      0      0 BRU
lo     65536    1234      0      0      0     1234      0      0      0 LRU

Explanation: Provides a compact overview, ideal for quick checks or scripts.

Example 10: Combine with grep for Specific Information

ifconfig eth0 | grep inet

Filters ifconfig output to show only lines containing IP address information for eth0.

Sample Output:

        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255

Explanation: Extracts IP-related details, useful for scripts or quick IP address checks.

Additional Tips:

Note: Interface names (e.g., eth0, wlan0) may vary depending on the system. Check the man page (man ifconfig) for additional options and details specific to your system.