Which commands retrieve a network interface's IP address and its default gateway using iproute2?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

Which commands retrieve a network interface's IP address and its default gateway using iproute2?

Explanation:
When using iproute2, you get both the host’s addresses and the default gateway by inspecting two aspects: the configured IPs on interfaces and the routing table. The command that lists all IP addresses on every interface is ip addr show. It reveals which interface has which IPv4 or IPv6 address, along with their scope and prefixes. The command that shows how traffic is routed is ip route show. The routing table includes a default route entry, usually phrased as a default via <gateway> on a specific interface, which is exactly the default gateway used to reach outside networks. Together, these two commands give you the IP address information and the default gateway in one go, using the modern, standard toolset. Older tools like ifconfig and netstat -rn are deprecated or provide incomplete views on modern systems. ip route show plus ip addr show specifically targets the needed data. ip route show with ip neigh show would reveal ARP/neighbor entries, not the default gateway itself, and ip link show only shows interface state and hardware details, not the IPs or the gateway. ip route get 0.0.0.0 can show the route used to reach a destination, but it doesn’t provide a complete listing of all interface IPs.

When using iproute2, you get both the host’s addresses and the default gateway by inspecting two aspects: the configured IPs on interfaces and the routing table. The command that lists all IP addresses on every interface is ip addr show. It reveals which interface has which IPv4 or IPv6 address, along with their scope and prefixes. The command that shows how traffic is routed is ip route show. The routing table includes a default route entry, usually phrased as a default via on a specific interface, which is exactly the default gateway used to reach outside networks.

Together, these two commands give you the IP address information and the default gateway in one go, using the modern, standard toolset.

Older tools like ifconfig and netstat -rn are deprecated or provide incomplete views on modern systems. ip route show plus ip addr show specifically targets the needed data. ip route show with ip neigh show would reveal ARP/neighbor entries, not the default gateway itself, and ip link show only shows interface state and hardware details, not the IPs or the gateway. ip route get 0.0.0.0 can show the route used to reach a destination, but it doesn’t provide a complete listing of all interface IPs.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy