Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The command 'ping -c 1 google.com' sends one ping packet to google.com to check connectivity.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
Using awk '{print $3}' extracts the third word from the default route line, which is the gateway IP.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The script checks the status of interface eth0; using the correct interface name is essential.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-6' lists IPv6 addresses, not IPv4.
Using 'link' does not show IP addresses.
✗ Incorrect
The command 'ip -o -4 addr show' lists IPv4 addresses of all interfaces in one line per interface.
5fill in blank
hardFill 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'
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.
✗ Incorrect
The script reads interface name and IP address into variables iface and ip_addr, then stores ip_addr in ip_map with iface as key.