码迷,mamicode.com
首页 > Web开发 > 详细

Raspberry pi 2 wireless settings.

时间:2016-01-15 01:09:54      阅读:602      评论:0      收藏:0      [点我收藏+]

标签:

主要参考:

0.https://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982

1.https://www.maketecheasier.com/set-up-raspberry-pi-as-wireless-access-point/

2.http://www.jenssegers.be/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi

3.https://www.embbnux.com/2015/02/08/setup_raspberry_to_wifi_access_point_with_rtl8188/

4.http://www.christianix.de/linux-tutor/hostapd.html

5.http://www.cnblogs.com/zhuwenger/archive/2011/03/11/1980294.html

 

===============================================

part 1

 

准备:

1.Raspberry pi 2 一个

2.USB无法网卡一个(我这里用的是:TP-LINKTL-WN725N)

一、安装raspberry.(系统安装就不再累述)

二、安装驱动,主要参考:https://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982

  下载对应的驱动安装即可。

三、安装isc-dhcp-server及配置

Edit “/etc/network/interfaces” and add the static IP address information for wlan0. You can learn about static IP addresses in our SSH and static IP address tutorial.

 sudo vim /etc/network/interfaces

Place a “#” sign in front of all the lines which mention wlan0 and wpa, except for “allow hotplug wlan0“. Then add the following lines to the file:

iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
gateway 192.168.1.1

The bottom half of the file will now look something like this:

allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0
gateway 192.168.1.1

Now reboot.

Install the DHCP server:

sudo apt-get install isc-dhcp-server

You can safely ignore any errors about not being able to start the DHCP server at this point. Now edit its configuration file:

sudo vim /etc/dhcp/dhcpd.conf

Add a “#” character in front of the “option domain-name” lines like this:

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

Remove the “#” sign in front of the “authoritative;” statement like this:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

At the bottom of the file add the following lines:

subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Make the wireless adapter the default for the DHCP request:

sudo vim /etc/default/isc-dhcp-server

Change “INTERFACES=""” to “INTERFACES="wlan0"

Restart the DHCP server:

sudo service isc-dhcp-server restart

四、安装hostapd, 参考:http://www.jenssegers.be/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi

Since we are building our own hostapd version, remove the original hostapd you might have installed:

sudo apt-get autoremove hostapd

On your Raspberry Pi, download and extract the source files from github:

wget https://github.com/jenssegers/RTL8188-hostapd/archive/v2.0.tar.gz
tar -zxvf v2.0.tar.gz

Now build hostapd:

cd RTL8188-hostapd-2.0/hostapd
sudo make

After a while, you should be given control back to the terminal.

sudo make install

This last step will move the created hostapd binary to /usr/local/bin, add a startup script and create a configuration file in /etc/hostapd/hostapd.conf

这是要说明一下,使用wpa加密方式,任何设置都无法连接,不知道为什么 ,使用wep加密方式可以正常连接

interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=MyPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1  # 1=wpa, 2=web, 3=both
# Hide SSID: 0 (don‘t), 1 (use emtpy), 2 (use ASCII 0) ignore_broadcast_ssid=0 #wpa=3  #1:wpa,2:wpa2,3:both #wpa_passphrase=raspberry  #password #wpa_key_mgmt=WPA-PSK #wpa_pairwise=TKIP #rsn_pairwise=CCMP

wep_default_key=0
wep_key0=1234567890

Edit this configuration file and start the hostapd service:

$ sudo service hostapd restart
[ ok ] Stopping advanced IEEE 802.11 management: hostapd.
[ ok ] Starting advanced IEEE 802.11 management: hostapd.

Tell hostapd where to find its configuration file by setting the default location:

sudo vim /etc/default/hostapd

Remove the “#” in front of “DAEMON_CONF” and alter the line to read:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

 

五、

Edit “/etc/sysctl.conf” to enable IP forwarding:

sudo vim /etc/sysctl.conf

Find the line which reads “Uncomment the next line to enable packet forwarding for IPv4” and uncomment the next line like this:

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Run the following command to activate forwarding now:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Now turn the Pi into a router with the follow commands:

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

And save the routing tables into the file “/etc/iptables.ipv4.nat

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Edit “/etc/network/interfaces“:

sudo vim /etc/network/interfaces

And add the following line to the end of the file. This line will restore the routing table whenever the Pi is booted:

pre-up iptables-restore < /etc/iptables.ipv4.nat

You should now reboot your Pi and test the wireless access using a laptop, smartphone, tablet or other Wi-Fi enabled device.

 

 ==========================================================

PART 2

 

0.http://liberize.me/tech/raspberry-pi-transparent-proxy.html

1.http://huahang.im/2014/12/27/shadowsocks-on-miwifi/

2.https://gist.github.com/wen-long/8644243

3.http://hbprotoss.github.io/posts/da-jian-zhi-neng-fan-qiang-lu-you-qi.html

 

ss-redir + chinadns + iptables

六、install shadowsocks-libev

cd /home/pi/Downloads/shadowsocks

wget https://github.com/shadowsocks/shadowsocks-libev/archive/v2.4.4.tar.gz

tar -zxvf v2.4.4.tar.gz

cd shadowsocks-libev

./configure && make

sudo make install

create shadowsocks config file

vim /etc/config.json

ss-redir -c /etc/config.json

 

install chinadns

cd /home/pi/Downloads/ChinaDNS

wget https://github.com/shadowsocks/ChinaDNS/releases/download/1.3.2/chinadns-1.3.2.tar.gz

tar -zxvf chinadns-1.3.2.tar.gz

cd chinadns-1.3.2

./configure &&make 

sudo make install

 

sudo chinadns -m -c /var/local/share/chnroute.txt

 

用vi创建一个脚本:

vi firewall.sh

然后写入如下内容:

#!/usr/bin/env sh

iptables -t nat -N SHADOWSOCKS
iptables -t nat -A SHADOWSOCKS -d a.b.c.d -j RETURN                # 这里请填写您服务器的外网IP地址
iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN              # 上一行、这一行和下面几行的作用
iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN             # 是让一些特定的网段流量不通过
iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN            # shadowsocks中转
iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN         #
iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN          #
iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN         #
iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN            #
iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN            #
iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 10000 # 这里填写上一步配置的"local_port"
iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS

最后赋予他可执行的权限,并且执行之:

chmod a+x firewall.sh
./firewall.sh

 

 

 

 

 

 

 

Raspberry pi 2 wireless settings.

标签:

原文地址:http://www.cnblogs.com/tianzhenyun/p/5126083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!