From 85cef43f457f743edbf30fa50a877a1a9e697eed Mon Sep 17 00:00:00 2001 From: Peng Li Date: Mon, 27 Aug 2018 20:02:48 +0800 Subject: [PATCH] add script of wifif config for raspberry pi --- bin/startHostapd.sh | 20 ++++++++++++++++++++ bin/stopHostapd.sh | 20 ++++++++++++++++++++ zsh/zshrc | 1 + 3 files changed, 41 insertions(+) create mode 100755 bin/startHostapd.sh create mode 100755 bin/stopHostapd.sh diff --git a/bin/startHostapd.sh b/bin/startHostapd.sh new file mode 100755 index 0000000..510ba47 --- /dev/null +++ b/bin/startHostapd.sh @@ -0,0 +1,20 @@ +#!/bin/bash -xe + +# This tool is to enable Hotspot mode on Raspberry Pi +# Refer https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md#internet-sharing + +# disable WiFi connection +wpa_cli -i wlan0 disable_network 0 || true + +# Stop dhcp cliennt, will start it with static IP and no wpa_supplicant +systemctl stop dhcpcd || true +killall dhcpcd || true + +# start Hostapd mode +systemctl start hostapd + +# start dhcp client with static IP +dhcpcd --static ip_address=192.168.4.1/24 --nohook wpa_supplicant wlan0 + +# start dnsmasq, dns server with IP reanges +dnsmasq --interface=wlan0 --dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h diff --git a/bin/stopHostapd.sh b/bin/stopHostapd.sh new file mode 100755 index 0000000..c20b12a --- /dev/null +++ b/bin/stopHostapd.sh @@ -0,0 +1,20 @@ +#!/bin/bash -xe + +# stop hostapd +systemctl stop hostapd || true + +# stop dns server +killall dnsmasq || true + +# stop dhcp client +killall dhcpcd || true + +sleep 1 + +# start dhcp +dhcpcd + +sleep 3 + +# scan wifi +wpa_cli -i wlan0 scan diff --git a/zsh/zshrc b/zsh/zshrc index c6dd499..994bd71 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -295,6 +295,7 @@ export MANPATH=$MANPATH:/usr/local/man export MANPATH=$MANPATH:${HOME}/perl5/man export PATH=$PATH:"${HOME}/scripts" +export PATH=$PATH:"/sbin:/usr/sbin" ## hunspell path export DICPATH="/usr/local/share/hunspell/" -- 2.11.0