Complete the code to check if a host is reachable using ping.
ping -c 4 [1]
The ping command followed by a hostname or IP address checks connectivity by sending packets. Here, google.com is a common host to test.
Complete the command to display the current network interfaces and their IP addresses.
ip [1]ip route which shows routing tables.ip link which shows interfaces but not IP addresses.The ip addr command shows network interfaces and their IP addresses, helping diagnose connectivity issues.
Fix the error in the command to trace the route packets take to reach a host.
traceroute [1]The traceroute command requires a hostname or IP address to trace the path packets take. Here, google.com is the target host.
Fill both blanks to create a command that shows active network connections and listening ports.
netstat [1] [2]
-t or -u which show TCP or UDP but not all connections.The netstat -a -l command lists all active connections and listening ports, useful for diagnosing network issues.
Fill all three blanks to create a dictionary comprehension that maps interface names to their IP addresses if the IP is IPv4.
interfaces = { [1]: [2] for [3], [2] in ip_addr.items() if '.' in [2] }This dictionary comprehension loops over ip_addr.items(), assigning interface names to iface and IPs to ip. It keeps only IPv4 addresses containing a dot.