VLAN240IP=$( ip add sh to 10.25.240.0/24 | sed -n '/inet/s/.*inet \([0-9.]\+\)\/24 .*/\1/p' ) VLAN252IP=$( ip add sh to 10.25.252.0/24 | sed -n '/inet/s/.*inet \([0-9.]\+\)\/24 .*/\1/p' ) while [ -z "${VLAN240IP}" -o -z "${VLAN252IP}" ]; do sleep 1 VLAN240IP=$( ip add sh to 10.25.240.0/24 | sed -n '/inet/s/.*inet \([0-9.]\+\)\/24 .*/\1/p' ) VLAN252IP=$( ip add sh to 10.25.252.0/24 | sed -n '/inet/s/.*inet \([0-9.]\+\)\/24 .*/\1/p' ) done ip ro add default via 10.25.240.254 dev mlnx0p2 src ${VLAN240IP} ip ro add default via 10.25.252.254 dev em2 src ${VLAN252IP} table 100 ip ru add from ${VLAN252IP} table 100 prio 100