diff options
author | Chase Qi <chase.qi@linaro.org> | 2017-11-17 15:26:03 +0800 |
---|---|---|
committer | Chase Qi <chase.qi@linaro.org> | 2017-11-20 20:48:35 +0800 |
commit | 721401ef18d42b9c63acb01fda5c290e5eadfc0f (patch) | |
tree | 83260428b71dc36611248d0e1294eec8dd12def6 | |
parent | 6ea0a7ce5bca6d0b667cfcbe608a802001ab12b4 (diff) |
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 <chase.qi@linaro.org>
-rwxr-xr-x | automated/linux/network-basic/network-basic.sh | 6 |
1 files changed, 3 insertions, 3 deletions
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" |