*BSD News Article 67637


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!inquo!vyzynz!news.dacom.co.kr!usenet.seri.re.kr!news.cais.net!nntp.primenet.com!news.asu.edu!ennfs.eas.asu.edu!cs.utexas.edu!news.unt.edu!mikye
From: mikye@jove.acs.unt.edu (Myong In Kye)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: user-ppp and kernel-ppp setup example
Date: 4 May 1996 05:24:59 GMT
Organization: University of North Texas
Lines: 532
Message-ID: <4mepnb$789@hermes.acs.unt.edu>
NNTP-Posting-Host: jove.acs.unt.edu
X-Newsreader: TIN [version 1.2 PL2]

Hi,
I hope the following examples could be a help to some FreeBSD users.
Thanks.

---------------------------------------------------------------------------
<<< USER PPP (a.k.a. iijppp) >>>

The following is a working example of a simple configuration of
user ppp (a.k.a. iijppp): 
N.B. Most of these are adapted from FreeBSD handbook.
N.B. The deivice for iijppp is tunN (tun0,...) and is built-in
     in the generic kernel. No need to recompile or reinstall kernel.

/etc/sysconfig
==============
### Start Of Netconfig Section ###
hostname=mypc
defaultdomainname=NO
tcp_extensions=YES

#----------------------------------------
# Loopback & User PPP (iijppp)
network_interfaces="lo0 tun0"
ifconfig_lo0="inet localhost"
ifconfig_tun0="inet ${hostname} ppp-gateway netmask 0xffffff00"
#----------------------------------------

#----------------------------------------
static_routes="loopback"
route_loopback="${hostname} localhost"
#----------------------------------------

defaultrouter=NO
routedflags=NO
timedflags=NO
xntpdflags="NO"
tickadjflags="-Aq"
ntpdate="NO"
rwhod=NO
sendmail_flags="-bd"
amdflags="NO"
nfs_client=NO
nfs_server=NO
nis_clientflags="NO"
nis_serverflags="NO"
yppasswddflags="NO"
namedflags="NO"
xtend=NO
savecore=NO
kerberos_server=NO
gated=NO

check_quotas=NO
accounting=NO
### End Of Netconfig Section ###

/etc/hosts
==========
127.0.0.1               localhost loghost localhost.my.domain
10.0.0.1                mypc mypc       # my machine
123.456.7.100           ppp-gateway     # My ISP's PPP GATEWAY

/etc/host.conf
==============
hosts
bind

/etc/resolv.conf
================
domain          xxx.com
nameserver      123.456.7.1
nameserver      123.456.7.11
nameserver      123.456.7.22
nameserver      123.456.7.33

/etc/ppp/ppp.conf
=================
#--------------------
# default: always
#--------------------
default:
 set device /dev/modem
# /dev/modem -> /dev/cuaaN   (symbolic link to real modem device)
 set speed 57600
 set parity none
 disable lqr pred1
 deny lqr pred1
 set dial "ABORT BUSY ABORT NO\\sCARRIER ABORT NO\\sDIAL\\sTONE TIMEOUT 5 \"\" ATZ OK AT!@#$% OK \\dATDT\\T TIMEOUT 30 CONNECT"
# use your modem's init string in place of !@#$%, or omit "AT!@#$% OK"
#--------------------
# myisp site: ppp with PAP authentication, dynamic IP assignment
#--------------------
myisp:
 set phone 9876543
 accept pap
 set authname MyLoginName
 set authkey  MyPassword
 set login "TIMEOUT 5 command:-\\r-command: ppp Switching\\sto\\sPPP."
#set login "TIMEOUT 5 login:-\\r-login: MyLoginName password: MyPassword"
# login string depends on your ISP's terminal server menu
 set timeout 0
 set openmode active
 set ifaddr 0 0

/etc/ppp/ppp.linkup
===================
MYADDR:
 add 0 0 HISADDR

/etc/ppp/ppp.secret (optional)
===================
root   RootPassword
userx  UserxPassword

NOTE: 1) Reboot when necessary.
      2) After dialing into your ISP, do not shell out from "PPP ON ...>"
	 prompt. Just leave it as it is.
	 Use another tty (<Alt><F2> keys) if you are on charater terminal,
	 or use another window if on x-window.

<<< USER PPP (a.k.a. iijppp) >>>
---------------------------------------------------------------------------

---------------------------------------------------------------------------
<<< KERNEL PPP >>>

The following scripts have been working fine on my FreeBSD box at home,
for ppp connection.  Most parts are collected from FreeBSD, and kermit
sites, with only a small portion of my own modifications.

I have had no problem using it for ppp connection with my ISP.
My bet is that it should work with your FreeBSD box with little 
modifications.

Assumptions:
1. Your kernel has been configured and recompiled with ppp0 device
   enabled. Otherwise, you have to recompile and install your kernel
   with ppp0 device enabled.
2. You have pppd program installed.
3. You have kermit program installed.
   (Kermit is my favorite dialup program :-) working with ppp)
   (It is the most reliable/flexible dialup package for me, at least.)


RELATED WEB SITES:

FreeBSD Handbook:
http://www.freebsd.org/handbook/
FreeBSD PPP and SLIP:
http://www.freebsd.org/handbook/handbook147.html#269
FreeBSD Kernel PPP:
http://www.freebsd.org/handbook/handbook156.html#281
FreeBSD Kernel PPP working as a PPP client:
http://www.freebsd.org/handbook/handbook157.html#282

C-Kermit 5A(190)
FreeBSD Binary:
ftp://ftp.cdrom.com/....../freebsd.../package.../c-kermit (?)
Sources:
ftp://kermit.columbia.edu/kermit/archives/cku190.tar.Z
ftp://kermit.columbia.edu/kermit/archives/cku190.tar.gz
ftp://kermit.columbia.edu/kermit/c-kermit
Web page:
http://www.columbia.edu/kermit/
http://www.columbia.edu/kermit/unix.html


NETWORK/PPP RELATED FILES:

/etc/sysconfig
==============
### Start Of Netconfig Section ###
hostname=mypc
defaultdomainname=NO
tcp_extensions=YES

#----------------------------------------
# Loopback
network_interfaces="lo0"
ifconfig_lo0="inet localhost"
#----------------------------------------

#----------------------------------------
static_routes="loopback"
route_loopback="${hostname} localhost"
#----------------------------------------

defaultrouter=NO
routedflags=NO
timedflags=NO
xntpdflags="NO"
tickadjflags="-Aq"
ntpdate="NO"
rwhod=NO
sendmail_flags="-bd"
amdflags="NO"
nfs_client=NO
nfs_server=NO
nis_clientflags="NO"
nis_serverflags="NO"
yppasswddflags="NO"
namedflags="NO"
xtend=NO
savecore=NO
kerberos_server=NO
gated=NO

check_quotas=NO
accounting=NO
### End Of Netconfig Section ###

/etc/hosts
==========
127.0.0.1               localhost loghost localhost.my.domain
10.0.0.1                mypc mypc       # my machine
123.456.7.100           ppp-gateway     # My ISP's PPP GATEWAY

/etc/host.conf
==============
hosts
bind

/etc/resolv.conf
================
domain          xxx.com
nameserver      123.456.7.1
nameserver      123.456.7.11
nameserver      123.456.7.22
nameserver      123.456.7.33

/etc/ppp/options
================
crtscts         # enable hardware flow control
modem           # modem control line
noipdefault     # remote PPP server must supply your IP address.
passive         # wait for LCP packets
domain xxx.com  # put your domain name here

:123.456.7.100  # put the IP of remote PPP gateway here
		# My IP: dynamically assigned

defaultroute    # put this if you want that PPP server will be your
		# default router
+ua /etc/ppp/pap-ua             # client side: PAP user & password


/etc/ppp/pap-ua
===============
MyLoginname
MyPassword


SHELL SCRIPTS:

/etc/ppp/pppdial
================
#!/bin/sh
# kermit-pppdial
echo '- kermit-pppdial'
exec kermit -y /etc/ppp/pppdial.kermit


/etc/ppp/pppup
==============
#!/bin/sh
# check ppp connection down
echo '- checking ppp0 down'
ifconfig ppp0 down
ifconfig ppp0 delete
# run pppd
echo '- pppd starts'
exec pppd /dev/modem 57600


/etc/ppp/ppptest
================
#!/bin/sh
DEVICE=ppp0
echo '* ckecking pppd'
pid=`cat /var/run/$DEVICE.pid`
if [ "X${pid}" != "X" ] ; then
	echo 'pppd running: PID=' ${pid-NONE}
else
	echo 'No pppd running.'
fi
echo '* netstat -n -I ppp0'
netstat -n -I ppp0
echo '* ifconfig ppp0'
ifconfig ppp0


/etc/ppp/pppdown
================
#!/bin/sh
DEVICE=ppp0
# kill pppd process
echo '- killing pppd process'
# If the ppp0 pid file is present then the program is running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
	kill -INT `cat /var/run/$DEVICE.pid`
#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
#
	if [ ! "$?" = "0" ]; then
		rm -f /var/run/$DEVICE.pid
		echo "ERROR: Removed stale pid file"
	else
		# Success. Let pppd clean up its own junk.
		echo "PPP link to $DEVICE terminated."
	fi
else
	# The ppp process is not running for ppp0
	echo "ERROR: PPP link is not active on $DEVICE"
fi

sleep 1
# down ppp connection
echo '- checking ppp0 down'
ifconfig ppp0 down
ifconfig ppp0 delete

# kill pppdial process
echo '- killing kermit-pppdial process'
pid=`ps -ax | grep kermit | grep -v grep | awk '{print $1;}'`
if [ "${pid}" != "" ] ; then
	#echo 'killing kermit, PID=' ${pid}
	kill -KILL ${pid}
fi
rm -f /var/spool/lock/LCK..modem


/etc/ppp/pppdial.kermit
=======================
;
; File: pppdial.kermit : kermit script to PPP-dial to my ISP
;

define chkerr if fail stop 1 \%1
define chkok input 3 OK, if fail stop 1 \%1
def errfail echo \%1, hangup, goto fail ; Macro to handle failures.

; ---------------------------------------
; MY MODEM
set modem sportster     ; YOUR MODEM TYPE!!!!!! (probably omittable ?!)
set line /dev/modem     ; SET LINE TO YOUR MODEM DEVICE !!!!!!
if fail end 1
set speed 57600         ; SET SPEED !!!!!!
if fail end 1
set flow none
set term bytesize 8
; ---------------------------------------

;----------------------------------------
; PHONE NUMBER
declare \&a[3]
assign  \&a[1] 987-6543
assign  \&a[2] 987-6542
assign  \&a[3] 987-6541
assign \%p ppp
;----------------------------------------

; ---------------------------------------------------------------
set file type binary            ; Binary mode

set carrier OFF                 ; Don't require carrier during dialing.

set input echo on               ; So we can watch what happens.
set input timeout proceed       ; Allow IF SUCCESS, IF FAILURE.
set input case ignore           ; Use caseless string comparisons

set parity none                 ; Avoid parity foulups
set flow none                   ; Avoid flow control deadlocks
hangup                          ; Begin by dropping DTR
pause 1                         ; for one second

echo Configuring MyModem on \v(line).

; ---------------------------------------------------------------
:INIT
output ATZ\13
chkok {Can't get modem's attention}
;output AT M0\13                ; Silence the modem
;chkok {Can't silence the modem}
;output AT L0\13                ; Lower the volume of modem
;chkok {Can't lower modem's volume}
;output AT !@#$%^&...\13        ; USE YOUR MODEM'S INIT STRING !!!!!!
;chkok {Can't initialize my modem}
output AT &C1&D2\13
chkok {Can't adjust DCD & DTR}

if def \%n if not equal "\%n" "=" goto BEGIN
echo Modem initialization complete, no number to dial
end 0

:BEGIN                          ; Now DIAL.
clear                           ; Clear INPUT buffer.
set count 60                    ; Dialing retry counter, 60 tries allowed.
echo
echo Dialing \%n on \v(line) at \v(speed) bps, wait...
pause 1
goto dial                       ; 1st time, skip pause and Redialing message

:REDIAL
if eq \%n \&a[1] assign \%n \&a[2]
else if eq \%n \&a[2] assign \%n \&a[3]
else assign \%n \&a[1]          ; Try alternate dial number
pause 1                         ; Wait 1 second before redialing.
echo Redialing \%n ...          ; Message for redialing.

:DIAL
output ATDT\%n\13               ; Dial the number.
clear input                     ; Clear echo from INPUT buffer.
input 30 \10                    ; Wait for the linefeeds...

:GETMSG
input 30 \10                    ; ...that surround the response message.
if success goto gotmsg          ; Got a message.
output \13                      ; cancel dialing by sending carriage return,
hangup                          ; User interrupted from keyboard,
output \13                      ; cancel dialing by sending carriage return,
goto again                      ; and go try again right away.

:GOTMSG
reinput 1 CONNECT               ; Got a message, was it CONNECT?
if success goto done            ; If so, we're done.
reinput 1 BUSY                  ; Line is busy.
if success goto busy            ; Go wait a while and then dial again.
reinput 1 ERROR                 ; Command syntax error.
if success errfail {Dialing command error}
reinput 1 NO CARRIER            ; Phone didn't answer or no carrier.
if success errfail {No answer or no carrier}
reinput 1 NO ANSWER             ; No answer
if success errfail {No answer - try again later}
reinput 1 NO DIAL TONE          ; No dialtone when phone taken off hook.
if success errfail {No dialtone - Is your modem connected to the phone line\63}
goto getmsg                     ; None of the above, get another message.

:BUSY
if < \v(count) 2 goto quit      ; Don't wait 1 seconds if tries are used up.
Echo Line is busy, will dial again in 1 seconds.
echo Press ^C to cancel...
output \13                      ; CR cancels dialing
hangup                          ; Hang up.
:AGAIN
if count goto redial            ; Then go redial.
:QUIT
errfail {It never answers!  I give up.} ; Too many tries.

:DONE                           ; Connected.
echo \7                         ; Celebrate with a beep.
set carrier on                  ; Require carrier from now on.
goto NEXT

:FAIL                           ; Dialing failed, no beep.
if count goto redial            ; Retry
define errfail                  ; Erase local macro definitions...
set carrier off                 ; So they can CONNECT and see what's up...
end 1                           ; Return failure code.

; ---------------------------------------------------------------

:NEXT
pause 1

; Check my ISP's Terminal Server Menu
; This part depends on your ISP's terminal server menu!!!
output \13
input 5 command:
if success echo {\x0aNow at my ISP's Dialup Menu}
else errfail {My ISP's menu not showing up! Too bad!}
pause 1

; start PPP
; This part depends on your ISP's terminal server menu!!!
output \%p\13
input 5 Switching\ to\ PPP.
if success echo {\x0a\x0aNow PPP login starts.}
else errfail {\x0a\x0aPPP not responding. Too bad!}

echo {kermit-pppdial script completed!}
echo \7
suspend

:FAIL
define errfail                  ; Erase local macro definitions...
end 0                           ; Finished, return success code.

; END OF PPPDIAL.KERMIT
; ---------------------------------------------------------------

MISCELLANEOUS STUFF:
Note 0:
Reboot if necessary.

Note 1:
Make a symbolic link (/dev/modem) to your real modem device:
# ln -s /dev/cuaaN /dev/modem
(Replcae N with 0, 1, 2, or 3 depending on serial port number
for your modem device.)
Effect:
/dev/modem -> /dev/cuaaN

Note 2:
Enable execute permission for the following files:
/etc/ppp/pppdial
/etc/ppp/pppup
/etc/ppp/ppptest
/etc/ppp/pppdown

Note 3:
Make some aliases in your .cshrc (.tcshrc) file:
alias pppdial /etc/ppp/pppdial
alias pppup   /etc/ppp/pppup
alias ppptest /etc/ppp/ppptest
alias pppdown /etc/ppp/pppdown

Note 4:
Reboot if necessary.

USAGE:
How to use the above shell scripts to use ppp:
# pppdial         ; dial up your ISP host
# pppup           ; activate ppp
......
run your network applications
......
# pppdown         ; deactivate ppp and hangup

<<< KERNEL PPP >>>
---------------------------------------------------------------------------