ifconfig - Linux
Overview
ifconfig (interface configurator) is a traditional command-line tool used to configure the network interfaces in Unix-based operating systems. It allows users to view and modify parameters associated with networking, such as enabling/disabling interfaces or setting up IP addresses. This command is instrumental in diagnosing network issues and configuring network settings.
Syntax
The general syntax of ifconfig is as follows:
ifconfig [interface]
ifconfig [interface] [options] [address]
- interface: The name of the network interface you want to configure (e.g.,
eth0,wlan0). - options: Commands to manipulate the interface settings.
- address: The IP address or other parameters to assign to the interface.
Options/Flags
Here are some commonly used options and flags in ifconfig:
up: Activates an interface.down: Deactivates an interface.addr: Sets the IP address of the interface.netmask <mask>: Sets the subnet mask.broadcast <address>: Sets the broadcast address.
Example Usage:
ifconfig eth0 up
This command activates the eth0 interface.
Examples
-
View All Interfaces:
ifconfig -aThis displays all the available network interfaces, including those that are down.
-
Set an IP Address:
ifconfig eth0 192.168.1.100 netmask 255.255.255.0This assigns the IP address
192.168.1.100toeth0with a subnet mask of255.255.255.0. -
Enable and Disable Interface:
ifconfig eth0 up ifconfig eth0 downThese commands activate and deactivate the
eth0interface, respectively.
Common Issues
- Interface Not Found: If you get an error saying the interface does not exist, double-check the interface name.
- Permissions:
ifconfigtypically requires root access. Usesudo ifconfigif you encounter permission denied errors.
Integration
ifconfig can be combined with other tools like grep for more effective results:
ifconfig | grep "inet "
This command filters and shows only lines containing IP addresses.
Related Commands
- ip: A modern replacement for
ifconfigthat provides more detailed and extensive network management capabilities. - netstat: Displays network connections, routing tables, and statistics.
- iwconfig: Similar to
ifconfig, but dedicated to wireless network interfaces.
For thorough documentation, please consult the manual pages (man ifconfig on your terminal) or the official Linux documentation online.