ifconfig Command – Manage Network Interfaces
The ifconfig (interface configuration) command is a legacy yet widely-used utility in Unix-like operating systems (e.g., Linux, FreeBSD) for configuring and troubleshooting network interfaces. It allows you to:
- View network interface details (IP address, MAC address, traffic stats).
- Assign IP addresses, netmasks, and broadcast addresses.
- Enable/disable interfaces or put them in promiscuous mode (for packet sniffing).
While modern Linux distributions increasingly use the ip command (from the iproute2 package) as a replacement, ifconfig remains relevant for legacy systems, quick troubleshooting, and environments where iproute2 is not available.
Table of Contents#
- Installing
ifconfig - Basic Syntax
- Viewing Network Interfaces
- Configuring Network Interfaces
- Enabling/Disabling Interfaces
- Troubleshooting with
ifconfig - Common & Best Practices
- Alternatives to
ifconfig - Conclusion
- References
1. Installing ifconfig#
On modern Linux distributions, ifconfig is part of the net-tools package (often not installed by default):
For Debian/Ubuntu:#
sudo apt update && sudo apt install net-toolsFor CentOS/RHEL (7+):#
sudo yum install net-tools # For CentOS 7/RHEL 7
sudo dnf install net-tools # For CentOS 8+/RHEL 8+For Fedora:#
sudo dnf install net-tools2. Basic Syntax#
The general syntax of ifconfig is:
ifconfig [interface] [options] [address]interface: Name of the network interface (e.g.,eth0,wlan0,lofor loopback).options: Flags likeup,down,promisc,mtu, etc.address: IP address, netmask, or other network parameters.
3. Viewing Network Interfaces#
To list all active network interfaces (and their details), run ifconfig with no arguments:
ifconfigSample Output (Simplified):#
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe9b:1234 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:9b:12:34 txqueuelen 1000 (Ethernet)
RX packets 12345 bytes 6789012 (6.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7890 bytes 567890 (554.6 KiB)
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 100 bytes 8900 (8.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 100 bytes 8900 (8.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0Output Breakdown:#
- Interface Name:
eth0(Ethernet),lo(loopback). - Flags:
UP(interface is active),BROADCAST(supports broadcast),RUNNING(cable is connected),LOOPBACK(forlo). - IP/IPv6 Addresses:
inet(IPv4),inet6(IPv6). - MAC Address:
ether(for Ethernet interfaces). - Traffic Stats:
RX(received) andTX(transmitted) packets/bytes, errors, and collisions.
4. Configuring Network Interfaces#
4.1 Assigning an IP Address#
To set an IP address (temporarily, until reboot) for an interface (e.g., eth0):
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0192.168.1.10: IP address.netmask 255.255.255.0: Subnet mask (defines the local network).
4.2 Setting Netmask, Broadcast, or MTU#
Netmask (Alternative Syntax)#
sudo ifconfig eth0 192.168.1.10/24 # Shorthand for netmask 255.255.255.0 (24 bits)Broadcast Address#
sudo ifconfig eth0 broadcast 192.168.1.255MTU (Maximum Transmission Unit)#
Adjust the MTU (e.g., for VPNs or jumbo frames):
sudo ifconfig eth0 mtu 1450 # Reduce MTU (default is 1500 for Ethernet)4.3 Promiscuous Mode#
Put an interface in promiscuous mode (captures all network traffic, not just traffic destined for it—used for packet sniffing):
sudo ifconfig eth0 promiscTo disable promiscuous mode:
sudo ifconfig eth0 -promisc5. Enabling/Disabling Interfaces#
Enable an Interface#
sudo ifconfig eth0 upDisable an Interface#
sudo ifconfig eth0 downUse case: Disable an interface to troubleshoot (e.g., reset network settings) or enable it after configuration.
6. Troubleshooting with ifconfig#
6.1 Check for Errors#
Inspect RX errors, TX errors, or collisions in the ifconfig output:
- RX/TX Errors: May indicate cable issues, driver bugs, or misconfigured hardware.
- Collisions: High collisions suggest network congestion or a faulty switch port.
6.2 Verify IP Configuration#
Ensure the IP address and netmask match your network’s requirements:
ifconfig eth06.3 List All Interfaces (Including Disabled)#
ifconfig -a # Shows all interfaces (even if down)7. Common & Best Practices#
7.1 Common Usage#
- View a specific interface:
ifconfig eth0 - List all interfaces (including down):
ifconfig -a - Temporarily assign an IP:
sudo ifconfig eth0 192.168.1.10
7.2 Best Practices#
- Temporary Changes Only:
ifconfigchanges are lost after a reboot. For persistent changes, edit network config files (e.g.,/etc/network/interfacesin Debian, or usenmcli/nmtuifor NetworkManager). - Validate Changes: After reconfiguring, use
pingto test connectivity:ping -c 3 192.168.1.1 # Ping the gateway - Promiscuous Mode Carefully: Only use promiscuous mode on trusted networks (it exposes all network traffic).
- Prefer
ipfor Modern Systems: Learn theipcommand (e.g.,ip addr,ip link) for modern Linux distributions.
8. Alternatives to ifconfig#
The ip command (from the iproute2 package) is the modern replacement for ifconfig. It is more powerful and flexible:
Example: ip Command Usage#
-
View interfaces:
ip addr show # Equivalent to `ifconfig` -
Assign an IP:
sudo ip addr add 192.168.1.10/24 dev eth0 -
Enable/disable an interface:
sudo ip link set eth0 up # Enable sudo ip link set eth0 down # Disable
Conclusion#
The ifconfig command remains a valuable tool for:
- Legacy systems or environments without
iproute2. - Quick troubleshooting (e.g., checking traffic stats, verifying IPs).
- Simple interface configuration (e.g., temporary IP assignment).
However, for modern Linux systems, learning the ip command is recommended for advanced networking tasks and long-term compatibility.
References#
- Linux
ifconfigman page:man ifconfig - Red Hat: Using the ip Command
- DigitalOcean: How To Use ifconfig and ip Command
- Linux Foundation: net-tools vs iproute2