Browse Source

parameterize make hotspot script

master
Charles Reid 5 years ago
parent
commit
0ca8f6c13a
  1. 23
      scripts/make_hotspot.sh

23
scripts/make_hotspot.sh

@ -10,6 +10,10 @@ USER_PROMPT=false @@ -10,6 +10,10 @@ USER_PROMPT=false
WRITE_CONFIG_FILES=false
WIFI_SSID="MyLittlePony"
WIFI_PW="AardvarkBadgerHedgehog"
AP_IP="192.168.4.1"
CLIENT_IP_START="192.168.4.2"
CLIENT_IP_END="192.168.4.20"
SUBNET_MASK="255.255.255.0"
if [ "$#" == "2" ]; then
AP_INTERFACE="$1"
@ -47,17 +51,18 @@ fi @@ -47,17 +51,18 @@ fi
# Set dhcp and dns config files
if [[ $WRITE_CONFIG_FILES == true ]]; then
cp /etc/dhcpcd.conf /etc/dhcpcd.conf.orig
cat <<EOF > /etc/dhcpcd.conf
interface $AP_INTERFACE
static ip_address=192.168.4.1/24
static ip_address=$AP_IP/24
nohook wpa_supplicant
EOF
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
cat <<EOF > /etc/dnsmasq.conf
interface=$AP_INTERFACE
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
dhcp-range=$CLIENT_IP_START,$CLIENT_IP_END,$SUBNET_MASK,24h
EOF
cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
@ -95,7 +100,8 @@ service dnsmasq start || service dnsmasq restart @@ -95,7 +100,8 @@ service dnsmasq start || service dnsmasq restart
# Connect to existing wifi
ifdown $GW_INTERFACE || ifconfig $GW_INTERFACE down
rfkill unblock wifi && rfkill unblock wlan
rfkill unblock wifi
rfkill unblock wlan
sleep 3
ifup $GW_INTERFACE || ifconfig $GW_INTERFACE up
@ -104,6 +110,15 @@ ifup $GW_INTERFACE || ifconfig $GW_INTERFACE up @@ -104,6 +110,15 @@ ifup $GW_INTERFACE || ifconfig $GW_INTERFACE up
ifconfig $AP_INTERFACE down
rfkill unblock wifi
rfkill unblock wlan
ifconfig $AP_INTERFACE 192.168.4.1/24 up
ifconfig $AP_INTERFACE $AP_IP/24 up
service dhcpcd start || service dhcpcd restart
service hostapd start || service hostapd restart
# iptables
iptables -t nat -F
iptables -F
iptables -t nat -A POSTROUTING -o $GW_INTERFACE -j MASQUERADE
iptables -A FORWARD -i $AP_INTERFACE -o $GW_INTERFACE -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
service hostapd restart

Loading…
Cancel
Save