Last active
August 19, 2018 13:58
-
-
Save gomasy/40d0c589d5d233c443777fda48598a0b to your computer and use it in GitHub Desktop.
xl2tpd により L2TP コネクションが確立した際に自動的に経路を追加するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script is run by pppd after the link is established. | |
# It executes all the scripts available in /etc/ppp/ip-up.d directory, | |
# with the following parameters: | |
# $1 = interface name (e.g. ppp0) | |
# $2 = tty device | |
# $3 = speed | |
# $4 = local IP address | |
# $5 = remote IP address | |
# $6 = ipparam (user specified parameter, see man pppd) | |
function getConnStatus() { | |
/sbin/ifconfig $1 | grep 'inet ' | wc -l | |
} | |
function getGatewayIp() { | |
/sbin/route -n | grep -m 1 "^0\.0\.0\.0" | awk '{print $2}' | |
} | |
if [ $(getConnStatus wlp3s0) -gt 0 ]; then | |
if='wlp3s0' | |
elif [ $(getConnStatus enp1s0) -gt 0 ]; then | |
if='enp1s0' | |
else | |
echo 'Unsupported interface.' | |
exit 1 | |
fi | |
/usr/bin/ip route add ***.***.***.*** via $(getGatewayIp $if) dev $if | |
/usr/bin/ip route add default via $5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment