路由器主要是由有线网卡和无线网卡组成(当然内核也有份),我们将无线网卡rt3070和fl2440上的有线网卡dm9000这个组合当做一个路由器,有线网卡作为WAN口(连接广域网),无线网卡作为LAN口(连接局域网).在这里,我将开发板和无线网卡制成的路由器当做二级路由,即连接到已有的路由器(一级路由).
内核配置:
[*] Networking support --->
Networking options --->
[*] Network packet filtering framework (Netfilter) --->
Core Netfilter Configuration ---> //除了下面列出的其他全选
< > Transparent proxying support (EXPERIMENTAL)
< > set target and match support
< > CHECKSUM target support
< > "CT" target support
< > "DSCP" and "TOS" target support
< > "NOTRACK" target support
< > "TCPOPTSTRIP" target support (EXPERIMENTAL)
< > "dscp" and "tos" match support
< > "ipvs" match support
<*> IP set support --->
(256) Maximum number of IP sets
<*> bitmap:ip set support
<*> bitmap:ip,mac set support
<*> bitmap:port set support
<*> list:set set support
<*> IP virtual server support ---> //除了下面列出的其他全选
[ ] IP virtual server debugging
[ ] SCTP load balancing support
< > FTP protocol helper
< > SIP persistence engine
IP: Netfilter Configuration ---> //里面的全选
<*> RF switch subsystem support --->
//注意要选最后一项,不然在使用hostapd命令时会出错,“rfkill: Cannot open RFKILL control device”.
2.hostapd移植
wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/hostapd-1.0.tar.gz
tar xvzf hostapd-1.0.tar.gz
cd hostapd-1.0
cd hostapd/
cp defconfig .config
vim .config
make
利用file查看文件类型,利用readelf 查看以来关系
3开发板上开启热点
1)配置文件hostapd.conf
vi /etc/hostapd.conf
>: mv /dev/random /dev/random.bak //解决随机数错误问题,采用符号链接的方法
>: ln -s /dev/urandom /dev/random
>: hostapd -B /etc/hostapd.conf //守护进程启动,开启热点
hostapd: can't load library 'libnl.so.1' //出现错误,重命名库文件即可
>: cd /lib
>: mv libnl.so.1.1 libnl.so.1(看依赖关系可以分析得出,为什么要这么改)
>: hostapd -B /etc/hostapd.conf
Configuration file: /etc/hostapd.conf
rfkill: Cannot open RFKILL control device
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 102.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3, TXop: 0.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7, TXop: 0.
Using interface wlan0 with hwaddr 00:22:c0:2f:e7:7a and ssid 'fl2440_wifi'
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 1, TXop: 47.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 1, TXop: 94.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 6, Aifs: 3, TXop: 0.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.
//到此开启热点成功,可以用手机搜到热点,用ifconfig查看发现多了一个连接
>: ifconfig
eth0 Link encap:Ethernet HWaddr 36:D5:CE:0E:84:33
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8574 errors:0 dropped:0 overruns:0 frame:0
TX packets:8068 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4562704 (4.3 MiB) TX bytes:371170 (362.4 KiB)
Interrupt:51 Base address:0x2300
mon.wlan0 Link encap:UNSPEC HWaddr 00-22-C0-2F-E7-7A-00-00-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1511 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:408733 (399.1 KiB) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 00:22:C0:2F:E7:7A
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
4:为了使手机电脑连接上热点自动获取IP,需要启动DHCP服务器
1)配置文件udhcpd.conf
vi /etc/udhcpd.conf
touch /var/lib/misc/udhcpd.leases //在路径/var/lib/misc/下创建一个租赁文件
ifconfig wlan0 192.168.2.1 netmask 255.255.255.0
udhcpd /etc/udhcpd.conf //启动DHCP服务
到此可以连接热点,但还不能上网
5.关于连接热点上网,使用防火墙策略.
1)iptables移植
wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/iptables-1.4.12.tar.bz2
tar -xjf iptables-1.4.12.tar.bz2
[luliteng@luliteng iptables-1.4.12]$ ./configure --prefix=/home/luliteng/fl2440/3rdparty/iptables --host=arm-linux --enable-static --disable-shared --disable-ipv6 --disable-largefile CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
make
make install
需要的是/fl2440/3rdparty/iptables/sbin/xtables-multi,将xtables-multi移植到开发板/bin/,并将xtables-multi重命名为iptables,移植之后注意给权限.
2)保证有线网卡可以上网,用网线连接开发板和一级路由器(一级路由器动态分配ip给eth0)
ifconfig eth0 up
udhcpc -i eth0
3)开发板加上无线网卡rt3070作为2级路由使用
ifconfig wlan0 192.168.2.1 //手动分配ip给wlan0
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
//开启转发功能,允许已建立连接和相关连接对内转发
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISH -j ACCEPT
//实现对外转发,数据包从wlan0流向eth0
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
//开启Linux的转发功能
cat /proc/sys/net/ipv4/ip_forward //默认为零,表示禁止数据包转发,将其修改为1,表示允许转发
echo 1 >/proc/sys/net/ipv4/ip_forward
到此连上wifi就可以上网了