0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use ifconfig Command in Linux: Syntax and Examples

The ifconfig command in Linux is used to display or configure network interfaces. You can run ifconfig alone to see all active interfaces or use options like ifconfig eth0 up to activate an interface.
📐

Syntax

The basic syntax of the ifconfig command is:

  • ifconfig [interface] [options]
  • interface: The network interface name (e.g., eth0, wlan0).
  • options: Commands to configure the interface like up, down, or setting IP addresses.
bash
ifconfig [interface] [options]
💻

Example

This example shows how to display all active network interfaces and their details using ifconfig without arguments.

bash
ifconfig
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) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6789 bytes 987654 (987.6 KB) 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 1000 bytes 80000 (80.0 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1000 bytes 80000 (80.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
⚠️

Common Pitfalls

Some common mistakes when using ifconfig include:

  • Running ifconfig without root privileges when trying to change settings, which will fail silently or show errors.
  • Using deprecated ifconfig on newer Linux systems where ip command is preferred.
  • Typing incorrect interface names, causing errors or no changes.

Always check interface names with ifconfig or ip link before configuring.

bash
sudo ifconfig eth0 up
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
📊

Quick Reference

CommandDescription
ifconfigShow all active network interfaces
ifconfig eth0Show details of interface eth0
ifconfig eth0 upActivate interface eth0
ifconfig eth0 downDeactivate interface eth0
ifconfig eth0 192.168.1.100 netmask 255.255.255.0Set IP address and netmask for eth0

Key Takeaways

Use ifconfig without arguments to list active network interfaces.
Specify interface name and options to configure network settings.
Root privileges are required to change interface configurations.
Check interface names carefully to avoid errors.
On newer Linux systems, consider using the ip command as ifconfig may be deprecated.