Last active
December 30, 2018 10:27
-
-
Save davibe/3724a41132622fad47b7b17f6c9d53ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update && sudo apt-get install -y hostapd dnsmasq iptables-persistent | |
export DEBIAN_FRONTEND=noninteractive | |
export ID=$(cat /sys/class/net/wlan0/address | sed 's/://g') | |
export AP_NAME=AP_$(date +%s) | |
export AP_PASS=raspberry | |
export WIFI_NAME=wifi_name | |
export WIFI_PASS=wifi_password | |
sudo bash -c 'cat > /etc/network/interfaces.d/ap' << EOF | |
allow-hotplug uap0 | |
auto uap0 | |
iface uap0 inet static | |
address 10.3.141.1 | |
netmask 255.255.255.0 | |
EOF | |
sudo bash -c 'cat > /etc/udev/rules.d/90-wireless.rules' << EOF | |
ACTION=="add", SUBSYSTEM=="ieee80211", KERNEL=="phy0", \ | |
RUN+="/sbin/iw phy %k interface add uap0 type __ap" | |
EOF | |
sudo bash -c 'cat > /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant' << 'EOF' | |
if [ -z "$wpa_supplicant_conf" ]; then | |
for x in \ | |
/etc/wpa_supplicant/wpa_supplicant-"$interface".conf \ | |
/etc/wpa_supplicant/wpa_supplicant.conf \ | |
/etc/wpa_supplicant-"$interface".conf \ | |
/etc/wpa_supplicant.conf \ | |
; do | |
if [ -s "$x" ]; then | |
wpa_supplicant_conf="$x" | |
break | |
fi | |
done | |
fi | |
: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf} | |
if [ "$ifwireless" = "1" ] && \ | |
type wpa_supplicant >/dev/null 2>&1 && \ | |
type wpa_cli >/dev/null 2>&1 | |
then | |
if [ "$reason" = "IPV4LL" ]; then | |
wpa_supplicant -B -iwlan0 -f/var/log/wpa_supplicant.log -c/etc/wpa_supplicant/wpa_supplicant.conf | |
fi | |
fi | |
EOF | |
sudo bash -c 'cat > /etc/wpa_supplicant/wpa_supplicant.conf' << EOF | |
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev | |
country=US | |
network={ | |
ssid="${WIFI_NAME}" | |
psk="${WIFI_PASS}" | |
key_mgmt=WPA-PSK | |
} | |
EOF | |
sudo bash -c 'cat > /etc/dnsmasq.conf' << EOF | |
interface=lo,uap0 | |
no-dhcp-interface=lo,wlan0 | |
bind-interfaces | |
server=8.8.8.8 | |
dhcp-range=10.3.141.50,10.3.141.255,12h | |
EOF | |
sudo bash -c 'cat > /etc/hostapd/hostapd.conf' << EOF | |
interface=uap0 | |
ssid=${AP_NAME} | |
hw_mode=g | |
channel=6 | |
macaddr_acl=0 | |
auth_algs=1 | |
ignore_broadcast_ssid=0 | |
wpa=2 | |
wpa_passphrase=${AP_PASS} | |
wpa_key_mgmt=WPA-PSK | |
wpa_pairwise=TKIP | |
rsn_pairwise=CCMP | |
EOF | |
sudo bash -c 'cat > /etc/default/hostapd' << EOF | |
DAEMON_CONF="/etc/hostapd/hostapd.conf" | |
EOF | |
sudo bash -c 'echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf' | |
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward' | |
sudo bash -c 'iptables -t nat -A POSTROUTING -s 10.3.141.0/24 ! -d 10.3.141.0/24 -j MASQUERADE' | |
sudo bash -c 'iptables-save > /etc/iptables/rules.v4' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment