The ifconfig command in Linux displays and configures network interface parameters such as IP addresses, netmasks, and MAC addresses. You use it by typing ifconfig to view all active interfaces, or ifconfig [interface] [options] to change settings on a specific one. This guide explains its syntax, common uses, and how it compares to modern alternatives like ip.
What Is ifconfig?
ifconfig (interface configuration) is a command-line utility that has been part of Unix-like systems for decades. It comes from the net-tools package, which was the standard set of networking tools on Linux for years. The command lets you:
- View all network interfaces and their current settings
- Assign or remove IP addresses and netmasks
- Enable or disable an interface
- Change the MTU (Maximum Transmission Unit) size
- Set the interface’s MAC address (hardware address)
While still widely used, ifconfig is considered deprecated in many modern distributions, replaced by the ip command from the iproute2 package. However, it remains installed by default on many systems and is still taught and used in scripts and documentation.
Basic Syntax and Common Options
The general form is:
ifconfig [interface] [options]
If you run ifconfig with no arguments, it shows all active interfaces (those that are up). To see all interfaces, including those that are down, use ifconfig -a.
Common options you’ll use:
up/down– bring an interface up or downinet IP– assign an IPv4 addressnetmask MASK– set the netmaskbroadcast ADDR– set the broadcast addressmtu N– set the MTU sizehw ether MAC– set the MAC addressadd ADDR/del ADDR– add or remove an IPv6 address
Viewing Interface Information
Running ifconfig alone gives output like this (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
ether 00:1a:2b:3c:4d:5e txqueuelen 1000
RX packets 1234 bytes 123456 (123.4 KB)
TX packets 567 bytes 78901 (78.9 KB)
Key fields to understand:
- flags – shows interface status (UP, BROADCAST, etc.)
- inet – IPv4 address
- netmask – subnet mask
- broadcast – broadcast address
- ether – MAC address
- RX/TX – received/transmitted packets and bytes
Assigning an IP Address
To set an IP address on an interface, use:
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
This assigns the address and netmask. You can also specify the broadcast address explicitly:
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
To bring the interface up after configuration, use sudo ifconfig eth0 up. Note that changes made this way are temporary and disappear after a reboot unless you configure them in your network manager or a startup script.
Enabling and Disabling Interfaces
To disable an interface (take it down), run:
sudo ifconfig eth0 down
To re-enable it:
sudo ifconfig eth0 up
Taking an interface down removes its IP addresses and stops all traffic. This can be useful for troubleshooting or when you need to change hardware settings like the MAC address.
Changing the MAC Address
You can temporarily change the MAC address of an interface. First, bring it down, then set the new address, then bring it up:
sudo ifconfig eth0 down sudo ifconfig eth0 hw ether 00:11:22:33:44:55 sudo ifconfig eth0 up
This is often used for privacy or to bypass MAC filtering. The change is not permanent; it reverts to the original MAC after a reboot. Be aware that some network drivers may not support changing the MAC address.
ifconfig vs. ip Command
The ip command from iproute2 is the modern replacement. Here’s a quick comparison:
ifconfig– shows all active interfaces;ip addr– shows all addressesifconfig eth0 up– brings interface up;ip link set eth0 up– sameifconfig eth0 192.168.1.1 netmask 255.255.255.0– assigns address;ip addr add 192.168.1.1/24 dev eth0– sameifconfig eth0 hw ether 00:...– sets MAC;ip link set eth0 address 00:...– same
Why switch? The ip command supports more features (like network namespaces, routing tables, and advanced link settings) and is more consistent across different Linux distributions. Also, ifconfig may not be installed by default on minimal systems. However, ifconfig is still useful for quick checks and is present on many older systems.
Common Problems and Troubleshooting
If you get command not found, you need to install net-tools. On Debian/Ubuntu: sudo apt install net-tools. On RHEL/CentOS: sudo yum install net-tools.
If you see SIOCSIFADDR: Permission denied, you forgot sudo – most configuration changes require root privileges.
If you assign an IP but lose connectivity, check that the netmask and broadcast are correct. A common mistake is using a wrong netmask, which can cause the interface to be on a different subnet than the gateway.
Remember that changes are not persistent. If you want to make them permanent, you need to edit configuration files (like /etc/network/interfaces on Debian) or use your network manager (NetworkManager, systemd-networkd).
Frequently Asked Questions
Why does ifconfig not show my wireless interface?
If the wireless interface is down, ifconfig won’t show it. Use ifconfig -a to see all interfaces, including those that are down. Also, some wireless interfaces are named like wlan0 or wlp2s0, so check with ip link or iwconfig.
How do I set a static IP permanently?
Use your distribution’s network configuration files. On Debian/Ubuntu, edit /etc/network/interfaces and add lines like auto eth0, iface eth0 inet static, address 192.168.1.10, netmask 255.255.255.0, gateway 192.168.1.1. On modern systems, use NetworkManager’s GUI or nmcli.
What does the RX and TX mean?
RX stands for received, TX for transmitted. These counters show the number of packets and bytes that have been received or transmitted on that interface. They are useful for monitoring traffic and diagnosing network issues.
Can I use ifconfig to set up VLANs?
No, ifconfig does not support VLANs. You need the ip command or tools like vconfig. For example, ip link add link eth0 name eth0.10 type vlan id 10.
Is ifconfig still safe to use?
Yes, it is safe and functional, but it is deprecated. It may not be installed by default on newer distributions, and it lacks some modern features. For scripting and new deployments, prefer the ip command.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Wii Browser Games With a USB or Bluetooth Controller
- Delete Focus on iPhone: Quick Steps
- Access Your Computer From Anywhere: Step-by-Step
- How to Get More Disk Space on Mac: 12 Fixes
- Open System Configuration in Windows 10: 7 Ways
- How to Connect VPN: Step-by-Step Setup Guide