嵌入式linux实现pppoe拨号上网

简介:

一.交叉编译内核

make menuconfig  -> Device Drivers -> Network device support  -> PPP (point-to-point protocol)  中,选中所有ppp选项。退出,保存配置,修改Makefile重新执行make zImage. 将arch/mips/boot/下的zImage下载到开发板上重启系统。

二.交叉编译pppoe server

下载ppp-2.4.5.tar.gz 、rp-pppoe-3.10.tar.gz 在 /opt 目录下。

tar -zxvf ppp-2.4.5.tar.gz
cd ppp-2.4.5

[root@root  ppp-2.4.5 ]# ./configure  CC=mipsel-linux-gcc AR=mipsel-linux-ar BANLIB=mipsel-linux-ranlib  --host=mipsel

-------------------------------------------------------------------------

Configuring for Linux

Creating Makefiles.

  Makefile <= linux/Makefile.top

  pppd/Makefile <= pppd/Makefile.linux

  pppstats/Makefile <= pppstats/Makefile.linux

  chat/Makefile <= chat/Makefile.linux

  pppdump/Makefile <= pppdump/Makefile.linux

  pppd/plugins/Makefile <= pppd/plugins/Makefile.linux

  pppd/plugins/rp-pppoe/Makefile <= pppd/plugins/rp-pppoe/Makefile.linux

  pppd/plugins/radius/Makefile <= pppd/plugins/radius/Makefile.linux

  pppd/plugins/pppoatm/Makefile <= pppd/plugins/pppoatm/Makefile.linux


  pppd/plugins/pppol2tp/Makefile <= pppd/plugins/pppol2tp/Makefile.linux

-------------------------------------------------------------------------

再直接 make CC=mipsel-linux-gcc

编译成功后在pppd目录下会生成pppd把这文件拷贝到usr/sbin目录下。 

cd /opt
tar -zxvf rp-pppoe-3.10.tar.gz
cd rp-pppoe-3.10/src

[root@root  src]# ./configure  CC=mipsel-linux-gcc AR=mipsel-linux-ar BANLIB=mipsel-linux-ranlib  --host=mipsel

-------------------------------------------------------------------------

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables... 

checking whether we are cross compiling... yes

checking for suffix of object files... o

checking whether we are using the GNU C compiler... yes

checking whether /opt/crosstool/mipsel-linux/bin/mipsel-linux-gcc accepts -g... yes

checking for /opt/crosstool/mipsel-linux/bin/mipsel-linux-gcc option to accept ISO C89... none needed

checking for mipsel-ranlib... no

checking for ranlib... ranlib

configure: WARNING: using cross tools not prefixed with host triplet

checking how to run the C preprocessor... /opt/crosstool/mipsel-linux/bin/mipsel-linux-gcc -E

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking for ANSI C header files... yes


checking for sys/wait.h that is POSIX.1 compatible... yes

checking for Linux 2.4 kernel-mode PPPoE support... cross-compiling, default:
no
checking packing order of bit fields... no defaults for cross-compiling

-------------------------------------------------------------------------

解决方法:进入src下直接./configure,然后修改下面的makefile和libevent下的makefile,gcc为mipsel-linux-gcc

直接 make
编译成功后configs目录下是rp-pppoe所需的配置文件,把这些文件全部复制到目标机的/etc/ppp目录下(没有就自己建一个)。

src目录下会产生pppoe,pppoe-server,pppoe-sniff,pppoe-relay。把这些程序下载到目标机/usr/sbin目录下。

三.配置

1)rp-pppoe-3.10/configs目录下是rp-pppoe所需的配置文件,把这些文件全部复制到目标机的/etc/ppp目录下(没有就自己建一个)。
2)拨号相关的脚本程序共有6个,在rp-pppoe-3.10/scripts中。
pppoe-setup:配置程序,把输入的帐号密码等信息存入配置文件。
pppoe-start:拨号程序,连接网络。
pppoe-stop:断开。
pppoe-status:查看连接状态。
pppoe-connect:连接网络,被pppoe-start所调用。
pppoe-init:初始化,被其他程序调用。
把这些脚本也放到/usr/sbin目录下。

四.测试

./pppoe-setup (下面是一些说明供参考)

>> Enter your PPPoE user name: ——此处输入拨号帐号的用户名 
>> Enter the Ethernet interface connected to the ADSL modem For Solaris, this is likely to be something like /dev/hme0. For Linux, it will be ethn, where n is a number. (default eth0): ——输eth0(视情况而定) 
>> Enter the demand value (default no): ——输no 
>> Enter the DNS information here: ——输IP(eg:69.45.45.34)(视当地运营商的DNS服务器IP而定)
>> Please enter your PPPoE password: ——输网通用户口令 
>> Choose a type of firewall (0-2): ——输0 (0为不要防火墙)
>> Accept these settings and adjust configuration files (y/n)? ——输y

执行pppoe-start后。如果这个时候就使用pppoe-start开始连接的话,很大情况下你会得到timeout的提示,那我们该怎么做呢?需要在dev目录下创建一个pts的文件夹,进入pts,创建节点mknod 0 c 136 0; mknod 1 c 136 1。每次链接都需要建立,蛮麻烦的吧,所以还是把这几条指令写进启动脚本吧。相信这样的话,一般您都会得到一个connected!的提示,说明ADSL已拨号成功,可以ping 下baidu看通不。

五.修改脚本

为了方便不用pppoe-setup,自己写一个脚本pppoe.sh为传参形式,把参数写入到指定的文件内 例如:

[root@root scripts]# ./pppoe.sh pppoe-name  eth2  pppoe-passwd

#!/bin/sh

U="$1"
E="$2"
PWD1="$3"

PPPD="/usr/sbin/pppd"
CONFIG="/etc/ppp/pppoe.conf"

if [ ! -r "$CONFIG" ] ; then
   echo "Oh, dear, I don't see the file '$CONFIG' anywhere.  Please"
   echo "re-install the PPPoE client."
   exit 1
fi

# Must have pppd
if [ ! -x $PPPD ] ; then
   echo "Oops, I can't execute the program '$PPPD'.  You"
   echo "must install the PPP software suite, version 2.3.10 or later."
   exit 1
fi

sed -i "s/USER=.*/USER=$U/" $CONFIG
sed -i "s/ETH=.*/ETH=$E/" $CONFIG
sed -i "s/FIREWALL=.*/FIREWALL=NONE/" $CONFIG
sed -i "s/DNSTYPE=.*/DNSTYPE=SERVER/" $CONFIG
sed -i "s/PIDFILE=.*/PIDFILE=/var/run/pppoe-$E.pid/" $CONFIG
sed -i "s/DEMAND=.*/DEMAND=no/" $CONFIG
sed -i "s/DNS1=.*/DNS1=""/" $CONFIG
sed -i "s/DNS2=.*/DNS2=""/" $CONFIG
sed -i "s/PEERDNS=.*/PEERDNS=yes/" $CONFIG
cp $CONFIG $CONFIG-bak

if [ -r /etc/ppp/pap-secrets ] ; then
   cp /etc/ppp/pap-secrets /etc/ppp/pap-secrets-bak
else
   cp /dev/null /etc/ppp/pap-secrets-bak
fi
if [ -r /etc/ppp/chap-secrets ] ; then
   cp /etc/ppp/chap-secrets /etc/ppp/chap-secrets-bak
else
   cp /dev/null /etc/ppp/chap-secrets-bak
fi

egrep -v "^$U|^\"$U\"" /etc/ppp/pap-secrets-bak > /etc/ppp/pap-secrets
echo "\"$U\"   *       \"$PWD1\"" >> /etc/ppp/pap-secrets
egrep -v "^$U|^\"$U\"" /etc/ppp/chap-secrets-bak > /etc/ppp/chap-secrets
echo "\"$U\"   *       \"$PWD1\"" >> /etc/ppp/chap-secrets

[root@root scripts]#/usr/sbin/pppoe-connect /etc/ppp/pppoe.conf

Using interface ppp0

Connect: ppp0 <--> /dev/pts/13

Warning - secret file /etc/ppp/chap-secrets has world and/or group access

CHAP authentication succeeded: Access granted

CHAP authentication succeeded

local  IP address 192.168.2.2

remote IP address 192.168.2.1

primary   DNS address 8.8.8.8


secondary DNS address 4.4.4.4

[root@root scripts]#/usr/sbin/pppoe-status 

pppoe-status: Link is up and running on interface ppp0

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:192.168.2.2  P-t-P:192.168.2.1  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1

          RX packets:7 errors:0 dropped:0 overruns:0 frame:0

          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:3 

          RX bytes:61 (61.0 B)  TX bytes:1447 (1.4 KiB)

[root@root scripts]#route -n

Kernel IP routing table

Destination   Gateway      Genmask        Flags Metric Ref   Use Iface

192.168.2.1   0.0.0.0      255.255.255.255 UH    0      0       0 ppp0

0.0.0.0       192.168.2.1  0.0.0.0         UG    0      0       0 ppp0

-----------------------------------------------------------------------


本文转自 Linux_woniu 51CTO博客,原文链接:http://blog.51cto.com/linuxcgi/1965326


相关文章
|
4月前
|
消息中间件 存储 缓存
【嵌入式软件工程师面经】Linux系统编程(线程进程)
【嵌入式软件工程师面经】Linux系统编程(线程进程)
101 1
|
4月前
|
网络协议 算法 Linux
【嵌入式软件工程师面经】Linux网络编程Socket
【嵌入式软件工程师面经】Linux网络编程Socket
114 1
|
2月前
|
NoSQL Linux C语言
嵌入式GDB调试Linux C程序或交叉编译(开发板)
【8月更文挑战第24天】本文档介绍了如何在嵌入式环境下使用GDB调试Linux C程序及进行交叉编译。调试步骤包括:编译程序时加入`-g`选项以生成调试信息;启动GDB并加载程序;设置断点;运行程序至断点;单步执行代码;查看变量值;继续执行或退出GDB。对于交叉编译,需安装对应架构的交叉编译工具链,配置编译环境,使用工具链编译程序,并将程序传输到开发板进行调试。过程中可能遇到工具链不匹配等问题,需针对性解决。
|
2月前
|
传感器 人工智能 网络协议
:嵌入式 Linux 及其用途
【8月更文挑战第24天】
90 0
|
3月前
|
Ubuntu 算法 Linux
嵌入式Linux的学习误区
**嵌入式Linux学习误区摘要** 1. **过度聚焦桌面Linux** - 许多学习者误将大量时间用于精通桌面Linux系统(如RedHat、Fedora、Ubuntu),认为这是嵌入式Linux开发的基石。 - 实际上,桌面Linux仅作为开发工具和环境,目标不应是成为Linux服务器专家,而应专注于嵌入式开发工具和流程。 2. **盲目阅读Linux内核源码** - 初学者在不了解Linux基本知识时试图直接研读内核源码,这往往导致困惑和挫败感。 - 在具备一定嵌入式Linux开发经验后再有针对性地阅读源码,才能有效提升技能。
35 4
|
4月前
|
物联网 Linux 芯片
学习嵌入式是选择单片机还是Linux?
单片机通常指的是一种集成了处理器、存储器和各种外设接口的微控制器芯片,常见的有STC、51系列、AVR、ARM Cortex-M等。单片机具有低成本、低功耗、实时性强等特点,适用于对资源要求较低、功耗要求较低、实时性要求较高的嵌入式系统。学习单片机开发可以让您深入了解嵌入式系统的底层原理和硬件编程,对于对嵌入式系统底层开发感兴趣的人来说,是一个很好的选择。
103 4
|
4月前
|
消息中间件 安全 Java
【嵌入式软件工程师面经】Linux多进程与多线程
【嵌入式软件工程师面经】Linux多进程与多线程
54 1
|
4月前
|
存储 缓存 Unix
【嵌入式软件工程师面经】Linux文件IO
【嵌入式软件工程师面经】Linux文件IO
41 1
|
5月前
|
Ubuntu 算法 Linux
嵌入式Linux的学习误区
该文指出了学习嵌入式Linux开发的两个常见误区。一是过分专注于学习桌面或服务器版Linux,而非关注嵌入式开发本身,实际上只需熟悉基本操作即可。二是试图在没有基础的情况下直接阅读Linux内核源代码,这是不切实际的,应先建立基础知识再进行源码学习。文章还提到了在嵌入式系统中获取和处理屏幕数据的示例,包括使用gsnap工具将framebuffer数据转为图像,以及涉及的交叉编译过程。
39 0
|
5月前
|
Linux 编译器 测试技术
嵌入式 Linux 下的 LVGL 移植
嵌入式 Linux 下的 LVGL 移植
199 0
下一篇
无影云桌面