Ricky Hao

Raspberry(树莓派) 2 B 之Kali系统开无线热点(RTL8188CUS)

首先,我们得下载hostapd

sudo apt-get install hostapd unzip

因为,官方提供的hostapd不支持RTL8188CUS的驱动,所以,我们得再下载别人已经编译好的继承了8188CUS驱动的hostapd,然后覆盖安装。

wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
unzip hostapd.zip 
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax 
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd 
sudo chown root.root /usr/sbin/hostapd 
sudo chmod 755 /usr/sbin/hostapd

然后,安装DHCP服务

sudo apt-get install udhcpd

配置udhcpd

vi /etc/udhcpd.conf

然后,将文件中以下几项改成如下所示

start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds

然后,编辑

vi /etc/default/udhcpd

并将其改为

#DHCPD_ENABLED="no"

接下来,我们要给无线网卡配置一个静态IP,以便DHCP分配

vi /etc/network/interfaces

将其中所有的含有wlan0的全部注释掉,然后添加

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0

然后,我们要给hostapd创建一个配置文件

sudo vi /etc/hostapd/hostapd.conf

文件内容

interface=wlan0
driver=rtl871xdrv
ssid=My_SSID_Name
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MYPASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

启动IP转向功能以便于开通NAT

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

编辑/etc/sysctl.conf改动下面这行:

net.ipv4.ip_forward=1

配置iptables防火墙

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

到这里路由的NAT功能已经被启用,我们将刚才配置的iptables保存下来以便于下次使用:

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

编辑/etc/network/interfaces然后在最后加上下面这行以使每次启动都自动加载iptables配置:

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

重启并测试hostapd

sudo hostapd -dd /etc/hostapd/hostapd.conf

如果没有错误的话,你这时应该能搜索到你所配置的无线信号。然后Ctrl+C退出这个测试。

如果一切正常的话,我们可以设置hostapd的配置文件路径了。

sudo vi /etc/default/hostapd

去掉注释符号并改动下面这行为我们的配置文件路径:

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

启动相应软件,并加入启动项

sudo service hostapd start
sudo service udhcpd start
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
点赞

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据