1
0
mirror of synced 2025-01-30 20:11:45 +03:00

Improve network interfaces

- Better detection of default network interface when the 'route'
  command is not available
This commit is contained in:
hwdsl2 2017-06-20 23:59:13 -05:00
parent c01fb79650
commit 5e3689198f
2 changed files with 7 additions and 5 deletions

View File

@ -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 <<EOF
Error: Default network interface '$DEF_IFACE' detected.

View File

@ -61,13 +61,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 <<EOF
Error: Default network interface '$DEF_IFACE' detected.