全功能无线路由器

全功能无线路由器


目          录

全功能无线路由器... 1

实验环境... 1

配置uclinux. 2

配置NAT功能... 2

选择ftp服务器,boa服务器和telnet服务器... 3

加入chroot,adduser,addgroup功能... 4

启动web服务器boa的方法... 5

准备inittab. 5

准备boa.conf5

集成boa配置文件到ramdisk. 8

启动ftp服务器... 9

启动telnet服务器... 10

集成所有的功能... 11

集成功能到ramdisk. 11

编辑rc. 12

启动后的情况... 13

iptables13

ifconfig. 13

iwconfig. 14

route. 15

使用配置分区... 15

在flash上创建分区... 15

在uclinux下mount分区... 16

集成全功能的摸索... 16

boa中的一些问题... 16

ftpd中的一些问题... 17

 

 

       本章内容包括架设FTP服务器,web服务器,telnet服务器,以及融合前面几章pppoe,wifi,dhcp服务器的内容,组成一个全功能的无线路由器。

实验环境

u  IXP425DP(P720板) 266Mhz 64M ram 16M flash

u  FC6

u  arm-linux-tools-20051123.tar.gz:gcc 3.4.4编译器

u  snapgear-3.5.0.tar.gz:  snapgear发布的uClinux包

u  snapgear-modules-20071004.sh: snapgear发布的uClinux包

u  files in /home/linuxuser/snapgear

 

配置uclinux

在阅读本章之前,应该已经阅读过pppoe,wifi,dhcp几章的内容。在那几章的基础上加入本章新的内容。作为无线路由器,必须加入NAT功能,能够使用iptables进行配置。而FTP服务器,web服务器,telnet服务器也是可以在make menuconfig里配置的,在此一一讲述。

 

配置NAT功能

       NAT功能的配置都在Customize Kernel Settings里面,选项很多,而且有些选项是默认的。选中Networking  --->Networking support,这个是默认的,一定要选上。

 

除了默认的选项以外还要选中不少,在此概括一下;

1.      Networking  ---> Networking options  ---> Network packet filtering (replacesipchains)  ---> Core NetfilterConfiguration--->Netfilter Xtables support (required for ip_tables)

这里面有很多的选项,全部选上。

 

2.   Networking  ---> Networking options  ---> Network packet filtering (replacesipchains)  --->IP: NetfilterConfiguration

 

上面的选项里面有关于NETLINK相关的选项,这个就不必选了。另外全部的选项使用build-in而不是module的形式。以上的功能选择不当会导致编译不过。最可能出现的是ULOG,或者ip policy相关的选项,尝试去掉ULOG target suppor, IPsecpolicy match support相关的选项就可以。

 

选择ftp服务器,boa服务器和telnet服务器

       选中vendor/user settings--->NetworkApplications--->ftpd

                                                                            --->boa

                                                                           --->telnetd

 

其中这些选项旁边或者子菜单有些辅助选项,先不要选了。

加入chroot,adduser,addgroup功能

选中vendor/usersettings--->BusyBox  ---> chroot

                                                         ---> chown

选中vendor/usersettings--->Tinylogin  --->adduser

                                                         --->addgroup

 

配置完后保存,编译内核。

启动web服务器boa的方法

先准备一些文件。

准备inittab

启动boa需要使用选项,而在initab里面启动时候不加选项。为了控制方便,改为利用rc或者手工启动。集成ramdisk的时候需要在initab里删除boa:unknown:/bin/boa。

initab内容如下:

inet:unknown:/bin/inetd

slog:unknown:/sbin/syslogd-n

klog:unknown:/sbin/klogd-n

 

需要注意的一点是,这个并非标准格式的initab,而是snapgear自带的默认initab。如果是别的init程序使用的initab,请自行修改。

 

准备boa.conf

boa需要配置文件boa.conf。可以在/snapgear/user/boa/examples找到样例,修改内容如下:

 

# The"ServerRoot" is not in this configuration file.  It can be compiled

# into theserver (see defines.h) or specified on the command line with

# the -c option,for example:

#

# boa -c/usr/local/boa

 

 

# Port: The portBoa runs on.  The default port for httpservers is 80.

# If it is lessthan 1024, the server must be started as root.

 

Port 80

 

User: The name or UID the server should runas.

# Group: Thegroup name or GID the server should run as.

 

#User nobody

#Group nogroup

User 0

Group 0

 

# Set to/dev/null if you don't want errors logged.

 

#ErrorLog /var/log/boa/error_log

#AccessLog/var/log/boa/access_log

#RefererLog/var/log/boa/referer_log

#AgentLog/var/log/boa/agent_log

#VerboseCGILogs

#ServerNamewww.your.org.here

 

# DocumentRoot:The root directory of the HTML documents.

 

DocumentRoot/var/www

 

# ChRoot: Boaroot '/' directory. This is useful to improve security of

# your system.Don't forget that ALL DIRECTORIES used by boa except logs

# must be inthis directory. If you need cgi scripts, you must copy shared

# libraries tothis directory (see ldconfig(8) for more info)

 

#Chroot /var

 

# UserDir: Thename of the directory which is appended onto a user's home

# directory if a~user request is recieved.

 

UserDirpublic_html

 

#DirectoryIndex: Name of the file to use as a pre-written HTML

# directory index.  Please MAKE AND USE THESE FILES.  On the

# fly creationof directory indexes can be _slow_.

#

 

DirectoryIndexindex.html

 

#DirectoryMaker/usr/local/sbin/boa_indexer

 

# LocalCodepage:Local codepage. This is send to client in 'Content-Type:'

# header bydefault.

 

#LocalCodepageiso-8859-1

 

# Codepage: Loadcodepage conversion table from file. This table will be used

# on-the-flyconversion.

 

#Codepageus-ascii /usr/lib/boa/iso-8859-2/us-ascii

 

#CodepageByBrowser: Specify codepage by $USER_AGENT. This command is used for

# automaticcodepage selection. You can use characters '*' and '?' in browser

# string. Forexample, "CodepageByBrowser Lynx/* us-ascii" will send for Lynx

# users alldocuments in us-ascii.

 

#CodepageByBrowserLynx/* us-ascii

 

# KeepAliveMax:Number of KeepAlive requests to allow per connection

# Comment out,or set to 0 to disable keepalive processing

 

KeepAliveMax1000

 

#KeepAliveTimeout: seconds to wait before keepalive connection times out

 

KeepAliveTimeout10

 

# MimeTypes:This is the file that is used to generate mime type pairs

# andContent-Type fields for boa.

 

MimeTypes/etc/mime.types

 

# DefaultType:MIME type used if the file extension is unknown, or there

# is no fileextension.

 

DefaultTypetext/plain

#DefaultTypetext/html

 

# AddType: addstypes without editing mime.types

# Example:AddType type extension [extension ...]

 

# Uncomment thenext line if you want .cgi files to execute from anywhere

#AddTypeapplication/x-httpd-cgi cgi

 

# Redirect,Alias, and ScriptAlias all have the same semantics -- they

# match thebeginning of a request and take appropriate action.  Use

# Redirect forother servers, Alias for the same server, and ScriptAlias

# to enabledirectories for script execution.

 

# ScriptAlias:Maps a virtual path to a directory for serving scripts

# Example:ScriptAlias /htbin/ /www/htbin/

 

ScriptAlias/cgi-bin/ /usr/lib/cgi-bin/

 

# VirtualHost:Maps a virtual host to a directory.

# Example:VirtualHost cz.boa.org /html/htdocs/boa/

 

#VirtualHost    www.second.company.com/var/www/second_company/

 

# Auth: HTTPBasic authorization. Format is "Auth <Directory><PasswdFile>".

# Password fileshould be readable _ONLY_ by root or trusted user(s). This file

# is openedbefore boa gives out privs.

# Example: Auth/secret /var/www/secret.passwd

 

Auth //etc/boa/boapasswd

其中Auth选项表明密码,DocumentRoot/var/www表明boa服务器的跟目录,DirectoryIndex index.html表示首页。概念和apache差不多。如果选择了打开了Auth选项,有时候实际上使用的密码文件是/etc/passwd,而不是设定的/etc/boa/boapasswd,原因不明。

 

集成boa配置文件到ramdisk

mime.types在/snapgear/user/boa/examples可以找到,index.html可以找一个能正常显示的静态网页改名就行。为了登录简单,需要修改passwd文件。

 

passwd原文如下:

root:C7P8YjbFj6hO6:0:0:root:/:/bin/sh

如果去掉密码,需要改为

root::0:0:root:/:/bin/sh

 

新建index.html文件,内容如下

<C><H4>BOATEST PAGE</H4></C>

 

 

现在initab,boa.conf,mime.types,index.html,passwd都已经准备好了,放在/home/linuxuser/boa。新建集成脚本install_boa.txt,内容如下。

 

umount tmp

rm -rframdisk.gz

rm -rf ramdisk

 

rm -rf tmp

mkdir tmp

cp -f/tftpboot/ramdisk.gz ramdisk.gz

gunzip ramdisk

mount -o loopramdisk tmp

 

mkdir./tmp/etc/boa

mkdir./tmp/var/www

mkdir ./tmp/var/log/boa/

cp -rf./boa.conf ./tmp/etc/boa/

cp -rf./mime.types ./tmp/etc/

cp -rf./index.html ./tmp/var/www

 

 

cp -rf ./inittab./tmp/etc/

cp -rf ./passwd./tmp/etc/

cp -rf./boapasswd ./tmp/etc/boa/

 

chmod -R 777./tmp/var/www

chmod -R 777./tmp/var/log/boa/

 

 

umount tmp

gzip ramdisk

cp -rframdisk.gz /tftpboot/ramdisktest.gz

rm -rf tmp

 

给install_boa.txt加上可执行属性,执行脚本,就集成好了。

 

       IXP425上linux启动完成之后,启动boa的命令为boa -c/etc/boa。在其他机器上登录,可以看到BOATEST PAGE的网页。

 

启动ftp服务器

       ftpd已经在make menuconfig的时候集成到ramdisk了。盒子启动以后添加一个用户,用户名和密码都是ftptest,执行命令adduser ftptest,信息如下:

# adduserftptest

Changingpassword for ftptest

Enter the newpassword (minimum of 5, maximum of 8 characters)

Please use acombination of upper and lower case letters and numbers.

Enter newpassword:

Bad password:too simple.

 

Warning: weakpassword (continuing).

Re-enter newpassword:

Passwordchanged.

 

查看密码文件

# cat passwd

root::0:0:root:/:/bin/sh

ftptest:aQc2MSdYMOU92:500:500::/home/ftptest:/bin/sh

# cat group

root::0:root

ftptest:x:500:

 

另外还需要使用chown改变文件的属性。假设/home/ftptest下还有文件夹和文件,需要使用以下命令;

#chown -Rftptest:ftptest /home/ftptest

#chmod -R 777 /home/ftptest

 

重新启动/bin/ftpd,可以登录。但是用windows下的cuteftp,flashfxp,FC6下的gftp都不能正确读取文件和文件夹,但是windows命令行ftp和linux命令行ftp都可以正确操作。

 

为了不是每次启动都添加用户名和密码需要把

ftptest:aQc2MSdYMOU92:500:500::/home/ftptest:/bin/sh

添加到ramdisk的/etc/passwd里面,并且把ftptest:x:500:添加到/etc/group里。

 

集成到ramdisk可以使用自动配置脚本/home/linuxuser/ftp/install_ftp.txt,内容如下:

 

umount tmp

rm -rframdisk.gz

rm -rf ramdisk

 

rm -rf tmp

mkdir tmp

cp -f/tftpboot/ramdisk.gz ramdisk.gz

gunzip ramdisk

mount -o loopramdisk tmp

 

cp -rf ./group ./tmp/etc/

cp -rf ./passwd./tmp/etc/

 

umount tmp

gzip ramdisk

cp -rframdisk.gz /tftpboot/ramdisktest.gz

rm -rf tmp

 

 

 

启动telnet服务器

       盒子启动以后执行/bin/telnetd,执行完以后会有???出现,按ctrl-c就行了。

 

集成所有的功能

       本小节将把FTP服务器,web服务器,telnet服务器,NAT, pppoe,wifi,dhcp服务器全部集成起来,组成一个全功能的无线路由器。

 

集成功能到ramdisk

       这些功能单独的集成方法都已经将了,那些配置文件和安装脚本都可以使用,唯一需要注意的是,文件的覆盖问题。

1. ftp服务器和boa服务器都用了passwd。那么这部分的内容需要叠加:最后的passwd和group文件应该如下:

passwd:

root::0:0:root:/:/bin/sh

ftptest:aQc2MSdYMOU92:500:500::/home/ftptest:/bin/sh

group:

root::0:root

ftptest:x:500:

这样,既清楚了root的密码,又有ftptest的信息。

2. 以往每个独立的安装脚本实际上都是将/tftpboot/ramdisk.gz复制到当前文件夹,集成为ramdisktest.gz复制回去,为了使用这些脚本简化集成工作,这个需要做特殊处理。

 

目前在实验环境中,几个独立安装的脚本在如下位置:

/home/linuxuser/P720/madwifi/madwifi-0.9.4/makewifi.txt

/home/linuxuser/pppoe/ppp-2.4.4good/stripit.txt

/home/linuxuser/allrouter/dhcpdisc/install_dhcpd.txt

/home/linuxuser/boa/install_boa.txt

/home/linuxuser/ftp/install_ftp.txt

 

所以全集成脚本allrouter.txt应该如下:

cp -rf/tftpboot/ramdisk.gz /tftpboot/ramdisk_backup.gz

cd/home/linuxuser/P720/madwifi/madwifi-0.9.4

./makewifi.txt

cp -rf/tftpboot/ramdisktest.gz /tftpboot/ramdisk.gz

cd/home/linuxuser/pppoe/ppp-2.4.4good

./stripit.txt

cp -rf/tftpboot/ramdisktest.gz /tftpboot/ramdisk.gz

cd/home/linuxuser/allrouter/dhcpdisc

./install_dhcpd.txt

cp -rf/tftpboot/ramdisktest.gz /tftpboot/ramdisk.gz

cd /home/linuxuser/boa

./install_boa.txt

cp -rf/tftpboot/ramdisktest.gz /tftpboot/ramdisk.gz

cd/home/linuxuser/ftp

./install_ftp.txt

cp -rf/tftpboot/ramdisk_backup.gz /tftpboot/ramdisk.gz

 

执行allrouter.txt,就可以得到全集成的ramdisk。

 

 

编辑rc

另外需要自动启动都可以加入到/etc/rc下。

 

hostname IXDP425

mount -t procproc /proc

mount -oremount,rw /dev/root /

ifconfig lo127.0.0.1

insmod/lib/modules/2.6.19-uc1/kernel/ixp425/ixp400-2.4/ixp400.ko

cat/etc/IxNpeMicrocode.dat > /dev/ixNpe

insmod/lib/modules/2.6.19-uc1/kernel/ixp425/net-2.4/ixp400_eth.ko

ifconfig eth0192.168.1.220 broadcast 192.168.1.255 netmask 255.255.255.0

#ifconfig ixp0192.168.1.220 broadcast 192.168.1.255 netmask 255.255.255.0

route add -net127.0.0.0 netmask 255.255.255.0 lo

#dhcpcd &

cat /etc/motd

 

cd/lib/modules/2.6.19-uc1/kernel/drivers/net/madwifi

insmod wlan.ko

insmodath_hal.ko

insmodath_rate_sample.ko

insmodwlan_scan_ap.ko

insmodwlan_scan_sta.ko

insmodath_pci.ko autocreate=ap

cd/home/wifitools

./wlanconfig athcreate wlandev wifi0 wlanmode ap

iwconfig ath1channel 6

iwconfig ath1essid "ryanp720"

ifconfig ath1172.17.0.1 up

 

/bin/pppdpty  '/bin/pppoe -I ixp0' user ucpppdefaultroute&

iptables -t nat-A POSTROUTING -s 172.17.0.0/16 -o ppp0 -j MASQUERADE

echo"1" > /proc/sys/net/ipv4/ip_forward

 

将这个rc替换ramdisk里的/etc/rc文件,注意要有可执行属性。

 

这样集成之后,制作出来的ramdisk下载到板子上就可以运行了。

 

 

 

 

启动后的情况

集成后系统的运行情况如下:

iptables

# iptables -tnat -L

Chain PREROUTING(policy ACCEPT)

target     prot opt source               destination        

 

ChainPOSTROUTING (policy ACCEPT)

target     prot opt source               destination        

MASQUERADE  0   --  172.17.0.0/16        anywhere           

 

Chain OUTPUT(policy ACCEPT)

target     prot opt source               destination        

 

ifconfig

# ifconfig

ath1      Link encap:Ethernet  HWaddr xx:xx:xx:1C:68:5B 

          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

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

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

          collisions:0 txqueuelen:0

         

ixp0      Link encap:Ethernet  HWaddr 00:02:B3:01:01:01 

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

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

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

          collisions:0 txqueuelen:256

         

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436 Metric:1

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

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

          collisions:0 txqueuelen:0

         

ppp0      Link encap:Point-to-Point Protocol 

          inet addr:xx:xx:xx  P-t-P:125.33.0.1  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARPMULTICAST  MTU:1492  Metric:1

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

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

          collisions:0 txqueuelen:3

         

wifi0     Link encap:UNSPEC  HWaddr00-16-16-1C-68-5B-4B-62-00-00-00-00-00-00-00-00 

          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

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

          TX packets:1068 errors:10 dropped:0overruns:0 carrier:0

          collisions:0 txqueuelen:199

                    Interrupt:27

 

iwconfig

# iwconfig

lo        no wireless extensions.

 

ixp0      no wireless extensions.

 

ixp1      no wireless extensions.

 

wifi0     no wireless extensions.

 

ath0      IEEE 802.11g  ESSID:""  Nickname:""

          Mode:Master  Channel:0 Access Point: 00:00:00:00:00:00 

          Bit Rate:0kb/s   Tx-Power:19 dBm   Sensitivity=1/1 

          Retry:off   RTS thr:off  Fragment thr:off

          Encryption key:off

          Power Management:off

         

ath1      IEEE 802.11g  ESSID:"ryanp720"  Nickname:""

          Mode:Master  Frequency:2.437GHz  Access Point: xx:xx:xx:1C:68:5B 

          Bit Rate:0kb/s   Tx-Power:19 dBm   Sensitivity=1/1 

          Retry:off   RTS thr:off  Fragment thr:off

          Encryption key:off

          Power Management:off

         

ppp0      no wireless extensions.

 

route

# route             

Kernel IProuting table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

xxx.xxx.0.1      *               255.255.255.255 UH    0     0        0 ppp0

127.0.0.0       *               255.255.255.0   U    0      0        0 lo

172.17.0.0      *               255.255.0.0     U    0      0        0ath1

default         *               0.0.0.0         U    0      0        0 ppp0

 

 

使用配置分区

在以上的过程中,有几个重要的配置文件,dhcpd.conf,boaconf等等,可以放到一个独立的分区,系统启动的时候,利用rc mount到ftp server可以访问的某个目录。可以下载这些文件,修改这些文件,然后上传。可以使用telnet umount。甚至可以利用ftp的可执行来做一个脚本上传。这样就无需串口线相连。boa可以实现基于http的实现,但是比较复杂。

在flash上创建分区

1. 新建分区文件;

dd if=/dev/zeroof=uconf bs=25600 count=1024

mke2fs -q -F uconf

执行完会得到uconf文件。

2. 复制文件

mkdir tmp

mount –o loop uconftmp

然后将需要的文件复制到tmp,再执行umount tmp

3. 在IXP425开发板上新建分区:

load -r -v -b0x00800000 uconf

fis create -b0x00800000 -l 0x80000 -f 0x50640000 -e 0x00800000 -r 0x01A00000 uconf.

这样就在0x50640000的位置建立了一个uconf分区

 

在uclinux下mount分区

首先使用cat命令查看分区的情况:

 

# cat /proc/mtd

dev:    size  erasesize  name

mtd0: 0004000000020000 "RedBoot"

mtd1: 0010000000020000 "zImage"

mtd2: 0064000000020000 "ramdisk"

mtd3: 00800000x80000 "uconf"

mtd4: 0000100000020000 "RedBoot config"

mtd5: 0002000000020000 "FIS directory"

 

说明在uconf在第三个分区上,执行命令:

mount  /dev/mtdblock3 /home/ftptest

这样,可以利用ftp来访问分区的内容,并且可以修改。

集成全功能的摸索

boa中的一些问题

       刚开始集成boa的时候,打开网页始终显示403错误,最可能的原因是文件的权限不对,或者文件路径不对找不到。已经看到进程

# ps

  PID  Uid    VmSize Stat Command

    1 root        216 S  /bin/init

    2 root            SW [keventd]

    3 root            SWN [ksoftirqd_CPU0]

    4 root            SW [kswapd]

    5 root            SW [bdflush]

    6 root            SW [kupdated]

    7 root            SW [mtdblockd]

   15 root        672 S  -/bin/sh

   16 root        232 S  /bin/inetd

   17 root        272 S  /bin/boa

   18 root        292 S  /sbin/syslogd -n

   19 root        264 S  /sbin/klogd -n

   25 root            DW [IxOsal 1]

   26 root            DW [IxOsal 2]

   32 root        288 R  ps

但是连接不上。

 

网页显示:

403 Forbidden

Your client doesnot have permission to get URL / from this server.

 

但是调整之后始终没有用。后来发现没有手工启动boa的时候也能在用ps在进程里看到boa,这才想到inittab。去掉inittab的boa,再手工启动就可以加入-c参数,正确识别conf文件

 

ftpd中的一些问题

       去掉root密码之后,用root还是登录不上。以为是权限问题,调整也没有用。后来决定采用新建一个用户ftptest的方法。这样可以利用ftptest登录,但是不能正确识别文件,即使chmod 777也没有用。最终使用chown的方法改变了owner才有效果。但是无法用图形界面的ftp客户端登录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值