ifconfig Command Examples

Network Interface Configuration Tool

⚠ Deprecation Notice: The ifconfig command is deprecated in many modern Linux distributions and has been replaced by the ip command from the iproute2 package. However, ifconfig is still widely used and available on most systems. For new scripts and automation, consider using ip addr, ip link, and ip route instead.

About ifconfig

The ifconfig (interface configuration) command is used to configure, manage, and query network interface parameters. It can display information about active network interfaces, assign IP addresses, enable or disable interfaces, and modify various network parameters. While deprecated, it remains one of the most commonly known networking commands.

Key Functions:

Note: Most ifconfig operations require root privileges. Use sudo ifconfig for configuration changes. Installation: apt install net-tools (Debian/Ubuntu) or yum install net-tools (RHEL/CentOS).

Command Syntax

ifconfig [interface] [options] [address]

Detailed Examples

Example 1: Display All Active Interfaces

ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:66a1 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:66:a1 txqueuelen 1000 (Ethernet) RX packets 1234567 bytes 890123456 (848.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 987654 bytes 123456789 (117.7 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 12345 bytes 12345678 (11.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12345 bytes 12345678 (11.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Without arguments, ifconfig displays all active network interfaces. The output includes:
  • Interface name: eth0 (Ethernet), lo (loopback), wlan0 (WiFi)
  • Flags: Interface status (UP means active, RUNNING means operational)
  • inet: IPv4 address and netmask
  • inet6: IPv6 address
  • ether: MAC address
  • MTU: Maximum Transmission Unit (packet size)
  • RX/TX statistics: Packets and bytes received/transmitted
  • Errors: Dropped packets, collisions, and other issues
Tip: The loopback interface (lo) is always present and used for local network connections within the machine itself (localhost/127.0.0.1).

Example 2: Display Specific Interface

ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a00:27ff:fe4e:66a1 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4e:66:a1 txqueuelen 1000 (Ethernet) RX packets 1234567 bytes 890123456 (848.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 987654 bytes 123456789 (117.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Displays configuration and statistics for only the eth0 interface. This is useful for:
  • Focusing on a specific network adapter
  • Troubleshooting connectivity issues
  • Monitoring traffic on one interface
  • Verifying configuration changes
Common interface names include: eth0/eth1 (Ethernet), wlan0 (WiFi), enp3s0 (predictable network names), lo (loopback).

Example 3: Display All Interfaces (Including Inactive)

ifconfig -a
The -a option displays all interfaces, including those that are currently down/inactive:
  • Shows disabled network adapters
  • Lists all available hardware interfaces
  • Useful for inventory and troubleshooting
  • Helps identify interfaces that need to be brought up
This is particularly useful when trying to enable a network interface that's currently down.
Note: An interface shown with ifconfig -a but not with ifconfig (without options) is in the DOWN state and not currently active.

Example 4: Assign IP Address to Interface

sudo ifconfig eth0 192.168.1.150
Assigns the IP address 192.168.1.150 to the eth0 interface. This command:
  • Requires root/sudo privileges
  • Takes effect immediately (no reboot required)
  • Changes are temporary (lost on reboot unless saved in network config)
  • Can be used for quick testing or temporary reconfiguration
To verify the change: ifconfig eth0 | grep inet
Warning: This change is temporary and will be lost after reboot. To make permanent changes, edit network configuration files (e.g., /etc/network/interfaces or use NetworkManager/netplan).

Example 5: Assign IP Address with Netmask

sudo ifconfig eth0 192.168.1.150 netmask 255.255.255.0
Assigns both IP address and subnet mask. The netmask defines the network portion of the address:
  • 255.255.255.0 = /24 CIDR = Class C network (254 usable hosts)
  • 255.255.0.0 = /16 CIDR = Class B network (65,534 usable hosts)
  • 255.0.0.0 = /8 CIDR = Class A network (16,777,214 usable hosts)
The netmask determines which portion of the IP address identifies the network vs. the host.
Tip: You can also specify the netmask using CIDR notation: ip addr add 192.168.1.150/24 dev eth0 (using the newer ip command).

Example 6: Bring Interface Up

sudo ifconfig eth0 up
Activates (brings up) the eth0 interface. This command:
  • Enables the network interface
  • Allows the interface to send/receive packets
  • Required after interface configuration changes
  • Necessary for connecting to the network
You can verify the interface is up by checking for the "UP" flag in ifconfig eth0 output.

Common workflow:

sudo ifconfig eth0 down # Disable interface
sudo ifconfig eth0 192.168.1.150 netmask 255.255.255.0
sudo ifconfig eth0 up # Enable interface

Example 7: Bring Interface Down

sudo ifconfig eth0 down
Deactivates (brings down) the eth0 interface. Use cases include:
  • Temporarily disabling network connectivity
  • Preparing for configuration changes
  • Troubleshooting network issues
  • Security: Disconnecting from untrusted networks
  • Testing failover configurations
The interface remains configured but won't send/receive packets until brought back up.
Warning: If you're connected remotely (SSH), bringing down the network interface you're connected through will disconnect you immediately!

Example 8: Change MTU Size

sudo ifconfig eth0 mtu 9000
Sets the Maximum Transmission Unit (MTU) to 9000 bytes, creating a "jumbo frame" configuration. MTU considerations:
  • Standard MTU: 1500 bytes (Ethernet default)
  • Jumbo frames: 9000 bytes (requires hardware support)
  • Benefits: Reduced overhead, better performance for large transfers
  • Requirements: All devices in path must support larger MTU
  • Use case: Storage networks, data center interconnects
Mismatched MTU settings can cause packet fragmentation and performance issues.
Note: To find optimal MTU: ping -M do -s 8972 192.168.1.1 (test with 8972 + 28 = 9000 total). If packets are fragmented, reduce size.

Example 9: Change MAC Address

sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
Changes the hardware (MAC) address of the interface. This is also called "MAC spoofing":
  • Step 1: Interface must be brought down first
  • Step 2: Set new MAC address with hw ether
  • Step 3: Bring interface back up
Use cases include:
  • Privacy enhancement
  • Testing network security policies
  • Replacing failed network hardware
  • Bypassing MAC-based access restrictions (with authorization)
Warning: Changing MAC addresses may violate network policies or terms of service. Only change MAC addresses on networks you own or have explicit permission to test.

Example 10: Configure Complete Interface Setup

#!/bin/bash
# Complete network interface configuration script

INTERFACE="eth0"
IP_ADDRESS="192.168.1.150"
NETMASK="255.255.255.0"
BROADCAST="192.168.1.255"

echo "Configuring $INTERFACE..."

# Bring interface down
sudo ifconfig $INTERFACE down

# Configure IP, netmask, and broadcast
sudo ifconfig $INTERFACE $IP_ADDRESS netmask $NETMASK broadcast $BROADCAST

# Set MTU for standard Ethernet
sudo ifconfig $INTERFACE mtu 1500

# Bring interface up
sudo ifconfig $INTERFACE up

# Display configuration
echo "Configuration complete:"
ifconfig $INTERFACE

# Test connectivity
ping -c 3 192.168.1.1 && echo "Gateway reachable" || echo "Gateway unreachable"
This comprehensive script demonstrates a complete network configuration workflow:
  • Uses variables for easy modification
  • Brings interface down for safe reconfiguration
  • Sets IP address, netmask, and broadcast address
  • Configures MTU size
  • Brings interface back up
  • Displays final configuration
  • Tests connectivity to gateway
This pattern is commonly used in system administration scripts and network provisioning automation.

Understanding Network Parameters

Interface Flags Explained

Flag Meaning
UP Interface is enabled and active
BROADCAST Interface supports broadcasting
RUNNING Interface is operational (driver loaded, cable connected)
MULTICAST Interface supports multicast
LOOPBACK Loopback interface (lo)
PROMISC Promiscuous mode (receives all packets, not just addressed to it)

Common Network Interface Names

Interface Name Description
lo Loopback interface (127.0.0.1)
eth0, eth1 Traditional Ethernet interface names
wlan0, wlan1 Wireless network interfaces
enp3s0, eno1 Predictable network interface names (modern systems)
docker0 Docker bridge interface
tun0, tap0 Virtual network interfaces (VPNs)
br0 Bridge interface

Migration from ifconfig to ip Command

ifconfig Command Equivalent ip Command
ifconfig ip addr show
ifconfig eth0 ip addr show eth0
ifconfig eth0 192.168.1.150 ip addr add 192.168.1.150/24 dev eth0
ifconfig eth0 up ip link set eth0 up
ifconfig eth0 down ip link set eth0 down
ifconfig eth0 mtu 9000 ip link set eth0 mtu 9000
ifconfig -a ip link show

Troubleshooting Network Issues

Diagnostic Commands Workflow

# 1. Check interface status
ifconfig eth0

# 2. Verify interface is UP
ifconfig eth0 | grep UP

# 3. Check for errors and dropped packets
ifconfig eth0 | grep -E "RX|TX"

# 4. Test connectivity to gateway
ping -c 3 192.168.1.1

# 5. Check routing table
route -n

# 6. Test DNS resolution
nslookup google.com

# 7. Check if physical cable is connected
ethtool eth0 | grep "Link detected"

Common Issues and Solutions

Issue: Interface has no IP address

Symptoms: No inet/inet6 line in ifconfig output

Solutions:
  • Manually assign IP: sudo ifconfig eth0 192.168.1.150 netmask 255.255.255.0
  • Request DHCP address: sudo dhclient eth0
  • Check if interface is up: sudo ifconfig eth0 up
  • Verify network cable is connected
  • Check if DHCP server is available on network

Issue: High number of RX/TX errors

Symptoms: Non-zero values in RX errors, TX errors, or dropped fields

Possible causes:
  • Faulty network cable
  • Bad network switch port
  • Duplex mismatch (half vs. full duplex)
  • MTU mismatch
  • Network interface hardware issues
Solutions:
  • Replace network cable
  • Try different switch port
  • Check duplex settings: ethtool eth0
  • Reset interface: sudo ifconfig eth0 down && sudo ifconfig eth0 up

Issue: Cannot reach network despite correct configuration

Solutions:
  • Check default gateway: route -n
  • Add default gateway: sudo route add default gw 192.168.1.1
  • Verify DNS settings: cat /etc/resolv.conf
  • Test with IP first, then domain names to isolate DNS issues
  • Check firewall rules: sudo iptables -L -n

Security Considerations

Promiscuous Mode Warning: Setting an interface to promiscuous mode (ifconfig eth0 promisc) allows it to capture all network traffic, not just packets addressed to it. This should only be used for legitimate network analysis and requires proper authorization.
Security Tip: Regularly monitor for unexpected changes in network configuration. Unauthorized MAC address changes or IP assignments could indicate a security compromise.
Best Practice: Always document network configuration changes. Use version control for network configuration scripts and maintain an inventory of all network interfaces and their purposes.

Performance Monitoring

Continuous Monitoring Script

#!/bin/bash
# Monitor network interface statistics

INTERFACE="eth0"

while true; do
clear
echo "=== Network Statistics for $INTERFACE ==="
echo "Time: $(date)"
echo ""
ifconfig $INTERFACE | grep -E "RX|TX|packets|bytes"
echo ""
echo "Press Ctrl+C to stop"
sleep 2
done
This script provides real-time monitoring of network statistics, refreshing every 2 seconds.

Related Commands