ifconfig Command: Tutorial & Examples
Display and configure network interfaces on Linux servers
The ifconfig
command is a classic network configuration tool used on Linux systems to display and modify the parameters of network interfaces. It allows
administrators to view interface status, assign IP addresses, enable or disable interfaces, and configure various network settings. Although now deprecated in
favor of the more powerful ip
command, ifconfig
remains widely available and useful for quick network diagnostics and legacy scripts on
many systems.
What ifconfig Does
The ifconfig
command interacts directly with the kernel's network stack to display or change the configuration of network interfaces. It can:
- Show detailed information about all or specific network interfaces, including IP addresses, MAC addresses, netmask, broadcast address, MTU, and transmitted/received packet statistics.
- Enable or disable network interfaces (bring them up or down).
- Assign or change IP addresses and network masks.
- Enable or disable promiscuous mode on interfaces, useful for network monitoring.
- Adjust other parameters such as the Maximum Transmission Unit (MTU).
This makes ifconfig
an essential tool for managing network connectivity on Linux servers and virtual machines, especially when working in environments without
graphical interfaces.
How ifconfig Works
ifconfig
uses system calls to query and manipulate the kernel's network interface configuration. It accesses the interface's parameters via
the ioctl system calls, communicating with the kernel's networking subsystem to retrieve or update settings. The command reads the current
state of interfaces from the kernel and writes changes back to configure the network stack accordingly.
Each network interface on the system corresponds to a physical or virtual device, such as an Ethernet card (eth0
), loopback device (lo
), or wireless
adapter (wlan0
). ifconfig
allows you to inspect and modify these interfaces' properties at a low level.
Common Command Line Parameters
Here are some frequently used options with ifconfig
:
- interface_name: Specify which network interface to operate on (e.g.,
eth0
,lo
). - up: Activate the interface (bring it up).
- down: Deactivate the interface (bring it down).
- IP_address: Set the IP address of the interface.
- netmask: Set the network mask for the interface.
- broadcast: Set the broadcast address for the interface.
- promisc: Enable promiscuous mode (receive all packets).
- -promisc: Disable promiscuous mode.
- mtu: Set the Maximum Transmission Unit size.
- alias: Add a secondary IP address to the interface.
Basic Usage Examples
Display all configured network interfaces with their details:
ifconfig
Sample output:
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:fe4e:66a1 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:4e:66:a1 txqueuelen 1000 (Ethernet)
RX packets 12345 bytes 1234567 (1.2 MB)
TX packets 6789 bytes 987654 (987.6 KB)
View information for a specific interface, e.g., eth0
:
ifconfig eth0
Assign an IP address and netmask to an interface:
ifconfig eth0 192.168.1.10 netmask 255.255.255.0
Bring the interface up (activate it):
ifconfig eth0 up
Bring the interface down (deactivate it):
ifconfig eth0 down
Enable promiscuous mode to capture all network traffic (useful for packet sniffing):
ifconfig eth0 promisc
Disable promiscuous mode:
ifconfig eth0 -promisc
Set the MTU size of an interface:
ifconfig eth0 mtu 1400
Add an alias IP address to an interface:
ifconfig eth0:0 192.168.1.11 netmask 255.255.255.0
Understanding ifconfig Output
The output of ifconfig
can be divided into several parts:
- Interface Name: e.g.,
eth0
,lo
. - Flags: Indicate interface status (e.g.,
UP
,BROADCAST
,RUNNING
,MULTICAST
). - MTU: Maximum Transmission Unit size in bytes.
- inet: IPv4 address assigned to the interface.
- netmask: Subnet mask for the IPv4 address.
- broadcast: Broadcast address for the subnet.
- inet6: IPv6 address and prefix length.
- ether: MAC (hardware) address.
- RX/TX packets and bytes: Counters for data received and transmitted.
- txqueuelen: Length of the transmit queue.
Understanding these fields helps diagnose network issues and verify configurations.
Potential Problems and Troubleshooting
- Permission Denied: Running
ifconfig
to change settings requires superuser privileges. Usesudo
to run commands that modify interfaces. - Interface Not Found: Specifying a non-existent interface name will cause an error.
- Changes Not Persistent: Changes made with
ifconfig
are not permanent and will be lost after reboot unless saved in network configuration files. - Deprecated Command Warning: Some modern Linux distributions may not include
ifconfig
by default or show warnings about its obsolescence. - Incorrect IP or Netmask: Setting wrong IP or netmask can cause connectivity issues.
For troubleshooting, always verify interface status with ifconfig interface_name
and confirm network connectivity with tools like ping
or ip
.
Deprecation and Alternatives
The ifconfig
command is deprecated and has been replaced by the more versatile and powerful ip
command from the iproute2 package. The
ip
command offers more features and a unified syntax for managing network interfaces, routing, and tunnels.
Example equivalent commands:
ip addr show eth0
ip link set eth0 up
ip addr add 192.168.1.10/24 dev eth0
Despite deprecation, ifconfig
remains widely used for simple tasks and legacy scripts.
Tips and Best Practices
- Always use
sudo
or run as root when changing interface settings. - Use
ifconfig
primarily for quick checks or legacy compatibility. - Learn and transition to the
ip
command for advanced network management. - Document any manual changes to network configuration to avoid losing settings after reboot.
- Combine
ifconfig
with other tools likeping
,netstat
, orss
for comprehensive network troubleshooting.
See Also
Further Reading
- Linux for Networking Professionals by Rob Vandenbrink (partner link)
- Understanding Linux Network Internals by Christian Benvenuti (partner link)
- Linux Networking Cookbook by Carla Schroder (partner link)
As an Amazon Associate, I earn from qualifying purchases.