- #!/bin/bash
- mkdir -p /home/pi/restore_etc
- cp /etc/dhcp/dhcpd.conf /home/pi/restore_etc
- cp /etc/default/isc-dhcp-server /home/pi/restore_etc
- cp /etc/network/interfaces /home/pi/restore_etc
- cp /etc/init.d/hostapd /home/pi/restore_etc
- cp /etc/default/hostapd /home/pi/restore_etc/etc.default.hostapd
- cp /etc/sysctl.conf /home/pi/restore_etc
- sudo apt-get update
- sudo apt-get install hostapd isc-dhcp-server -y
- sudo sed -i '/domain-name-servers ns1.example.org/s/^/#/g' /etc/dhcp/dhcpd.conf
- sudo sed -i '/domain-name \"example.org\";/s/^/#/g' /etc/dhcp/dhcpd.conf
- sudo sed -i '/authoritative;/s/^#//g' /etc/dhcp/dhcpd.conf
- cat >>/etc/dhcp/dhcpd.conf <<EOF
- subnet 192.168.99.0 netmask 255.255.255.0 {
- range 192.168.99.100 192.168.99.150;
- option broadcast-address 192.168.99.255;
- option routers 192.168.99.1;
- default-lease-time 600;
- max-lease-time 7200;
- option domain-name "local";
- option domain-name-servers 8.8.8.8, 8.8.4.4;
- }
- EOF
- sed -i '/INTERFACES=\"\"/c\INTERFACES=\"wlan0\"' /etc/default/isc-dhcp-server
- sudo sed -i '/iface wlan0 inet manual/s/^/#/g' /etc/network/interfaces
- sudo sed -i '/wpa_supplicant.conf/s/^/#/g' /etc/network/interfaces
- cat >>/etc/network/interfaces <<EOF
- iface wlan0 inet static
- address 192.168.99.1
- netmask 255.255.255.0
- post-up iw dev $IFACE set power_save off
- EOF
- cat >>/etc/hostapd/hostapd.conf <<EOF
- interface=wlan0
- ssid=WiPi
- hw_mode=g
- channel=6
- macaddr_acl=0
- auth_algs=1
- ignore_broadcast_ssid=0
- wpa=2
- wpa_passphrase=raspberry
- wpa_key_mgmt=WPA-PSK
- wpa_pairwise=TKIP
- rsn_pairwise=CCMP
- EOF
- echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
- sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
- sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
- sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
- sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
- sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
- echo "up iptables-restore < /etc/iptables.ipv4.nat" >>/etc/network/interfaces
- sed -i '/DAEMON_CONF=/c\DAEMON_CONF=/etc/hostapd/hostapd.conf' /etc/init.d/hostapd
- sed -i '/#DAEMON_CONF=\"\"/c\DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"' /etc/default/hostapd
- sudo update-rc.d hostapd enable
- sudo update-rc.d isc-dhcp-server enable
Raspi Zero As An Access Point
Posted by Anonymous on Thu 20th Apr 2017 19:53
raw | new post
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.