Skip to content

Instantly share code, notes, and snippets.

@totti2
Last active April 7, 2018 16:16
Show Gist options
  • Save totti2/e59c1bbf5c2e5ea3c52dc36cf12c8276 to your computer and use it in GitHub Desktop.
Save totti2/e59c1bbf5c2e5ea3c52dc36cf12c8276 to your computer and use it in GitHub Desktop.
Adding accesspoint-mode to SSRPARI's stretch-branch (found here: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md)
#!/bin/bash
if [ "$WIFIPASS" == "" ]
then
read -p "Wifi Network name: " APName
read -p "Wifi Password: " WIFIPASS
fi
if [ -z "$exc" ]
then
source functions.sh
source dependencies.sh
fi
sudo systemctl stop dhcpcd
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
# ======================
# SETUP THE CONFIG FILES
# ======================
#
# STATIC IP / BRIDGE
#
save_original /etc/dhcpcd.conf
exc patch /etc/dhcpcd.conf <<EOT
@@ -55,3 +55,5 @@
#interface eth0
#fallback static_eth0
+interface wlan1
+ static ip_address=192.168.1.1/24
EOT
# Not necessary, but in case someone needs it:
# BRIDGE
#
#save_original /etc/network/interfaces
# exc patch /etc/network/interfaces <<EOT
#@@ -5,3 +5,8 @@
#
# # Include files from /etc/network/interfaces.d:
# source-directory /etc/network/interfaces.d
#+
#+# Bridge setup
#+auto br0
#+iface br0 inet manual
#+bridge_ports eth0 wlan1
#EOT
sudo service dhcpcd start
#
# ACCES POINT
#
save_original /etc/hostapd/hostapd.conf
exc patch /etc/hostapd/hostapd.conf <<EOT
@@ -0,0 +1,16 @@
+interface=wlan1
+driver=nl80211
+ssid=$APName
+hw_mode=g
+channel=6
+macaddr_acl=0
+auth_algs=1
+ignore_broadcast_ssid=0
+wpa=2
+wpa_passphrase=$WIFIPASS
+wpa_key_mgmt=WPA-PSK
+#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by old client devices
+rsn_pairwise=CCMP
+ieee80211n=1
+wmm_enabled=1
+ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
EOT
save_original /etc/default/hostapd
exc patch /etc/default/hostapd <<EOT
@@ -7,7 +7,7 @@
# 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=""
+DAEMON_CONF="/etc/hostapd/hostapd.conf"
# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
EOT
#
# DHCP-SERVER
#
save_original /etc/dnsmasq.conf
exc patch /etc/dnsmasq.conf <<EOT
@@ -668,3 +668,6 @@
# Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
dhcp-reply-delay=tag:client_is_a_pi,2
+
+interface=wlan1 # Use the require wireless interface - usually wlan0
+ dhcp-range=192.168.1.2,192.168.1.20,255.255.255.0,24h
EOT
#
# ROUTING AND MASQUERADE
#
save_original /etc/sysctl.conf
exc patch /etc/sysctl.conf <<EOT
@@ -25,7 +25,7 @@
#net.ipv4.tcp_syncookies=1
# Uncomment the next line to enable packet forwarding for IPv4
-#net.ipv4.ip_forward=1
+net.ipv4.ip_forward=1
# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
EOT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
save_original /etc/rc.local
exc patch /etc/rc.local <<EOT
@@ -17,4 +17,5 @@
printf "My IP address is %s\n" "$_IP"
fi
+iptables-restore < /etc/iptables.ipv4.nat
exit 0
EOT
# Not necessary, but in case someone needs it:
# BRIDGE
#
# sudo brctl addbr br0
# sudo brctl addif br0 eth0
sudo systemctl start hostapd
sudo systemctl start dnsmasq
@totti2
Copy link
Author

totti2 commented Apr 2, 2018

bridge-functions not needed
don't forget to add dnsmasq to the dependencies.sh
finished

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment