Bird
Raised Fist0
Linux CLIscripting~5 mins

ifconfig and ip addr in Linux CLI - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes you need to see the details of your computer's network connections. The commands ifconfig and ip addr help you check your network interfaces and their settings like IP addresses. This helps you understand or fix network problems.
When you want to see the IP address assigned to your computer.
When you need to check if a network interface is active or down.
When you want to find the MAC address of your network card.
When troubleshooting network connection issues.
When configuring or verifying network settings on a Linux machine.
Commands
This command shows all active network interfaces and their details like IP address and MAC address.
Terminal
ifconfig
Expected OutputExpected
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 1000 bytes 1234567 (1.2 MB) TX packets 800 bytes 987654 (987.6 KB) Interrupt:19 Base address:0x2000
This command shows all network interfaces with detailed information including IP addresses and interface status.
Terminal
ip addr
Expected OutputExpected
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:4e:66:a1 brd ff:ff:ff:ff:ff:ff inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0 valid_lft 86394sec preferred_lft 86394sec inet6 fe80::a00:27ff:fe4e:66a1/64 scope link valid_lft forever preferred_lft forever
Key Concept

If you remember nothing else, remember: 'ip addr' is the modern, more detailed command to check network interfaces, while 'ifconfig' is older but still commonly used.

Common Mistakes
Trying to use ifconfig on a system where it is not installed by default.
Many modern Linux systems do not include ifconfig by default, so the command will fail.
Use 'ip addr' instead, which is installed by default on modern Linux systems.
Running 'ifconfig' without root privileges and expecting to see all interfaces.
Some interfaces or details may not show without proper permissions.
Run 'sudo ifconfig' or 'sudo ip addr' to see all details.
Summary
Use 'ifconfig' to quickly see active network interfaces and their IP addresses on older systems.
Use 'ip addr' for a detailed and modern view of all network interfaces and their settings.
Both commands help you check network status and troubleshoot connection issues.

Practice

(1/5)
1. What is the main purpose of the ifconfig and ip addr commands in Linux?
easy
A. To manage user accounts
B. To edit text files in the system
C. To monitor CPU usage
D. To display network interface details and IP addresses

Solution

  1. Step 1: Understand command purpose

    The commands ifconfig and ip addr are used to show details about network interfaces and their IP addresses.
  2. Step 2: Eliminate unrelated options

    Options about editing files, managing users, or CPU monitoring do not relate to network interfaces.
  3. Final Answer:

    To display network interface details and IP addresses -> Option D
  4. Quick Check:

    Network info = C [OK]
Hint: Remember: both commands show network info, not files or users [OK]
Common Mistakes:
  • Confusing network commands with file editing tools
  • Thinking these commands manage users
  • Assuming they monitor CPU or memory
2. Which of the following is the correct syntax to display all IP addresses using the ip command?
easy
A. ip address list all
B. ip show addr
C. ip addr show
D. ip display ip

Solution

  1. Step 1: Recall correct command syntax

    The correct syntax to show IP addresses is ip addr show or simply ip addr.
  2. Step 2: Check other options for errors

    Options B, C, and D use incorrect order or invalid keywords.
  3. Final Answer:

    ip addr show -> Option C
  4. Quick Check:

    Correct syntax = A [OK]
Hint: Remember: 'ip addr show' is the standard order [OK]
Common Mistakes:
  • Swapping 'addr' and 'show' order
  • Using invalid keywords like 'display' or 'list all'
  • Adding unnecessary words
3. What will be the output of the command ifconfig eth0 if the interface eth0 is up with IP 192.168.1.10 and netmask 255.255.255.0?
medium
A. Shows interface eth0 details including IP 192.168.1.10 and netmask 255.255.255.0
B. Shows only the MAC address of eth0
C. Shows error: interface eth0 not found
D. Shows CPU usage statistics

Solution

  1. Step 1: Understand ifconfig eth0 output

    This command displays detailed info about the eth0 interface, including IP address and netmask if the interface is up.
  2. Step 2: Eliminate unrelated outputs

    It does not show only MAC address, CPU stats, or error if interface exists and is up.
  3. Final Answer:

    Shows interface eth0 details including IP 192.168.1.10 and netmask 255.255.255.0 -> Option A
  4. Quick Check:

    ifconfig eth0 shows IP and netmask = D [OK]
Hint: ifconfig with interface name shows full details [OK]
Common Mistakes:
  • Expecting only MAC address output
  • Assuming error if interface is active
  • Confusing with CPU or system stats
4. You run ip addr show eth0 but get no output. What is the most likely reason?
medium
A. The eth0 interface does not exist or is down
B. You need to run the command as root
C. The command syntax is incorrect
D. The IP address is not assigned yet

Solution

  1. Step 1: Analyze command behavior

    If ip addr show eth0 returns no output, it usually means the interface eth0 does not exist or is disabled.
  2. Step 2: Check other options

    Running as root is not required to show interfaces; syntax is correct; lack of IP alone does not cause no output.
  3. Final Answer:

    The eth0 interface does not exist or is down -> Option A
  4. Quick Check:

    No output means interface missing/down = B [OK]
Hint: No output usually means interface missing or down [OK]
Common Mistakes:
  • Assuming root is needed to view interfaces
  • Thinking syntax is wrong
  • Confusing no IP with no output
5. You want to write a script that checks if the interface eth1 has an IP address assigned using ip addr. Which command snippet correctly tests this?
hard
A. ifconfig eth1 | grep -q 'inet6 '; then echo 'IP assigned'; else echo 'No IP'; fi
B. if ip addr show eth1 | grep -q 'inet '; then echo 'IP assigned'; else echo 'No IP'; fi
C. ip addr show eth1 | grep -q 'ether '; then echo 'IP assigned'; else echo 'No IP'; fi
D. if ip link show eth1 | grep -q 'UP'; then echo 'IP assigned'; else echo 'No IP'; fi

Solution

  1. Step 1: Identify correct IP address check

    The command ip addr show eth1 lists addresses; searching for 'inet ' finds IPv4 addresses assigned.
  2. Step 2: Evaluate other options

    ifconfig eth1 | grep -q 'inet6 '; then echo 'IP assigned'; else echo 'No IP'; fi checks IPv6 with ifconfig but question asks for ip addr. ip addr show eth1 | grep -q 'ether '; then echo 'IP assigned'; else echo 'No IP'; fi looks for MAC address ('ether'), not IP. if ip link show eth1 | grep -q 'UP'; then echo 'IP assigned'; else echo 'No IP'; fi checks interface status, not IP assignment.
  3. Final Answer:

    if ip addr show eth1 | grep -q 'inet '; then echo 'IP assigned'; else echo 'No IP'; fi -> Option B
  4. Quick Check:

    Check 'inet ' in ip addr output = A [OK]
Hint: Search 'inet ' in ip addr output to find IPv4 address [OK]
Common Mistakes:
  • Checking MAC address instead of IP
  • Using ip link instead of ip addr
  • Confusing IPv6 with IPv4 check
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard