树莓派 360wifi 路由器 带FTP 成功 hostapd isc-dhcp-server iptables

首先,树莓派一定要一个好电源

不然肯定带不动,要不360wifi不启动,要不有线网带不动

360wifi 1 的芯片天生就有驱动,且可以使用iw wlan0查看,它支持AP

参考自 http://www.raspicn.com/thread-83-1-1.html 文章

但是基本上每一步都出现了问题,最终一一解决

1.配置无线网、有线网IP以及相关

/etc/network/interfaces 中

无线网:

auto wlan0
iface wlan0 inet static address 192.168.10.1 netmask 255.255.255.0

有线网也是静态的

auto eth0
iface eth0 inet static
address   49.140.107.175   
gateway  49.140.107.254
netmask  255.255.255.0

auto eth0 必须要有,网卡的自动挂载

 

修改eth0的MAC地址,

http://blog.163.com/zhangliye_2009/blog/static/1223120282013719103025889/

ifconfig eth0 down
ifconfig eth0 hw ether 00:00:00:00:00:01
必须要和在一起
不然会出现
SIOCSIFHWADDR: Device or resource busy  
ifconfig eth0 down hw ether 00:00:00:00:00:01

 

DNS 

nano /etc/resolv.conf

 

添加默认网关

route add default gw 49.140.107.254

自动添加:在 /etc/init.d/rc.local 最后的地方添加上述代码

 

2.安装hostapd

sudo apt-get install hostapd
sudo nano /etc/default/hostapd
其中#DAEMON_CONF= ""
修改如下
DAEMON_CONF="/etc/hostapd/hostapd.conf"

创建
sudo nano /etc/hostapd/hostapd.conf
# 把无线网卡wlan0 作为接入点
interface=wlan0
# 使用nl80211驱动
driver=nl80211
#共享网络的SSID是RaspberryPi
ssid=RaspberryPi
# 网卡工作在802.11G模式
hw_mode=g
#无线网卡选用11信道
channel=11
# WPA2 配置
wpa=2
#wpa密码是raspberry
wpa_passphrase=raspberry
#认证方式为WPA-PSK 加密方式为CCMP
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP 
rsn_pairwise=CCMP
beacon_int=100 
auth_algs=3
wmm_enabled=1

然后启动下hostapd

service hostapd restart

理论,此时用电脑查询wifi就可以看到建好的AP了

可能出现,用iwconfig会发现没有IP地址,参考 http://wangye.org/blog/archives/845/

/etc/default/ifplugd
修改以下
INTERFACES="eth0" HOTPLUG_INTERFACES="eth0" ARGS="-q -f -u0 -d10 -w -I" SUSPEND_ACTION="stop"

3.安装dhcp服务

sudo apt-get install isc-dhcp-server
sudo nano /etc/dhcp/dhcpd.conf 

更新成如下内容
default-lease-time 600;    600秒
max-lease-time 7200;       7200秒
log-facility local7;

option doamin-name-servers 10.10.10.10 ;这里是学校的DNS,不然接收端会无法解析,或者这里不要,在下面那里直接使用学校的DNS

subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.10 192.168.10.100;
  option routers 192.168.10.1;
  option broadcast-address 192.168.10.127;
  option domain-name-servers 8.8.8.8,8.8.4.4;  路由器的模拟DNS,或者上面的不要,直接10.10.10.10
  default-lease-time 600;
  max-lease-time 7200;
}

此时启动DHCP

service isc-dhcp-server restart

如果正常,就已经可以连接到AP,并且能够获得一个IP地址

出现FAIL的话,可以尝试查看 ifconfig 的wlan0 是不是没有IP地址了

如果是,需要用上述方法或者 ifconfig wlan0 **.**.**.** netmask 255.255.255.0 up

给它一个IP然后再启动DHCP

 

4.配置路由转发

因为学校是静态的IP,因此使用了

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

同时编辑

/etc/sysctl.conf 改动下面这行:
net.ipv4.ip_forward=1

然后将路由信息保存下,每次启动就加载

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
编辑/etc/network/interfaces然后在最后加上下面这行以使每次启动都自动加载iptables配置:
pre-up iptables-restore < /etc/iptables.ipv4.nat

如果顺利,应该就可以连通了。

如果不行,先尝试在终端ping一个外网ip地址,看看是不是路由器的DNS没有设置好

5. SAMBA FTP

sudo apt-get install samba
sudo apt-get install samba-common-bin

/ect/samba/smb.conf

修改

[global]
        log file = /var/log/samba/log.%m
[tmp]
        comment = Temporary file space
        path = /tmp   ;共享的文件夹
        read only = no
        public = yes

创建 /etc/samba/smbpasswd 文件
再给samba添加用户名为aaa的用户:sudo smbpasswd -a aaa (必须要已经存在的用户)

参考:  http://www.eeboard.com/bbs/forum.php?mod=viewthread&tid=5473

6.额外

1.至于iptables实在是太强大

http://www.cnblogs.com/JemBai/archive/2012/04/27/2474003.html

有需要的话再去学学

2.服务的开机自启动和禁用

update-rc.d -f hostapd remove

update-rc.d hostapd defaults    

而且可以排列优先级,相对比chkconfig 简单而且使用广泛

http://blog.chinaunix.net/uid-108431-id-2875296.html

posted @ 2014-06-13 18:11  不卖糖水  阅读(888)  评论(0编辑  收藏  举报