From 721401ef18d42b9c63acb01fda5c290e5eadfc0f Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Fri, 17 Nov 2017 15:26:03 +0800 Subject: linux: network-basic: cover multiple subnets On system uses multiple subnets, there is more then one gateway in route table. For example: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.11.1 0.0.0.0 UG 100 0 0 enp0s25 default 192.168.0.1 0.0.0.0 UG 600 0 0 wlp3s0 This patch: * Test the top default interface by default as it is the default interface for all traffics. * Obtain gateway by interface under test. Change-Id: I42328fcdf592ea2cb0ad35a43daa12833a60e415 Signed-off-by: Chase Qi --- automated/linux/network-basic/network-basic.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'automated') diff --git a/automated/linux/network-basic/network-basic.sh b/automated/linux/network-basic/network-basic.sh index 0c5dd8c..8160074 100755 --- a/automated/linux/network-basic/network-basic.sh +++ b/automated/linux/network-basic/network-basic.sh @@ -40,9 +40,9 @@ create_out_dir "${OUTPUT}" install # When not specified, test the default interface. -test -z "${INTERFACE}" && INTERFACE=$(route | grep default | awk '{print $NF}') -# Get default Route Gateway IP address of a given interface -GATEWAY=$(ip route list | grep default | awk '{print $3}') +test -z "${INTERFACE}" && INTERFACE=$(route | grep -m 1 "^default" | awk '{print $NF}') +# Get Route Gateway IP address of a given interface. +GATEWAY=$(route | grep -m 1 "^default.*${INTERFACE}$" | awk '{print $2}') run "netstat -an" "print-network-statistics" run "ip addr" "list-all-network-interfaces" -- cgit v1.2.3