Last active
July 11, 2018 16:15
-
-
Save Jsitech/4795fd3f97db389b56fd14db15031dda to your computer and use it in GitHub Desktop.
Simple Script to Set up an Access Point on the latest version of Raspbian Stretch
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
#!/bin/bash | |
# Raspbian-AP-Setup | Simple Script to Set up an Access Point on the latest version of Raspbian Stretch | |
# jasonsoto.com | |
# jsitech-sec.com | |
############################################################################################################## | |
if [ "$USER" != "root" ]; then | |
echo "Permission Denied" | |
echo "Run as the root user" | |
exit | |
else | |
echo "Cool, running as root" | |
fi | |
echo "[+] Setting up the Wifi AP......" | |
apt install hostapd dnsmasq | |
echo "" | |
echo "[+] Setting up Hostapd..." | |
echo "" | |
echo "[?] Please type in a SSID for the WiFi AP: " ; read wifissid | |
echo "[?] Please type in a Passphrase (Lenght 8 or Longer) for the WiFi AP: " ; read wifipass | |
cat > /etc/hostapd/hostapd.conf <<EOF | |
interface=wlan0 | |
ssid=$wifissid | |
hw_mode=g | |
channel=7 | |
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] | |
wmm_enabled=0 | |
macaddr_acl=0 | |
auth_algs=1 | |
wpa=2 | |
ignore_broadcast_ssid=0 | |
wpa_passphrase=$wifipass | |
wpa_key_mgmt=WPA-PSK | |
wpa_pairwise=TKIP | |
rsn_pairwise=CCMP | |
EOF | |
cat > /etc/default/hostapd <<EOF | |
# Defaults for hostapd initscript | |
# | |
# See /usr/share/doc/hostapd/README.Debian for information about alternative | |
# methods of managing hostapd. | |
# | |
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration | |
# file and hostapd will be started during system boot. An example configuration | |
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz | |
# | |
DAEMON_CONF="/etc/hostapd/hostapd.conf" | |
# Additional daemon options to be appended to hostapd command:- | |
# -d show more debug messages (-dd for even more) | |
# -K include key data in debug messages | |
# -t include timestamps in some debug messages | |
# | |
# Note that -B (daemon mode) and -P (pidfile) options are automatically | |
# configured by the init.d script and must not be added to DAEMON_OPTS. | |
# | |
#DAEMON_OPTS="" | |
EOF | |
echo "[+] Setting up Dnsmasq...." | |
echo "interface wlan0" >> /etc/dhcpcd.conf | |
echo "static ip_address=192.168.1.1" >> /etc/dhcpcd.conf | |
echo "static routers=192.168.1.1" >> /etc/dhcpcd.conf | |
echo "static domain_name_servers=8.8.8.8" >> /etc/dhcpcd.conf | |
echo "interface=wlan0" >> /etc/dnsmasq.conf | |
echo "domain-needed" >> /etc/dnsmasq.conf | |
echo "bogus-priv" >> /etc/dnsmasq.conf | |
echo "dhcp-range=192.168.1.8,192.168.1.15,12h" >> /etc/dnsmasq.conf | |
echo -n " ¿Do you Want to configure traffic forwarding (y/n): "; read config_forwarding | |
if [ "$config_forwarding" == "y" ]; then | |
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf | |
sysctl -e -p | |
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 | |
echo "[+] Setting up iptables-persistent...." | |
apt-get install iptables-persistent | |
echo "" | |
echo "[+]Traffic Forwarding configured!" | |
fi | |
echo "" | |
echo "[+] Done setting up Wifi AP, Please Reboot......" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment