0
0
Bash Scriptingscripting~10 mins

Why network scripts automate connectivity tasks in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the network is reachable by pinging google.com once.

Bash Scripting
ping -c 1 [1]
Drag options to blanks, or click blank then click option'
Aexample.com
Blocalhost
C192.168.1.1
Dgoogle.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' will only test your own machine, not the network.
Using an IP like 192.168.1.1 might not be reachable depending on your network.
2fill in blank
medium

Complete the script to store the IP address of the default gateway in the variable gateway_ip.

Bash Scripting
gateway_ip=$(ip route | grep default | [1] '{print $3}')
Drag options to blanks, or click blank then click option'
Acut
Bawk
Csed
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cut' without specifying delimiter and field might not work as expected.
Using 'sed' is more complex for this simple extraction.
3fill in blank
hard

Fix the error in the script to correctly check if the network interface eth0 is up.

Bash Scripting
if ip link show [1] | grep -q 'state UP'; then
  echo "Interface is up"
else
  echo "Interface is down"
fi
Drag options to blanks, or click blank then click option'
Aeth1
Blo
Ceth0
Dwlan0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lo' checks the loopback interface, which is always up.
Using 'wlan0' checks wireless interface, which may not exist.
4fill in blank
hard

Fill both blanks to create a script that lists all active network interfaces and their IP addresses.

Bash Scripting
ip -o [2] [1] show | awk '{print $2, $4}'
Drag options to blanks, or click blank then click option'
Aaddr
B-4
C-6
Dlink
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-6' lists IPv6 addresses, not IPv4.
Using 'link' does not show IP addresses.
5fill in blank
hard

Fill all three blanks to create a dictionary-like output of interface names and their IPv4 addresses, excluding interfaces without IP.

Bash Scripting
declare -A ip_map
while read -r [1] [2]; do
  ip_map[[1]]=[2]
done < <(ip -o -4 addr show | awk '{print $2, $4}' | cut -d/ -f1)
Drag options to blanks, or click blank then click option'
Aiface
Bip_addr
Cip
Dinterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both interface and IP causes errors.
Not cutting the IP address to remove subnet mask causes wrong values.