Mastering ifconfig: A Comprehensive Guide to Network Interface Configuration
In the world of Linux and Unix-like operating systems, network configuration is a fundamental skill for system administrators, developers, and power users. For decades, ifconfig (short for interface configuration) has been the go-to command-line tool for managing network interfaces. While it’s now deprecated in favor of the more modern ip command from the iproute2 suite, ifconfig remains widely used in legacy systems, embedded devices, and older scripts.
This blog will dive deep into ifconfig: what it is, how to install it, core concepts, practical commands, use cases, best practices, and alternatives. Whether you’re troubleshooting connectivity issues or configuring temporary network settings, this guide will equip you with everything you need to master ifconfig.
Table of Contents#
- What is ifconfig?
- Installation & Availability
- Core Concepts & Terminology
- 3.1 Network Interfaces
- 3.2 IP Addresses (IPv4/IPv6)
- 3.3 Subnet Masks & Broadcast Addresses
- 3.4 MAC Addresses
- Basic ifconfig Commands & Usage Examples
- 4.1 List All Network Interfaces
- 4.2 Display Detailed Info for a Specific Interface
- 4.3 Enable/Disable an Interface
- 4.4 Assign an IPv4 Address
- 4.5 Assign an IPv6 Address
- 4.6 Set a Subnet Mask
- 4.7 Configure a Broadcast Address
- 4.8 Change MAC Address (Spoofing)
- 4.9 Set MTU Size
- Common Use Cases & Practices
- 5.1 Troubleshooting Network Connectivity
- 5.2 Configuring Temporary Network Settings
- 5.3 Verifying Interface Configuration
- Best Practices for Using ifconfig
- ifconfig vs. ip Command: Key Differences
- Deprecation & Alternatives
- Frequently Asked Questions (FAQ)
- Conclusion
- References
1. What is ifconfig?#
ifconfig is a command-line utility for configuring, managing, and querying network interfaces in Linux, Unix, and macOS systems. It allows users to:
- View detailed information about network interfaces (IP addresses, MAC addresses, MTU size, etc.)
- Enable or disable interfaces
- Assign temporary IP addresses (IPv4/IPv6), subnet masks, and broadcast addresses
- Modify advanced settings like MTU (Maximum Transmission Unit) and MAC addresses
- Troubleshoot basic network connectivity issues
Critical note: ifconfig changes are temporary by default—they will be lost after a system reboot unless saved to persistent configuration files.
2. Installation & Availability#
ifconfig is part of the net-tools package, which is not pre-installed on most modern Linux distributions (due to its deprecation). Here’s how to install it:
Debian/Ubuntu-based Systems#
sudo apt update && sudo apt install net-tools -yRHEL/CentOS/Fedora-based Systems#
sudo dnf install net-tools -y # For modern RHEL/Fedora
# Or for older RHEL/CentOS versions:
sudo yum install net-tools -ymacOS#
ifconfig is pre-installed on all macOS versions and remains fully functional. macOS does not use net-tools—it has its own implementation. Note that macOS does not include the ip command; use ifconfig or networksetup for network configuration on macOS.
Windows#
Windows does not include ifconfig—use the ipconfig command instead for similar functionality.
3. Core Concepts & Terminology#
Before using ifconfig, it’s essential to understand key network terms:
3.1 Network Interfaces#
A network interface is a hardware or software component that connects a system to a network. Common interface names include:
eth0/ens33: Wired Ethernet interfaceswlan0: Wireless Wi-Fi interfacelo: Loopback interface (used for internal communication within the system, IP:127.0.0.1)tun0/tap0: Virtual interfaces for VPNs or tunnels
3.2 IP Addresses#
An IP address uniquely identifies a device on a network:
- IPv4: 32-bit numerical address (e.g.,
192.168.1.100), widely used in legacy networks. - IPv6: 128-bit alphanumeric address (e.g.,
2001:db8::1), designed to replace IPv4.
3.3 Subnet Masks & Broadcast Addresses#
- Subnet Mask: Defines the range of IP addresses in a subnet (e.g.,
255.255.255.0for a /24 network). It separates the network portion from the host portion of an IP address. - Broadcast Address: A special IP address used to send data to all devices in a subnet (e.g.,
192.168.1.255for a /24 network).
3.4 MAC Addresses#
A MAC (Media Access Control) address is a unique 48-bit hardware address assigned to a network interface (e.g., 00:1A:2B:3C:4D:5E). It’s used for communication within a local network.
4. Basic ifconfig Commands & Usage Examples#
Below are the most common ifconfig commands with practical examples. Most commands require root privileges (prefix with sudo).
4.1 List All Network Interfaces#
Display all active and inactive interfaces:
ifconfig -a- Omit the
-aflag to show only active interfaces:
ifconfigSample 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
inet6 2001:db8::1 prefixlen 64 scopeid 0x0<global>
ether 00:1a:2b:3c:4d:5e txqueuelen 1000 (Ethernet)
RX packets 12345 bytes 6789012 (6.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9876 bytes 5432100 (5.4 MB)
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 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4.2 Display Detailed Info for a Specific Interface#
Show configuration details for a single interface (e.g., eth0):
ifconfig eth04.3 Enable/Disable an Interface#
- Enable an interface:
sudo ifconfig eth0 up- Disable an interface:
sudo ifconfig eth0 downThis is useful for resetting a misbehaving interface or disconnecting from a network temporarily.
4.4 Assign an IPv4 Address#
Assign an IPv4 address to an interface (e.g., 192.168.1.101 to eth0):
sudo ifconfig eth0 192.168.1.1014.5 Assign an IPv6 Address#
Assign an IPv6 address (e.g., 2001:db8::2 to eth0 with a /64 prefix):
sudo ifconfig eth0 inet6 add 2001:db8::2/64To remove an IPv6 address:
sudo ifconfig eth0 inet6 del 2001:db8::2/644.6 Set a Subnet Mask#
You can set the subnet mask alongside an IP address:
sudo ifconfig eth0 192.168.1.101 netmask 255.255.255.0Or set it separately:
sudo ifconfig eth0 netmask 255.255.255.04.7 Configure a Broadcast Address#
Set the broadcast address for a subnet (e.g., 192.168.1.255):
sudo ifconfig eth0 broadcast 192.168.1.255Or combine IP, netmask, and broadcast in one command:
sudo ifconfig eth0 192.168.1.101 netmask 255.255.255.0 broadcast 192.168.1.2554.8 Change MAC Address (Spoofing)#
Spoofing a MAC address can be useful for privacy or bypassing network filters. First, disable the interface:
sudo ifconfig eth0 downThen set the new MAC address:
sudo ifconfig eth0 hw ether 00:11:22:33:44:55Re-enable the interface:
sudo ifconfig eth0 upVerify the change:
ifconfig eth0 | grep ether4.9 Set MTU Size#
MTU (Maximum Transmission Unit) is the largest packet size an interface can send without fragmentation. The default is 1500 bytes for Ethernet. To set a custom MTU (e.g., 1400 bytes):
sudo ifconfig eth0 mtu 1400This is helpful for optimizing performance in networks with packet size restrictions (e.g., VPNs).
5. Common Use Cases & Practices#
5.1 Troubleshooting Network Connectivity#
- Check if an interface is active (look for the
UPflag inifconfig eth0output). - Verify that the IP address and subnet mask match the network’s requirements.
- Ensure the MTU size is compatible with the network (incorrect MTU can cause packet loss).
5.2 Configuring Temporary Network Settings#
ifconfig is ideal for testing network configurations without making permanent changes. For example:
- Assign a temporary IP address to test connectivity to a new device.
- Spoof a MAC address to access a network that filters by hardware address.
5.3 Verifying Interface Configuration#
After making changes, use ifconfig to confirm that settings like IP address, netmask, and MTU are correctly applied. You can also use tools like ping or traceroute to validate connectivity.
6. Best Practices for Using ifconfig#
- Use Root Privileges: Most
ifconfigcommands require root access—always prefix withsudoto avoid permission errors. - Disable Interfaces Before Modifying: Always disable an interface (e.g.,
ifconfig eth0 down) before changing MAC address or MTU to prevent conflicts. - Avoid Persistent Changes with ifconfig:
ifconfigchanges are temporary. For persistent configurations, edit system files (e.g.,/etc/network/interfaceson Debian/Ubuntu,/etc/sysconfig/network-scripts/ifcfg-eth0on RHEL/CentOS) or use network managers likenmcli. - Validate Changes: After applying settings, verify them with
ifconfigand test connectivity withpingorcurl. - Be Cautious with MAC Spoofing: Some networks block spoofed MAC addresses. Only use this practice for legitimate purposes (e.g., testing, privacy).
7. ifconfig vs. ip Command: Key Differences#
The ip command from the iproute2 suite is the modern replacement for ifconfig. While ifconfig uses older ioctl system calls, ip communicates with the kernel through netlink sockets, which are more efficient and support a wider range of network configuration tasks. Here’s how they compare:
| Feature | ifconfig | ip Command |
|---|---|---|
| Package | net-tools (deprecated) | iproute2 (actively maintained) |
| Routing Management | Requires separate commands (e.g., route) | Built-in routing support (ip route) |
| IPv6 Support | Limited | Full, native IPv6 support |
| Virtual Interfaces | Basic support | Advanced support (VLANs, tunnels) |
| Persistence | No (temporary changes only) | No, but integrates with network managers |
| Syntax | Simpler for basic tasks | More verbose, but flexible |
Example Equivalents:#
ifconfig Command | ip Command Equivalent |
|---|---|
ifconfig eth0 up | sudo ip link set eth0 up |
ifconfig eth0 down | sudo ip link set eth0 down |
ifconfig eth0 192.168.1.100 | sudo ip addr add 192.168.1.100/24 dev eth0 |
ifconfig -a | ip addr show |
ifconfig eth0 | ip addr show eth0 |
ifconfig eth0 mtu 1400 | sudo ip link set eth0 mtu 1400 |
ifconfig eth0 hw ether 00:11:22:33:44:55 | sudo ip link set eth0 address 00:11:22:33:44:55 |
route -n | ip route show |
8. Deprecation & Alternatives#
ifconfig and the net-tools package have been deprecated for over a decade. The main reasons are:
- Lack of support for modern network features (e.g., advanced IPv6, virtual interfaces, routing policies, traffic control)
- The
ipcommand uses netlink sockets instead of the olderioctlsystem calls, making it more efficient and extensible - Most major distributions have removed
net-toolsfrom their default installations (e.g., Ubuntu 25.04 does not include it) - Limited feature development; while the net-tools package continues to receive occasional updates (the latest release was in September 2025), it has not kept pace with modern networking requirements
Recommended Alternatives:#
ipCommand: The official replacement forifconfig—use it for all modern network configuration tasks.ssCommand: Replacesnetstatfor viewing socket statistics, active connections, and listening ports (e.g.,ss -tulnfor listening TCP/UDP ports).nmcli: A command-line tool for NetworkManager (common on desktop Linux systems) that simplifies persistent network configuration.nmtui: A text-based user interface for NetworkManager, ideal for users who prefer a graphical-like experience in the terminal.
9. Frequently Asked Questions (FAQ)#
Is ifconfig still available on Linux?#
ifconfig is not installed by default on most modern Linux distributions (e.g., Ubuntu 25.04, Fedora, RHEL 9+). You can install it manually via the net-tools package, but using the ip command is recommended.
Is ifconfig deprecated on macOS?#
No. macOS includes its own implementation of ifconfig that is fully functional and actively maintained. It remains the primary command-line tool for network interface configuration on macOS.
What is the difference between ifconfig and ip?#
ifconfig is part of the older net-tools package and uses ioctl system calls. The ip command (from iproute2) uses netlink sockets, which are more efficient and support modern features like policy-based routing, VLANs, tunnels, and traffic control.
Can I still use ifconfig in scripts?#
Yes, but be aware that ifconfig may not be available on all systems. If you need portable scripts, consider checking for ifconfig availability or using ip commands instead.
What replaced netstat?#
The ss command (from iproute2) replaced netstat. For example, use ss -tuln to list all listening TCP and UDP ports.
10. Conclusion#
While ifconfig is no longer the primary tool for network configuration on Linux, it remains a useful utility for legacy systems, embedded devices, quick diagnostics, and macOS environments. This guide has covered everything from installation and core concepts to practical commands and best practices.
When to use ifconfig:
- On legacy systems or embedded devices where
ipis not available - On macOS, where
ifconfigis the standard tool - For quick, simple interface checks when you’re already familiar with its syntax
- When working with older scripts that depend on
ifconfigoutput
When to use ip:
- On all modern Linux distributions (Ubuntu, Fedora, RHEL, Arch, etc.)
- When you need routing, VLAN, tunnel, or advanced interface management
- For scripting, as
ipprovides more consistent and parseable output - When working with containers, virtual networks, or policy-based routing
For day-to-day Linux system administration, make the ip command your default. It is actively maintained, supports all modern networking features, and is available on every major distribution without installing additional packages.
11. References#
- Linux
ifconfigMan Page: https://man7.org/linux/man-pages/man8/ifconfig.8.html iproute2Documentation: https://man7.org/linux/man-pages/man8/ip.8.html- Debian Network Configuration Guide: https://wiki.debian.org/NetworkConfiguration
- RHEL Network Configuration Documentation: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking
- Red Hat:
ifconfigvsipCommand: https://www.redhat.com/en/blog/ifconfig-vs-ip