一、目标
本文档目标是说明使用Redhat Linux建立拨号服务器。
二、测试环境
软件:
1、Redhat Linux AS5完全安装。
硬件:
1、56K Modem。
注意软猫(win-modem)在Linux下无法使用
三、服务器设置
Modem与服务器的连线接好后,打开Modem电源。在Linux要使用的程序为mgetty和pppd。
1、使用minicom测试Modem与服务器连接。
运行:
minicom -s
出现以下界面:
Filenames and paths
File transfer protocols
Serial port setup
Modem and dialing
Screen and keyboard
Save setup as dfl
Save setup as..
Exit
Exit from Minicom
在出现的选择中选择:Serial port setup
出现以下界面:
A - Serial Device : /dev/ttyS0
B - Lockfile Location : /var/lock
C - Callin Program :
D - Callout Program :
E - Bps/Par/Bits : 57600 8N1
F - Hardware Flow Control : Yes
G - Software Flow Control : No
Change which setting?
一般只需要修改A、E两项。修改完后回车返回。
选择Exit,回车。如果设置正确的话,将看到AT和OK字符如下:
AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0
OK
按Ctrl-A Z X退出minicom。
2、设置mgetty自动运行:
运行以下命令:
echo "S0:2345:respawn:/sbin/mgetty ttyS0" >> /etc/inittab
注意其中的ttyS0为modem连接的串口,请按需要修改。
3、使mgetty自动运行pppd:
运行以下命令:
echo "/AutoPPP/ - a_ppp /usr/sbin/pppd file /etc/ppp/options" >> /etc/mgetty+sendfax/mgetty.config
在/etc/mgetty+sendfax/login.config文件中去掉'AutoPPP'所在行的注释:
/AutoPPP/ - a_ppp /usr/sbin/pppd auth -chap +pap login debug
4、修改pppd运行参数:
运行以下命令:
echo "-chap +pap login debug modem crtscts proxyarp lock lcp-max-terminate 30 lcp-max-failure 30 lcp-echo-interval 5 passive" > /etc/ppp/options
4、IP分配:
运行以下命令:
echo "192.168.1.3:192.168.1.201" > /etc/ppp/options.ttyS0
echo "noauth" >> /etc/ppp/options.ttyS0
5、设置pppd使用系统用户验证登录:
echo "* * "" *" /etc/ppp/pap-secrets
6、新建用户和组,并设置密码:
运行以下命令:
groupadd -g 1001 ppp
adduser thinker
passwd thinker
7、修改用户shell:
编辑/etc/passwd文件,将thinker用户一行改为如下内容:
thinker:x:1001:1001:,,,:/home/thinker:/usr/sbin/ppplogin
指定thinker的shell为/usr/sbin/ppplogin
8、新建/usr/sbin/ppplogin文件,内容如下:
#!/bin/sh
exec /usr/sbin/pppd debug passive asyncmap 0 proxyarp lock modem crtscts lcp-max-terminate 30 lcp-max-failure 30 lcp-echo-interval 5
修改ppplogin所有者,以便其它用户使用,并用它或执行:
chown root.ppp /usr/sbin/ppplogin
chmod +x /usr/sbin/ppplogin
9、使非root用户可运行pppd程序:
运行以下命令:
chmod +s /usr/sbin/pppd
10、使init运行mgetty:
运行以下命令:
init q
11、启用包转发和iptables的NAT功能,使客户端可访问目标网络:
编辑/etc/sysctl.sys文件,改"net.ipv4.ip_forward = 0"为"net.ipv4.ip_forward = 1"
运行:
sysctl -p
启用iptables的NAT功能,运行:
iptables -F
iptables -X
iptables -F -t nat
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 192.16.11.107
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
说明:eth0为拨号服务器连接目录网络的网口,192.16.11.107为eth0的IP地址。请按需要修改。
将以上几行加入/etc/rc.local文件,使机器启动时自动运行。
三、测试
客户端拨号后可查看/var/log/message、/var/log/secure和/var/log/mgetty.log.ttyS0日志文件。
正常拨号时/var/log/message文件的内容:
Mar 7 15:37:20 web2 pppd[7195]: pppd 2.4.4 started by a_ppp, uid 0
Mar 7 15:37:20 web2 pppd[7195]: Using interface ppp0
Mar 7 15:37:20 web2 pppd[7195]: Connect: ppp0 <--> /dev/ttyS0
Mar 7 15:37:23 web2 pppd[7195]: user thinker logged in
Mar 7 15:37:23 web2 pppd[7195]: PAP peer authentication succeeded for thinker
Mar 7 15:37:24 web2 pppd[7195]: Cannot determine ethernet address for proxy ARP
Mar 7 15:37:24 web2 pppd[7195]: local IP address 192.168.1.3
Mar 7 15:37:24 web2 pppd[7195]: remote IP address 192.168.1.201
Mar 7 15:37:28 web2 pppd[7195]: LCP terminated by peer (^WM-H^CM-Z^@<M-Mt^@^@^@^@)
Mar 7 15:37:28 web2 pppd[7195]: Connect time 0.1 minutes.
Mar 7 15:37:28 web2 pppd[7195]: Sent 33 bytes, received 1828 bytes.
Mar 7 15:37:31 web2 pppd[7195]: Connection terminated.
Mar 7 15:37:31 web2 pppd[7195]: Modem hangup
Mar 7 15:37:31 web2 pppd[7195]: Exit.
正常拨号时mgetty.log.ttyS0文件的内容:
03/04 13:25:51 yS0 mgetty: interim release 1.1.33-Apr10
03/04 13:25:51 yS0 check for lockfiles
03/04 13:25:51 yS0 locking the line
03/04 13:25:52 yS0 lowering DTR to reset Modem
03/04 13:25:52 yS0 send: \dATQ0V1H0[0d]
03/04 13:25:53 yS0 waiting for ``OK'' ** found **
03/04 13:25:53 yS0 send: ATS0=0Q0&D3&C1[0d]
03/04 13:25:53 yS0 waiting for ``OK'' ** found **
03/04 13:25:53 yS0 mdm_send: 'ATI'
03/04 13:25:53 yS0 non-numeric ID string: 'TP560 Data/Fax/Voice 56K Modem'
03/04 13:25:53 yS0 mdm_send: 'AT+FCLASS=2.0' -> ERROR
03/04 13:25:53 yS0 mdm_send: 'AT+FCLASS=2' -> ERROR
03/04 13:25:54 yS0 waiting...
03/04 13:26:20 yS0 wfr: waiting for ``RING''
03/04 13:26:20 yS0 send: ATA[0d]
03/04 13:26:20 yS0 waiting for ``CONNECT'' ** found **
03/04 13:26:34 yS0 send:
03/04 13:26:34 yS0 waiting for ``_'' ** found **
03/04 13:26:37 ##### data dev=ttyS0, pid=29338, caller='none', conn='28800/V44', name='', cmd='/bin/login', user='/AutoPPP/'
正常拨号进/var/log/secure文件的内容:
Mar 4 14:27:38 web2 login: pam_unix(login:session): session opened for user thinker by LOGIN(uid=0)
Mar 4 14:27:38 web2 login: DIALUP AT ttyS0 BY thinker
Mar 4 14:27:38 web2 login: LOGIN ON ttyS0 BY thinker
--------------------------------------------------------------
以上实验实际测试过可以正常使用
转载于:https://blog.51cto.com/william1/552667