ifconfig Command in Linux (original) (raw)

Last Updated : 8 Jun, 2026

The ifconfig (interface configuration) command is a Linux networking utility used to view and configure network interfaces. It allows administrators to inspect interface details such as IP addresses, MAC addresses, packet statistics and link status.

Example: Finding Your IP Address in Linux

To view information about all network interfaces on your Linux system

**Command:

ifconfig

**Output:

Finding IP Address in Linux Using `ifconfig`

Here,

1. eno1 (Wired / Ethernet Network Interface)

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

**Practical use:

**IPv4 Address Information:

inet 192.168.42.0 netmask 255.255.255.0 broadcast 192.168.42.255

**Practical use:

**IPv6 Address:

inet6 fe80::4d2c:0edb:a219:acf0

**Practical use:

**MAC Address:

ether c8:4b:d6:62:bb:da

**Practical use:

**Packet Statistics:

RX packets / TX packets

**Practical use:

**Error Indicators:

errors dropped overruns frame

**Practical use:

2. lo (Loopback Interface)

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1

**Practical use:

3. wlp0s20f3 (Wireless / Wi-Fi Interface)

Wireless network interface used for Wi-Fi connections

wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
inet 10.143.75.50

**Practical use:

Syntax

ifconfig [interface] [options]

Many modern Linux distributions do not include ifconfig by default. If you see the error. You need to install the net-tools package.

**Command:

sudo apt install net-tools

For RHEL (Red Hat Enterprise Linux) based Distributions

**Command:

dnf install net-tools

Options available in `ifconfig` Command

Option Description Syntax
-a Display all interfaces, including those that are down ifconfig -a
-s Display a short list, instead of details ifconfig -s
-v Run the command in verbose mode ifconfig -v
up Activate the driver for the given interface ifconfig interface up
down Deactivate the driver for the given interface ifconfig interface down
add addr/prefixlen Add an IPv6 address to an interface ifconfig interface add addr/prefixlen
del addr/prefixlen Remove an IPv6 address from an interface ifconfig interface del addr/prefixlen
[-]arp Enable/disable the use of ARP protocol on an interface ifconfig interface [-]arp
[-]promisc Enable/disable promiscuous mode on an interface ifconfig interface [-]promisc
[-]allmulti Enable/disable all-multicast mode for an interface ifconfig interface [-]allmulti
mtu N Set the Maximum Transfer Unit (MTU) ifconfig interface mtu size
--help Display help related to the ifconfig command ifconfig --help

Public IP Address in Linux

A public IP address is a globally unique identifier assigned to a device that is directly connected to the internet. It enables other devices and services on the internet to locate and communicate with that device. Public IP addresses are assigned by the Internet Assigned Numbers Authority (IANA) through Internet Service Providers (ISPs) and are globally route table across the internet.

Public IPs are commonly required for:

Example: Viewing the Public IP Address in Linux

Linux systems can retrieve the public IP address by querying external web services using command-line tools.

**Command:

curl ifconfig.me

Methods to Display the Public IP Address

**1. Using wget with ifconfig.me

**Command:

wget -qO- ifconfig.me

**Output:

Using `wget` with `ifconfig.me` to Find Your IP Address in Linux

Using `wget` with `ifconfig.me` to Find Your IP Address in Linux

**2. Using dig with OpenDNS

This command uses the OpenDNS resolver to query your public IP address.

**Command:

dig +short myip.opendns.com @resolver1.opendns.com

**Output:

Using `dig` with `resolver1.opendns.com` to Find Your IP Address in Linux

Using `dig` with `resolver1.opendns.com` to Find Your IP Address in Linux

**3. Using curl with icanhazip.com

This command queries the icanhazip.com service to obtain your public IP address.

**Command:

curl icanhazip.com

**Output:

 Using `curl` with `icanhazip.com`to Find Your IP Address in Linux

Using `curl` with `icanhazip.com`to Find Your IP Address in Linux

**4. Using wget with icanhazip.com

Similar to the curl command, this uses the icanhazip.com service to fetch your public IP address.

**Command:

wget -qO- icanhazip.com

**Output:

 Using `wget` with `icanhazip.com` to Find Your IP Address in Linux

Using `wget` with `icanhazip.com` to Find Your IP Address in Linux

**5. Using Google/OpenDNS resolver

This command utilizes the DNS service provided by Google to resolve your public IP address.

**Command:

host myip.opendns.com resolver1.opendns.com

**Output:

Using host with dns.google to Find Your IP Address in Linux

Using host with dns.google to Find Your IP Address in Linux

Private IP Address in Linux

A private IP address is used within a local network such as a home, office or organizational intranet. These addresses are not directly accessible from the internet. Private IP addresses are defined by the Internet Engineering Task Force (IETF) in RFC 1918 and are reserved exclusively for internal networking.

Private IP Address Ranges

Devices inside the same private network can communicate directly using these addresses. To access the internet, private IPs rely on Network Address Translation (NAT), which maps them to a shared public IP.

Example: Viewing Private IP Addresses in Linux

Linux provides multiple tools to display private IP addresses assigned to network interfaces.

**Command:

ifconfig

or

ip addr

Methods to Display Private IP Addresses

**1. Using hostname

The -I option with the hostname command can be used to display the private IP address of your machine.

**Command:

hostname -I

**Output:

Using hostname to Find Your IP Address in Linux

Using hostname to Find Your IP Address in Linux

**2. Using nmcli (NetworkManager command-line tool)

If you're using NetworkManager, this command filters out IPv4 addresses associated with your network interfaces.

**Command:

nmcli dev show | grep IP4.ADDRESS

**Output:

Using nmcli to Find Your IP Address in Linux

Using nmcli to Find Your IP Address in Linux

**3. Using awk with ifconfig

This command uses the awk tool to filter and print only the private IP addresses from the ifconfig output.

**Command:

ifconfig | awk '/inet / {print $2}'

**Output:

Using `awk` with `ifconfig` to Find Your IP Address in Linux

Using `awk` with `ifconfig` to Find Your IP Address in Linux

**4. Using grep with ip

This command uses grep with Perl-compatible regular expressions to extract private IP addresses from the ip command output.

**Command:

ip addr show | grep -oP 'inet \K[\d.]+'

**Output:

Using `grep` with `ip` to Find Your IP Address in Linux

Using `grep` with `ip` to Find Your IP Address in Linux

**5. Using ss (socket statistics)

This complex command lists the IP addresses to which the system is listening for incoming connections.

**Command:

ss -tunapl | grep LISTEN | awk '{print $5}' | cut -d: -f1 | sort -u

**Output:

Using `ss` (socket statistics) command to Find Your IP Address in Linux

Using `ss` (socket statistics) command to Find Your IP Address in Linux

Linux ifconfig Command Examples

1. Display Specific Network Interface

This command shows detailed information about the specified interface, eth0.

ifconfig eth0

2. Enable a Network Interface

This command activates the specified network interface, eth0.

ifconfig eth0 up

3. Disable a Network Interface

This command deactivates the specified network interface, eth0.

ifconfig eth0 down

4. Assign an IP Address

This command assigns the IP address 192.168.1.10 to the specified network interface, eth0.

ifconfig eth0 192.168.1.10

5. Set a Netmask

This command sets the netmask for the specified network interface, eth0.

ifconfig eth0 netmask 255.255.255.0

6. Set a Broadcast Address

This command sets the broadcast address for the specified network interface, eth0.

ifconfig eth0 broadcast 192.168.1.255

7. Change the MAC Address

This command changes the MAC address of the specified network interface, eth0.

ifconfig eth0 hw ether 00:1a:2b:3c:4d:5e

8. Add an Alias to a Network Interface

This command adds an alias with IP address 192.168.1.20 to the specified network interface, eth0.

ifconfig eth0:0 192.168.1.20

9. Remove an Alias from a Network Interface

This command removes the alias eth0:0 from the specified network interface.

ifconfig eth0:0 down