pastebin - collaborative debugging tool
mesageforyousir.kpaste.net RSS


Raspi Zero As An Access Point
Posted by Anonymous on Thu 20th Apr 2017 19:53
raw | new post

  1. #!/bin/bash
  2.  
  3. mkdir -p /home/pi/restore_etc
  4.  
  5. cp /etc/dhcp/dhcpd.conf /home/pi/restore_etc
  6. cp /etc/default/isc-dhcp-server /home/pi/restore_etc
  7. cp /etc/network/interfaces /home/pi/restore_etc
  8. cp /etc/init.d/hostapd /home/pi/restore_etc
  9. cp /etc/default/hostapd /home/pi/restore_etc/etc.default.hostapd
  10. cp /etc/sysctl.conf /home/pi/restore_etc
  11.  
  12.  
  13. sudo apt-get update
  14. sudo apt-get install hostapd isc-dhcp-server -y
  15. sudo sed -i '/domain-name-servers ns1.example.org/s/^/#/g' /etc/dhcp/dhcpd.conf
  16. sudo sed -i '/domain-name \"example.org\";/s/^/#/g' /etc/dhcp/dhcpd.conf
  17. sudo sed -i '/authoritative;/s/^#//g' /etc/dhcp/dhcpd.conf
  18. cat >>/etc/dhcp/dhcpd.conf <<EOF
  19. subnet 192.168.99.0 netmask 255.255.255.0 {
  20.     range 192.168.99.100 192.168.99.150;
  21.     option broadcast-address 192.168.99.255;
  22.     option routers 192.168.99.1;
  23.     default-lease-time 600;
  24.     max-lease-time 7200;
  25.     option domain-name "local";
  26.     option domain-name-servers 8.8.8.8, 8.8.4.4;
  27. }
  28. EOF
  29.  
  30. sed -i '/INTERFACES=\"\"/c\INTERFACES=\"wlan0\"' /etc/default/isc-dhcp-server
  31.  
  32. sudo sed -i '/iface wlan0 inet manual/s/^/#/g' /etc/network/interfaces
  33. sudo sed -i '/wpa_supplicant.conf/s/^/#/g' /etc/network/interfaces
  34. cat >>/etc/network/interfaces <<EOF
  35. iface wlan0 inet static
  36.   address 192.168.99.1
  37.   netmask 255.255.255.0
  38.   post-up iw dev $IFACE set power_save off
  39. EOF
  40.  
  41. cat >>/etc/hostapd/hostapd.conf <<EOF
  42. interface=wlan0
  43. ssid=WiPi
  44. hw_mode=g
  45. channel=6
  46. macaddr_acl=0
  47. auth_algs=1
  48. ignore_broadcast_ssid=0
  49. wpa=2
  50. wpa_passphrase=raspberry
  51. wpa_key_mgmt=WPA-PSK
  52. wpa_pairwise=TKIP
  53. rsn_pairwise=CCMP
  54. EOF
  55.  
  56. echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
  57.  
  58. sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  59.  
  60. sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  61. sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  62. sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
  63. sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
  64.  
  65. echo "up iptables-restore < /etc/iptables.ipv4.nat" >>/etc/network/interfaces
  66.  
  67. sed -i '/DAEMON_CONF=/c\DAEMON_CONF=/etc/hostapd/hostapd.conf' /etc/init.d/hostapd
  68. sed -i '/#DAEMON_CONF=\"\"/c\DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"' /etc/default/hostapd
  69.  
  70. sudo update-rc.d hostapd enable
  71. sudo update-rc.d isc-dhcp-server enable

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at