Raspberry Pi3 を使用してCaptive Portalの環境を構築しました。

また、CoovaChilli は日本語の情報が少ない事とDB(PostgreSQL)

使用しない環境を構築した時のメモ書きです。

 

ネットワーク設定(固定IP)

①.vi /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.11.2/24
static routers=192.168.11.1
static domain_name_servers=192.168.11.1

interface wlan0
static ip_address=192.168.43.1/24
static routers=192.168.43.1
static domain_name_servers=192.168.43.1

②.vi /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual

 

Raspberry Pi3の設定

①.apt-get update

②.apt-get upgrade

③.rpi-update

※.「-bash: rpi-update: コマンドが見つかりません」の設定方法

wget https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update
mv ./rpi-update /usr/bin/rpi-update
chmod +x /usr/bin/rpi-update
rpi-update

④.reboot

 

hostapd導入と設定

①.apt-get install hostapd

②.zcat /usr/share/doc/hostapd/examples/hostapd.conf.gz > /etc/hostapd/hostapd.conf

③.vi /etc/hostapd/hostapd.conf

※.以下の内容を最後に記入します。

interface=wlan0
driver=nl80211
ssid=xxxx
country_code=JP
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=xxxx
rsn_pairwise=CCMP

ssid、wpa_passphrase は環境に合わせて設定します。

④.vi /etc/default/hostapd

※.以下の内容を最後に記入します。

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

⑤.WPASupplicantを無効

※.以下のコマンドを実行して無効にします。

mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/

 

isc-dhcp-server導入と設定

①.apt-get install isc-dhcp-server

②.vi /etc/dhcp/dhcpd.conf

※.以下の内容を最後に記入します。

authoritative;

subnet 192.168.43.0 netmask 255.255.255.0 {
option routers 192.168.43.1;
option broadcast-address 192.168.43.255;
option subnet-mask 255.255.255.0;
option domain-name "local";
option domain-name-servers 8.8.8.8,8.8.4.4;
default-lease-time 600;
max-lease-time 1800;
range 192.168.43.2 192.168.43.254;
}

WiFiの情報になるので環境に合わせて設定してください。

③.vi /etc/default/isc-dhcp-server

変更前

INTERFACES=""

変更後

INTERFACES="wlan0"

④.vi /etc/sysctl.conf

※.#を解除しています。

変更前

#net.ipv4.ip_forward=1

変更後

net.ipv4.ip_forward=1

⑤.iptables の登録

※.以下のコマンドを実行します。

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
iptables-save > /etc/iptables.ipv4.nat

⑥.vi /etc/network/interfaces

※.以下の内容を最後に記入します。

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

⑦.WiFiの接続確認

※.WiFiが正常に接続出来る事を確認します。

⑧.chkconfig isc-dhcp-server off

※.isc-dhcp-server の自動起動を無効にします。

CoovaChilliがDHCPの機能があるので必ず無効にする必要があります。

 

haserl導入

①.mkdir /root/tmp

②.cd /root/tmp

③.wget http://ftp.cn.debian.org/debian/pool/main/h/haserl/haserl_0.9.35-2_armhf.deb

※.必ず最新版(0.9.35以上)を導入してください。

④.apt-get install liblua5.2-0

⑤.dpkg -i haserl_0.9.35-2_armhf.deb

⑥.rm haserl_0.9.35-2_armhf.deb

 

FreeRadiu導入と設定

①.apt-get install freeradius

②.vi /etc/freeradius/users

※.ID、パスワードが必要無くアクセス出来る設定です。

DEFAULT Auth-Type := ACCEPT
Reply-Message = "Hello, %{User-Name}",
Session-Timeout := 60

※.ID:test PASSWORD:777 でログイン出来る設定です。

test Cleartext-Password := "777"
Reply-Message = "Hello, %{User-Name}",
Session-Timeout := 60

③.アクセス確認

※.WiFiからアクセスした事を想定したコマンド内容

radtest test 777 192.168.43.1 0 testing123

rad_recv: Access-Accept packet from host 192.168.43.1 port 1812, id=186, length=20 と

表示すれば問題ないです。

※.llocalhostからアクセスした事を想定したコマンド内容

radtest test 777 localhost 0 testing123

rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=65, length=20 と

表示すれば問題ないです。

④./etc/init.d/freeradius stop

※.サービスを停止する必要があります。

⑤.freeradius -XXX

※.テストを実施する場合はサービスを停止しないと以下のエラーが発生します。

Error: Failed binding to authentication address * port 1812: Address already in use
Error: /etc/freeradius/radiusd.conf[273]: Error binding to port for 0.0.0.0 port 1812

 

CoovaChilli導入

①.apt-get install debhelper libssl-dev gengetopt libtool automake

※.リビルド用のパッケージを導入します。

②.wget https://github.com/coova/coova-chilli/archive/1.3.1.4.tar.gz

※.最新版のcoova-chilli-1.3.1.4をダウンロードします。

③.tar xvf 1.3.1.4.tar.gz

※.解凍します。

④.cd coova-chilli-1.3.1.4

⑤.export CFLAGS=”-Wno-error”

※.エラーを回避するためのおまじないです。

⑥.export CXXFLAGS=”-Wno-error”

※.エラーを回避するためのおまじないです。

⑦.echo 9 > debian/compat

※.パッケージの互換性を保つための設定です。

⑧.vi /root/tmp/coova-chilli-1.3.1.4/debian/rules

※.52行目の部分を修正します。

変更前

$(MAKE) DESTDIR=$(CURDIR)/debian/coova-chilli install

変更後

$(MAKE) DESTDIR=/ install

⑨.dpkg-buildpackage -us -uc

※.リビルドを実行します。

⑩.cd ..

※.パッケージが出来た場所に移動します。

⑪.dpkg -i coova-chilli_1.3.0_armhf.deb

※.リビルド後のパッケージを導入します。

⑫.スクリプト確認

※.Y か I : パッケージメンテナのバージョンをインストールする を選択する。

 

CoovaChilli設定

①.vi /etc/chilli/defaults

※.以下の内容で設定します

HS_WANIF=eth0
HS_LANIF=wlan0

HS_NETWORK=192.168.43.0
HS_UAMLISTEN=192.168.43.1

HS_DNS1=8.8.8.8
HS_DNS2=8.8.4.4

環境で合わせるようにしてください。

②.vi /etc/default/chilli

変更前

START_CHILLI=0

変更後

START_CHILLI=1

③.vi /etc/chilli/wwwsh

変更前

haserl=$(which haserl 2>/dev/null)

変更後

haserl=/usr/bin/haserl

 

CoovaChilli起動

①./etc/init.d/chilli start

※.coova-chilli を起動します。

②.WiFi に接続します。

WiFi に接続する事でCaptive Portalの状態が確認できます。

 

補足情報

CoovaChilliのリビルド時の追加オプション

機能を追加する時に必要かも知れないのでメモ書きです。

vi /root/tmp/coova-chilli-1.3.1.4/debian/rules

※.19行目の「config.status: configure」に追加する。

--enable-statusfile --enable-dhcpopt --enable-sessgarden \
--enable-ipwhitelist --enable-miniconfig

 

CoovaChilli デバッグコマンド

※.通信状態などが確認できます。

chilli --fg --debug

パケットキャプチャ

※.Wiresharkで解析する時に使用したコマンドです。

tcpdump -n -i tun0 -s 0 -w dumpfile.cap

CoovaChilli強制終了方法

①.ps alx | grep chilli*

※.CoovaChilliのプロセスを確認します。

②.kill プロセスID

※.強制的にプロセスを終了します。