install_hotspot.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Based on Adafruit Learning Technologies Onion Pi project
  3. # But mainly fixed by Raspberry Pi FR...
  4. if (( $EUID != 0 )); then
  5. echo "This must be run as root. Try 'sudo bash $0'."
  6. exit 1
  7. fi
  8. apt-get update -y
  9. apt install dnsmasq -y
  10. systemctl stop dnsmasq
  11. echo "interface wlan0
  12. static ip_address=192.0.4.1/24
  13. nohook wpa_supplicant" >> /etc/dhcpcd.conf
  14. service dhcpcd restart
  15. mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
  16. echo "interface=wlan0 # Use the require wireless interface - usually wlan0
  17. dhcp-range=192.0.4.2,192.0.4.22,255.255.255.0,24h" > /etc/dnsmasq.conf
  18. systemctl unmask dnsmasq
  19. systemctl enable dnsmasq
  20. systemctl restart dnsmasq
  21. if command -v rfkill &> /dev/null
  22. then
  23. rfkill unblock wlan
  24. fi
  25. apt-get install hostapd -y
  26. systemctl unmask hostapd
  27. systemctl enable hostapd
  28. ssid=Pyrale
  29. passphrase=Paypoo2016
  30. echo "interface=wlan0
  31. driver=nl80211
  32. ssid=$ssid
  33. hw_mode=g
  34. channel=7
  35. wmm_enabled=0
  36. macaddr_acl=0
  37. auth_algs=1
  38. ignore_broadcast_ssid=0
  39. wpa=2
  40. wpa_passphrase=$passphrase
  41. wpa_key_mgmt=WPA-PSK
  42. wpa_pairwise=TKIP
  43. rsn_pairwise=CCMP
  44. " > /etc/hostapd/hostapd.conf
  45. echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' >> /etc/default/hostapd
  46. systemctl start hostapd
  47. cp /etc/sysctl.conf /etc/sysctl.bak
  48. echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
  49. echo "up iptables-restore < /etc/iptables.ipv4.nat" >> /etc/network/interfaces
  50. sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  51. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  52. iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  53. iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
  54. sh -c "iptables-save > /etc/iptables.ipv4.nat"
  55. sed -i '/exit 0/ i iptables-restore < /etc/iptables.ipv4.nat' /etc/rc.local
  56. exit 0