Wednesday, October 10, 2012

pon and poff script

if your distro does not provide pon and poff command, you can add the pon/poff script by yourself and make them executable

pon
---------------------------------------------

#!/bin/sh

while [ $# -ge 1 ]; do
case "$1" in
  --quick|-q)
    QUICK=true
    shift
    ;;
  -*)
    echo "\
Usage: pon [OPTIONS] [provider] [arguments]
  -q|--quick           pppd hangs up after all ip-up scripts are run

If pon is invoked without arguments, /etc/ppp/ppp_on_boot file will be
run, presuming it exists and is executable. Otherwise, a PPP connection
will be started using settings from /etc/ppp/peers/provider.
If you specify one argument, a PPP connection will be started using
settings from the appropriate file in the /etc/ppp/peers/ directory, and
any additional arguments supplied will be passed as extra arguments to
pppd.
"
    exit 0
    ;;
  *)
    break
    ;;
esac
done

if [ ! -r /etc/ppp/peers/ ]; then
  echo "Error: only members of the 'dip' group can use this command."
  exit 1
fi

if [ "$1" ]; then
  PROVIDER=$1
  shift
fi

# Perform ppp_on_boot migration from pppoe package.
if [ -L /etc/ppp/ppp_on_boot -a "$(readlink /etc/ppp/ppp_on_boot)" = \
     "ppp_on_boot.dsl" -a ! -e /etc/ppp/ppp_on_boot.dsl ]; then
  rm -f /etc/ppp/ppp_on_boot
  ln -s pppoe_on_boot /etc/ppp/ppp_on_boot
fi

if [ -z "$PROVIDER" ]; then
  if [ -x /etc/ppp/ppp_on_boot ]; then
    [ "$QUICK" ] && touch /var/run/ppp-quick
    exec /etc/ppp/ppp_on_boot
  fi
  # try the default script
  PROVIDER=provider
fi

if [ ! -e "/etc/ppp/peers/$PROVIDER" ]; then
  echo "\
The file /etc/ppp/peers/$PROVIDER does not exist. Please create it or use
a command line argument to use another file in the /etc/ppp/peers/ directory."
  exit 1
fi

[ "$QUICK" ] && touch /var/run/ppp-quick
exec /usr/sbin/pppd call $PROVIDER "$@"


poff
------------------------------------------


#!/bin/sh

# $Id: poff,v 1.8 1999/08/28 16:34:51 phil Exp $
# Written by John Hasler <john@dhh.gt.org> and based on work
# by Phil Hands <phil@hands.com>.  Distributed under the GNU GPL

if [ -x /usr/bin/kill ]; then
  KILL="/usr/bin/kill"
else
  KILL="/bin/kill"
fi
SIG=TERM
DONE="stopped"
MODE=""

usage ()
{
   cat <<!EOF!
usage: $0 [option] [provider]
options:
  -r        Cause pppd to drop the line and redial.
  -d        Toggle the state of pppd's debug option.
  -c        Cause pppd to renegotiate compression.
  -a        Stop all pppd's.  'provider' will be ignored.
  -h        Print this help summary and exit.
  -v        Print version and exit.
  none      Stop pppd.

Options may not be combined.

If 'provider' is omitted pppd will be stopped or signalled if and only if
there is exactly one running unless the '-a' option was given.  If
'provider' is supplied the pppd controlling the connection to that
provider will be stopped or signalled.
!EOF!
}

# Get option.  If there are none replace the "?" that getopts puts in
# FLAG on error with "null".
getopts rdcavh FLAG
if [ "$?" -ne 0 ]; then
    FLAG="null"
fi

# Check for additional options.  Should be none.
getopts :rdcavh DUMMY
if [ "$?" -eq 0 ]; then
    echo "$0: Illegal option -- ${OPTARG}."
    exit 1
fi

case $FLAG in
 "r") SIG=HUP;  DONE=signalled; shift ;;
 "d") SIG=USR1; DONE=signalled; shift ;;
 "c") SIG=USR2; DONE=signalled; shift ;;
 "a") MODE="all"; shift ;;
 "v") echo "$0$Revision: 1.8 $_TrickToPrint_RCS_Revision"; exit 0 ;;
 "h") usage; exit 0 ;;
 "?") exit 1;
esac

# Get the PIDs of all the pppds running.  Could also get these from
# /var/run, but pppd doesn't create .pid files until ppp is up.
PIDS=$(pidof pppd)

# poff is pointless if pppd isn't running.
if [ -z "$PIDS" ]; then
    echo "$0: No pppd is running.  None ${DONE}."
    exit 1
fi

# Find out how many pppd's are running.
N=$(echo "$PIDS" | wc -w)

# If there are no arguments we can't do anything if there is more than one
# pppd running.
if [ "$#" -eq 0 -a "$N" -gt 1 -a $FLAG != "a" ]; then
    echo "$0: More than one pppd running and no "-a" option and
no arguments supplied. Nothing ${DONE}."
    exit 1
fi

# If either there are no arguments or '-a' was specified kill all the
# pppd's.
if [ "$#" -eq 0 -o "$MODE" = "all" ]; then
    $KILL -$SIG $PIDS || {
        echo "$0: $KILL failed.  None ${DONE}."
        exit 1
    }
    exit 0
fi

# There is an argument, so kill the pppd started on that provider.
PEER=$(echo $1 | sed -e 's#/#\\/#g')
PID=$(ps -o pid,cmd axw | awk "/^ *[0-9]* *(\/usr\/sbin\/)?pppd call $PEER( |\$)/ {print \$1}")

if [ "$PID" ]; then
    $KILL -$SIG $PID || {
        echo "$0: $KILL failed.  None ${DONE}."
        exit 1
    }
else
   echo "$0: I could not find a pppd process for provider '$1'. None ${DONE}."
   exit 1
fi
/etc/ppp/peers#
exit 0




sample configuration for internet mobile access, vpn and pppoe in  /etc/ppp/peers#

mobile internet access with hello provider

root@tun-K42JB:/etc/ppp/peers# cat hello
debug
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/hello"
usepeerdns
/dev/ttyACM0 921600
defaultroute
crtscts
lcp-echo-failure 0



vpn sample configuration

root@tun-K42JB:/etc/ppp/peers# cat vpn1
pty "pptp 20.80.2.3  --nolaunchpppd"
name username1
remotename PPTP
require-mppe-128
file /etc/ppp/options.pptp
ipparam vpn1
mru 1412
mtu 1412
 


pppoe sample configuration


root@tun-K42JB:/etc/ppp/peers# cat dsl-provider
# Configuration file for PPP, using PPP over Ethernet
# to connect to a DSL provider.
#
# See the manual page pppd(8) for information on all the options.

##
# Section 1
#
# Stuff to configure...

# MUST CHANGE: Uncomment the following line, replacing the user@provider.net
# by the DSL user name given to your by your DSL provider.
# (There should be a matching entry in /etc/ppp/pap-secrets with the password.)
#user myusername@myprovider.net

# Use the pppoe program to send the ppp packets over the Ethernet link
# This line should work fine if this computer is the only one accessing
# the Internet through this DSL connection. This is the right line to use
# for most people.
#pty "/usr/sbin/pppoe -I eth0 -T 80 -m 1452"

# An even more conservative version of the previous line, if things
# don't work using -m 1452...
#pty "/usr/sbin/pppoe -I eth0 -T 80 -m 1412"

# If the computer connected to the Internet using pppoe is not being used
# by other computers as a gateway to the Internet, you can try the following
# line instead, for a small gain in speed:
#pty "/usr/sbin/pppoe -I eth0 -T 80"


# The following two options should work fine for most DSL users.

# Assumes that your IP address is allocated dynamically
# by your DSL provider...
noipdefault
# Try to get the name server addresses from the ISP.
# Use this connection as the default route.
# Comment out if you already have the correct default route installed.
defaultroute

##
# Section 2
#
# Uncomment if your DSL provider charges by minute connected
# and you want to use demand-dialing.
#
# Disconnect after 300 seconds (5 minutes) of idle time.

#demand
#idle 300

##
# Section 3
#
# You shouldn't need to change these options...

hide-password
lcp-echo-interval 20
lcp-echo-failure 3
# Override any connect script that may have been set in /etc/ppp/options.
connect /bin/true
noauth
persist
mtu 1492

# RFC 2516, paragraph 7 mandates that the following options MUST NOT be
# requested and MUST be rejected if requested by the peer:
# Address-and-Control-Field-Compression (ACFC)
noaccomp
# Asynchronous-Control-Character-Map (ACCM)
default-asyncmap

plugin rp-pppoe.so
nic-wlan0
user "ppp1"


1 comment: