Ifconfig is a command-line utility used to configure and display network interface parameters on Linux and other Unix-like systems. You use it to view IP addresses, enable or disable interfaces, and set netmasks or MAC addresses. Below are practical examples showing how to check and change network settings with ifconfig.
What Is Ifconfig and Why Use It?
Ifconfig stands for “interface configuration.” It has been part of the net-tools package for decades and remains the go-to tool on many older or minimal Linux installations. Although modern distributions increasingly favor the ip command (from iproute2), ifconfig is still widely used in scripts, documentation, and on systems where net-tools is the default. It works with Ethernet, Wi-Fi, loopback, and virtual interfaces.
The utility can display current settings, assign IP addresses, change netmasks, bring interfaces up or down, and even alter the MAC address. Because it writes directly to kernel network structures, it requires root privileges for any change—viewing status works as a normal user.
Basic Ifconfig Syntax and Viewing Interfaces
The simplest form is running ifconfig with no arguments. This shows all active interfaces with their IPv4 addresses, netmasks, MAC addresses, packet counts, and error statistics. To see inactive interfaces too, use ifconfig -a.
$ ifconfig
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 12345 bytes 1234567 (1.1 MiB)
TX packets 6789 bytes 987654 (964 KiB)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
To inspect a single interface, append its name: ifconfig eth0. This is useful when you need only the IP or MAC of one adapter, especially in scripts where you might pipe the output to grep or awk.
Assigning an IP Address and Netmask
To set an IPv4 address on an interface, use the following syntax:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
This assigns the IP and netmask in one command. You can also specify the broadcast address with broadcast 192.168.1.255 if the default is not what you need. If you omit the netmask, ifconfig uses the classful default (e.g., 255.0.0.0 for a Class A address), which is rarely what you want—so always specify it.
For IPv6, the syntax differs slightly:
sudo ifconfig eth0 inet6 add 2001:db8::1/64
Note that ifconfig is primarily IPv4-oriented; most IPv6 configuration is better done with ip -6 addr add.
Bringing Interfaces Up and Down
To disable an interface, use sudo ifconfig eth0 down. This removes its IP address and stops network traffic. To re-enable it, use sudo ifconfig eth0 up. These commands are equivalent to ip link set eth0 down/up.
A common use case is after changing network settings: you bring the interface down and up to apply them. However, doing so over an SSH connection will drop your session—so be careful when working remotely. Always have a console or out-of-band access if you plan to bring down the interface you are connected through.
You can also bring up an interface with a specific IP in one step:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
Changing the MAC Address
Ifconfig lets you change the hardware (MAC) address of an interface, which can be useful for testing or privacy. The command is:
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
This sets the MAC address to the specified value. The interface must be down first on many systems, so run sudo ifconfig eth0 down before changing the MAC, then bring it up again. Note that the new MAC address is not persistent—it reverts to the original after a reboot unless you configure it in a startup script or network manager.
Common Ifconfig Options and Their Meanings
ifconfig– show active interfacesifconfig -a– show all interfaces, including down onesifconfig eth0– show only eth0ifconfig eth0 up/down– enable or disable the interfaceifconfig eth0 192.168.1.1 netmask 255.255.255.0– assign IP and netmaskifconfig eth0 hw ether 00:11:22:33:44:55– set MAC addressifconfig eth0 mtu 9000– set the Maximum Transmission Unit (e.g., for jumbo frames)ifconfig eth0 promisc– enable promiscuous mode (for packet sniffing)
The mtu option is useful when you need to adjust packet size for performance or compatibility. Promiscuous mode is typically used with tools like tcpdump, but it requires root and may be restricted by security policies.
Ifconfig vs. the ip Command
Modern Linux distributions are moving away from ifconfig in favor of the ip command from iproute2. The main reasons are that ip supports IPv6 more fully, handles multiple addresses per interface better, and provides more detailed link-layer information. Here is a quick comparison:
- Show all interfaces:
ip addr showvs.ifconfig -a - Bring interface up:
ip link set eth0 upvs.ifconfig eth0 up - Assign IP:
ip addr add 192.168.1.1/24 dev eth0vs.ifconfig eth0 192.168.1.1 netmask 255.255.255.0 - Change MAC:
ip link set eth0 address 00:11:22:33:44:55vs.ifconfig eth0 hw ether ...
If your system uses ip by default, ifconfig may not even be installed. You can install net-tools on most distributions (e.g., sudo apt install net-tools on Debian/Ubuntu, sudo yum install net-tools on RHEL/CentOS).
Common Problems and Troubleshooting
One frequent issue is the error SIOCSIFADDR: No such device when you mistype the interface name. Check with ifconfig -a to see the exact names—they might be enp0s3 or wlp2s0 rather than the traditional eth0.
Another problem is losing network connectivity after changing settings. This usually happens because you assigned an incorrect IP or netmask. Double-check your subnet and gateway. If you are using DHCP, you can revert by running sudo dhclient eth0 (or sudo dhcpcd eth0) to request a new lease.
If ifconfig is not found, the net-tools package is missing. Install it as described above. On minimal containers or embedded systems, you may need to use ip instead because net-tools is not included.
Frequently Asked Questions
How do I see my IP address with ifconfig?
Run ifconfig without arguments to see all active interfaces and their IPv4 addresses. Look for the inet line under each interface. For a specific interface, use ifconfig eth0 and read the inet value.
Does ifconfig work on Windows?
No, ifconfig is a Unix/Linux command. Windows uses ipconfig for similar purposes, but the syntax and output are different. For example, ipconfig /all shows detailed network information.
Why does ifconfig show only 127.0.0.1 (loopback)?
That means your network interface is down or has no IP address assigned. Check if the interface is up with ifconfig -a; if it is down, bring it up with sudo ifconfig eth0 up and then request an IP via DHCP or assign one manually.
Can I change my IP address temporarily with ifconfig?
Yes, assigning an IP with ifconfig changes it immediately, but the change is not persistent. It reverts to the original setting after a reboot or when the network manager restarts. For permanent changes, edit your distribution’s network configuration files or use NetworkManager.
Is ifconfig deprecated?
It is deprecated on many modern Linux distributions in favor of the ip command, but it is still widely used and available via the net-tools package. Some minimal systems may not include it by default. For new scripts or administration, prefer ip unless you need compatibility with older systems.
How do I set a default gateway with ifconfig?
Ifconfig does not handle routing; use the route command (also from net-tools) or ip route add. For example: sudo route add default gw 192.168.1.1 eth0 or sudo ip route add default via 192.168.1.1 dev eth0.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Gadgets After Support Ends: Do They Improve?
- Delete Google Search Results About You
- OnePlus Buds Pro 3 Price Drop: Are They Worth It?
- Cloud Migration Ways to Prepare
- Remote Work Productivity Hacks That Actually Work
- Epic Games Removes Dark and Darker? Fact Check