把linux当无线路由器用,基于树莓派的无线路由器改造

家里的渣渣路由罢工了,只能链接却无法上网。本来打算上网淘一个回来,结果昨晚收拾东西的时候发现大学买来做人脸识别的树莓派在墙角吃灰很久,于是打算对其进行改造。

太久没动树莓派,上电没有正常跑起来,干脆直接从第一步刷系统开始操作。

一、系统设置

2、打开网络设置

sudo nano /etc/network/interfacse

将wlan0修改为如下

#自动IP

auto lo

iface lo inet loopback

iface eth0 inet dhcp

iface eth0 inet manual

#网卡设置为固定IP

iface wlan0 inet static

address192.168.1.1netmask255.255.255.0

二、hostapd

1、安装hostapd

sudo apt-get install hostapd

2、使用下面的语句打开hostapd

sudo nano /etc/default/hostapd

3、找到#DAEMON_CONF= ""这一行,首先取消注释(去掉前面的#号),然后将其修改为:

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

4、打开hostapd.conf

sudo nano /etc/hostapd/hostapd.conf

5、添加配置信息(PS:由于没查到我买的设备的具体型号,这里采用后面的方式进行配置)

# 把无线网卡wlan0 作为接入点

interface=wlan0

# 使用对应的驱动

driver=XXXX

#共享网络的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=100auth_algs=3wmm_enabled=1

6、安装 autoremove hostapd

sudo apt-get autoremove hostapd

7、下载安装第三方驱动:

wget https://github.com/jenssegers/RTL8188-hostapd/archive/v1.1.tar.gz

tar -zxvf v1.1.tar.gz

cd RTL8188-hostapd-1.1/hostapdsudo make

sudo make install

8、启动hostapd服务:

sudo service hostapd restart

之后提示下面的文字表示启动成功

[ ok ] Stopping advanced IEEE 802.11management: hostapd.

[ ok ] Starting advanced IEEE802.11 management: hostapd.

打开hostapd.conf查询到我的配置如下

# Basic configuration

interface=wlan0

ssid=Wifi

channel=6#bridge=br0

# WPA and WPA2 configuration

macaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=3wpa_passphrase=YourPassword

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

# Hardware configuration

driver=rtl871xdrv

ieee80211n=1hw_mode=g

device_name=RTL8192CU

manufacturer=Realtek

三、DHCP

1、安装DHCP服务,用于对每个接入的设备分配IP

sudo apt-get install isc-dhcp-server

2、编辑配置文件

sudo nano /etc/dhcp/dhcpd.conf

3、设置网关等信息,这里使用的是192.168.1.1

#默认租期(S)

default-lease-time 84600;

#最大租期(S)

max-lease-time 84600;

log-facility local7;

subnet192.168.1.0 netmask 255.255.255.0{

range192.168.1.10 192.168.1.100;

option routers192.168.1.1;

option broadcast-address 192.168.1.127;

//设置DNS服务器地址

option domain-name-servers 192.168.31.1,192.168.1.1;

default-lease-time 84600;

max-lease-time 84600;

}

4、启动DHCP服务

sudo service isc-dhcp-server restart

四、转发配置

1、配置路由转发

4666036370f3881867df914382415702.gif

sudo iptables -Fsudo iptables -Xsudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEsudobash

iptables-save > /etc/iptables.up.rules

exit

4666036370f3881867df914382415702.gif

2、打开iptables文件

sudo nano /etc/network/if-pre-up.d/iptables

添加以下代码

#!/bin/bash/sbin/iptables-restore < /etc/iptables.up.rules

3、修改iptables权限

sudo chmod 755 /etc/network/if-pre-up.d/iptables

4、设置内核转发,打开sysctl.conf文件

sudo nano /etc/sysctl.conf

将文件内的下列两行

# Uncomment the next line to enable packet forwarding forIPv4

#net.ipv4.ip_forward=1

修改为(即去掉net.ipv4.ip_forward=1的注释)

# Uncomment the next line to enable packet forwarding forIPv4

net.ipv4.ip_forward=1

5、修改内核之后使其生效

sudo sysctl -p

至此,已经完成无线路由器的设置功能。

五、自启设置

1、安装chkconfig

sudo apt-get install chkconfig

2、设置hostapd、dhcp自启动

sudo chkconfig --add hostapdsudo chkconfig --add isc-dhcp-server

PS: 手机有时候会出现连接上wifi后无法联网的情况,需要手动设置IP,暂时未解决~~

0b1331709591d260c1c78e86d0c51c18.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值