Bird
0
0

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📝 Application Q15 of 15
Linux CLI - Networking Commands
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?
Aifconfig eth1 | grep -q 'inet6 '; then echo 'IP assigned'; else echo 'No IP'; fi
Bif ip addr show eth1 | grep -q 'inet '; then echo 'IP assigned'; else echo 'No IP'; fi
Cip addr show eth1 | grep -q 'ether '; then echo 'IP assigned'; else echo 'No IP'; fi
Dif ip link show eth1 | grep -q 'UP'; then echo 'IP assigned'; else echo 'No IP'; fi
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes