2012年10月6日 星期六

[L2TP] How to connect to Home network by using l2tp


This script will automatic build up the enviroment.
Set routing table.
And connect to Home network.



#!/bin/bash
#sudo aptitude install xl2tpd
Second=3
interface_number=$(ifconfig | grep “Link encap” | cut -d ’ ’ -f 1 | wc -l)

echo ” ”
echo ” ”
echo ” \033[1;31m Please ‘sudo su’ first \033[m” # sudo su –> change to root privilege
echo ” *****************************************************************
echo ” * *
for i in interface_number);
do
eval interface(ifconfig | grep “Link encap” | cut -d ’ ’ -f 1 | sed -n “i p”)
eval echo ’interface$i | xargs -i echo ” * “{}” *
done
echo ” * *
echo ” *****************************************************************
echo “Please input interface : “
read input # read character input
eval echo ‘input

cd /etc/xl2tpd/

if test -e /etc/xl2tpd/xl2tpd.conf; then
sudo cp /etc/xl2tpd/xl2tpd.conf /etc/xl2tpd/xl2tpd.conf.bak
sudo rm /etc/xl2tpd/xl2tpd.conf
fi

cd ~

if ! test -e ~/xl2tpd.conf; then
touch xl2tpd.conf
echo “[global]” >> ~/xl2tpd.conf
echo “access control = no” >> ~/xl2tpd.conf
echo “port = 1701” >> ~/xl2tpd.conf
echo “[lac testvpn]” >> ~/xl2tpd.conf
echo “name = someone” >> ~/xl2tpd.conf
echo “lns = ‘The IP of remote of WAN IP’” >> ~/xl2tpd.conf # change to echo “lns = xxx.xxx.xxx.xxx” >> ~/xl2tpd.conf
echo “pppoptfile = /etc/ppp/peers/testvpn.l2tpd” >> ~/xl2tpd.conf
echo “ppp debug = no” >> ~/xl2tpd.conf
fi

sudo cp ~/xl2tpd.conf /etc/xl2tpd/

if ! test -e ~/testvpn.l2tpd; then
touch testvpn.l2tpd
echo “remotename testvpn” >> ~/testvpn.l2tpd
echo ‘user “The authorize name of remote WAN IP”’ >> ~/testvpn.l2tpd # change to echo ‘user “Hello”’ >> ~/testvpn.l2tpd
echo ‘password “The authorize password of remote WAN IP”’ >> ~/testvpn.l2tpd # change to echo ‘password “World”’ >> ~/testvpn.l2tpd
echo “unit 0” >> ~/testvpn.l2tpd
echo “lock” >> ~/testvpn.l2tpd
echo “nodeflate” >> ~/testvpn.l2tpd
echo “nobsdcomp” >> ~/testvpn.l2tpd
echo “noauth” >> ~/testvpn.l2tpd
echo “persist” >> ~/testvpn.l2tpd
echo “nopcomp” >> ~/testvpn.l2tpd
echo “noaccomp” >> ~/testvpn.l2tpd
echo “maxfail 5” >> ~/testvpn.l2tpd
echo “debug” >> ~/testvpn.l2tpd
fi

sudo cp ~/testvpn.l2tpd /etc/ppp/peers/
xl2tpd -c /etc/xl2tpd/testvpn.options
sudo echo ‘c testvpn’ > /var/run/xl2tpd/l2tp-control
ip_address=input | cut -d ’ ’ -f 3)
echo ip_address # Change to route add -host xxx.xxx.xxx.xxx gw Second” second”
sleep $Second # must wait for few second to wait ppp0 up
route add default ppp0


Reference :

Related Posts:

0 意見:

張貼留言