玩转树莓派树莓派树莓派

在树莓派上部署ATC网络模拟工具的自动化脚本

2018-01-08  本文已影响104人  盖瑞_

尝试了下在树莓派上搭建Augmented Traffic Control (ATC) 来模拟弱网测试环境,主要分为两个部分:

  1. 将树莓派设置成具有发射AP热点的能力
  2. 在树莓派上安装ATC

网上手动配置的教程方式很多,步骤比较多也容易出错,这里整理成一份自动化脚本配置的方式,主要参考Raspberry Pi 3 access-point-setup · GitHub


首先将树莓派设置成具有发射AP热点的能力

  1. 手动配置AP的步骤比较繁琐,可以使用rPi3-ap-setup.sh脚本进行自动化配置,执行以下命令,其中password rPi3AP可以自定义,对应热点密码和热点名称。以下脚本主要包括:
    1.1. 给wlan0配置static ip
    1.2. 使用hostapd配置一个热点AP的帐号密码等
    1.3. 使用dnsmasq配置DHCP和DNS服务
curl -sSL https://gist.githubusercontent.com/jeffreyzh/e7f29c01cd1f07e9ff58a9f7b57f3187/raw/f620e2b3a878fdae361010efeabefca4c3b06c52/rPi3-ap-setup.sh | sudo bash $0 password rPi3AP
  1. 以上完成后,正常情况下可以搜索到热点 ,但热点可能无法连接,或者提示密码错误,那么可以执行以下命令:
sudo wget -q https://gist.githubusercontent.com/Lewiscowles1986/390d4d423a08c4663c0ada0adfe04cdb/raw/5b41bc95d1d483b48e119db64e0603eefaec57ff/dhcpcd.sh -O /usr/lib/dhcpcd5/dhcpcd
sudo chmod +x /usr/lib/dhcpcd5/dhcpcd
  1. 此时设置热点AP已完成,但连接后无法上网,所以还需要配置热点AP使用有线网卡的链接网络,以下脚本主要包括:
    3.1. 打开ipv4转发
    3.2. 在wlan0和eth0之间配置NAT规则
curl -sSL https://gist.githubusercontent.com/jeffreyzh/f6c03de9af9a9799a7725d0d0e917946/raw/f1d2477b2919c8887cfe578587f550c8883baedd/adapter-passthrough.sh | sudo bash $0

以上的规则需要设置为重启时自动配置,可以执行:

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

然后打开sudo nano /etc/rc.local,在exit 0之前添加一行:

iptables-restore < /etc/iptables.ipv4.nat  
  1. 此时AP配置完成,可以通过连接树莓派的热点来上网了!

在树莓派上配置AP的一些参考资料:

安装ATC

以上AP设置完成后,可以开始部署atc,步骤参考官方文档Augmented Traffic Control:
这里需要注意的是ATC所需的Python 和django版本

Python 2.7: Currently, ATC is only supported on python version 2.7.
Django 1.10: Currently, ATC is only supported using django version 1.10.

下面记录部署时踩过的坑

pip instasll atc时提示 AttributeError: ‘module’ object has no attribute ‘lru_cache'

Python 2.7: Currently, ATC is only supported on python version 2.7.
Django 1.10: Currently, ATC is only supported using django version 1.10.

查看当前django版本的方式:

pi@raspberrypi:~ $ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.10'
>>>

如果不符合,使用pip安装指定版本

sudo pip uninstall Django
sudo pip install django==1.10.6

atc is not running:ATC和最新版django-rest-framework不兼容

sudo pip install djangorestframework==3.4

atc not running:atcd启动时没有设置正确的网卡

上一篇 下一篇

猜你喜欢

热点阅读