From 5e3689198f089462765893389f6cf853ec53d97c Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Tue, 20 Jun 2017 23:59:13 -0500 Subject: [PATCH] Improve network interfaces - Better detection of default network interface when the 'route' command is not available --- vpnsetup.sh | 7 ++++--- vpnsetup_centos.sh | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index cdc0f8a..ea5bb35 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Script for automatic setup of an IPsec VPN server on Ubuntu LTS and Debian 8. +# Script for automatic setup of an IPsec VPN server on Ubuntu LTS and Debian. # Works on any dedicated server or Virtual Private Server (VPS) except OpenVZ. # # DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! @@ -66,13 +66,14 @@ if [ "$(id -u)" != 0 ]; then fi NET_IFACE=${VPN_NET_IFACE:-'eth0'} -DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')" +DEF_IFACE="$(route 2>/dev/null | grep '^default' | grep -o '[^ ]*$')" +[ -z "$DEF_IFACE" ] && DEF_IFACE="$(ip -4 route list 0/0 2>/dev/null | grep -Po '(?<=dev )(\S+)')" if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then if ! grep -qs raspbian /etc/os-release; then case "$DEF_IFACE" in - wlan*) + wl*) cat 1>&2 </dev/null) if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then if ! grep -qs raspbian /etc/os-release; then case "$DEF_IFACE" in - wlan*) + wl*) cat 1>&2 <