mynote/raspberry/router.md
2019-01-30 17:25:35 +08:00

114 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 用树莓派做路由器
## 网络配置
设置静态ip 需编辑/etc/dhcpcd.conf 文件, 修改/etc/network/interfaces 无效
wlan0 连接公网并将网络共享给有线网和wlan1
``` bash
interface wlan0 #指定接口
static ip_address=192.168.215.1/24 #IP根据需要更改/24的意思是子网掩码为 255.255.255.0
# static router=192.168.215.1 #网关
# static domain_name_serverrs=223.5.5.5 # DNS
interface wlan0
static ip_address=192.168.216.1/24
```
## 固定wlan名称
sudo nano /etc/udev/rules.d/10-network.rules
``` bash
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="MAC_address",name="wlan0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="MAC_address",name="wlan1"
```
## 安装配饰DHCP服务
sudo apt install dnsmasq
nano /etc/dnsmasq.conf
``` bash
listen-address = 127.0.0.1, 192.168.1.1, 192.168.2.1
dhcp-range = 192.168.1.20, 192.168.1.200, 12h
dhcp-range = 192.168.2.20, 192.168.2.200, 12h
```
## 开启内核转发包服务
sudo nano /etc/sysctl.conf
``` bash
net ipv4.ip_forward = 1 #去掉注释
```
## create_ap
``` bash
git clone https://github.com/oblique/create_ap.git
cd create_ap
sudo make install
sudo apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq
sudo create_ap wlan0 eth0 热点名 密码
```
rc.local
``` bash
screen -dmS wlanpa create_ap wlanpa wlansrc hellolight 1234567890
wpa_cli -iwlansrc enable_network 0
```
## wpa_cli 设置
wpa_cli -iwlan0 set_network 0 ssid '"wlan"'
wpa_cli -iwlan0 set_network 0 key_mgmt WPA-EAP
wpa_cli -iwlan0 set_network 0 pairwise TKIP(CCMP)
wpa_cli -iwlan0 set_network 0 group TKIP(CCMP)
wpa_cli -iwlan0 set_network 0 eap PEAP
wpa_cli -iwlan0 set_network 0 identity '"username"'
wpa_cli -iwlan0 set_network 0 password '"password"'
## hostapd
``` bash
interface=wlan0
# 网卡对应的驱动名
driver=nl80211
# 无线网络的名称是Pi-wifi
ssid=Pi-wifi
# 无线路由器工作模式为80211g2.4G
hw_mode=g
# 无线网卡使用的信道
channel=10
# 支持 802.11n
ieee80211n=1
# 采用WPA2配置
wpa=2
# 无线网络密码是123456789
wpa_passphrase=123456789
# 认证方式为WPA-PSK
wpa_key_mgmt=WPA-PSK
# 开启 WMM
wmm_enabled=1
# 开启 40MHz channels 和 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# 接受所有 MAC 地址
macaddr_acl=0
# 使用 WPA 认证
auth_algs=1
# 需连接者知道ssid
ignore_broadcast_ssid=0
# 使用 WPA2
wpa=2
# 使用预先共享的 key
wpa_key_mgmt=WPA-PSK
# 使用 AES, 而非 TKIP
rsn_pairwise=CCMP
```