├── Readme.md └── install.sh /Readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | This install file configures your Raspberrypi 3 Model B as a Wifi-Access Point (AP) 4 | by sharing the incoming internet connection on `eth0` on the `wlan0` device 5 | (internal WiFi Chip on the new Pi). 6 | 7 | ## Goal 8 | Setup your Raspberrypi 3 as a WiFi Access Point (or Router) to share your ethernet connection with friends and family as a nice take-it-with-you WiFi Network. 9 | 10 | ## Environment 11 | This script was tested on 12 | 13 | - Raspberry-Pi 3 Model B 14 | - No additonal HW connected 15 | - Rasbian GBU/Linux 8 (`cat /etc/issue`) and Debian version 8.0 (`cat /etc/debian_version`) 16 | - No changes made to the configuration so far 17 | 18 | ## Installing 19 | ``` 20 | git clone https://github.com/sebastianzillessen/WiFi-AP-Raspberry-Pi-3.git 21 | cd WiFi-AP-Raspberry-Pi-3 22 | sudo su 23 | chmod +x install.sh 24 | ./install.sh 25 | ``` 26 | 27 | Your can specify the following parameters when calling `./install.sh`: 28 | 29 | 1. SSID (default: WiFiAPi ) 30 | 2. PASSPHRASE(default: Raspberrypi) 31 | 3. IP_RANGE (default: 192.168.1, produces IP of Pi with 192.168.1.1) 32 | 4. Incoming Internet connection device (default: eth0) 33 | 5. WiFi Connection Device (default: wlan0) 34 | 35 | These are parsed in the order. So with 36 | 37 | ``` 38 | ./install.sh TestAP test123 39 | ``` 40 | You would setup your Raspberrypi with a SSID `TestAp` and a Password `test123`. 41 | 42 | *NOTE*: As the script runs an update of all installed software at the beginning, it might take some time. So be patient! 43 | 44 | 45 | 46 | 47 | 48 | 49 | Feel free to modify it. 50 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SSID="${1:-WiFiAPi}" 4 | PASSPHRASE="${2:-Raspberrypi}" 5 | IP_RANGE="${3:-192.168.1}" 6 | INC="${4:-eth0}" 7 | WIFI="${5:-wlan0}" 8 | 9 | 10 | echo "Setting up your WiFi-Accesspoint on your pi with:" 11 | echo " SSID: $SSID" 12 | echo " PASSPHRASE: $PASSPHRASE" 13 | echo " IP-Address: $IP_RANGE.1" 14 | echo " IP-Range: $IP_RANGE.0" 15 | echo " Incomming device: $INC" 16 | echo " WiFi device: $WIFI" 17 | 18 | 19 | # update os 20 | apt-get update 21 | #apt-get -y upgrade 22 | apt-get -y install hostapd isc-dhcp-server iptables 23 | 24 | # check wlan0 available 25 | 26 | if ! ifconfig -a | grep "$WIFI"; then 27 | echo "$WIFI not found, exiting"; 28 | exit -1 29 | fi 30 | if ! ifconfig -a | grep "$INC"; then 31 | echo "$INC not found, exiting"; 32 | return -1 33 | fi 34 | 35 | # modify dhcp.conf 36 | sed -i.bak 's/option domain-name/\#option domain-name/g' /etc/dhcp/dhcpd.conf 37 | sed -i 's/#authoritative;/authoritative;/g' /etc/dhcp/dhcpd.conf 38 | 39 | # add ip addresses 40 | CONF=" 41 | subnet $IP_RANGE.0 netmask 255.255.255.0 { 42 | range $IP_RANGE.10 $IP_RANGE.50; 43 | option broadcast-address $IP_RANGE.255; 44 | option routers $IP_RANGE.1; 45 | default-lease-time 600; 46 | max-lease-time 7200; 47 | option domain-name "local"; 48 | option domain-name-servers 8.8.8.8, 8.8.4.4; 49 | } 50 | " 51 | echo "$CONF" >> /etc/dhcp/dhcpd.conf 52 | 53 | # set where DHCP runs 54 | sed -i.bak "s/\(INTERFACES *= *\).*/\1\"$WIFI\"/" /etc/default/isc-dhcp-server 55 | 56 | # set static ip address for $WIFI 57 | INTERF_CONF=" 58 | # interfaces(5) file used by ifup(8) and ifdown(8) 59 | # Please note that this file is written to be used with dhcpcd 60 | # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' 61 | # Include files from /etc/network/interfaces.d: 62 | source-directory /etc/network/interfaces.d 63 | 64 | auto lo 65 | iface lo inet loopback 66 | 67 | iface $INC inet manual 68 | 69 | allow-hotplug $WIFI 70 | iface $WIFI inet static 71 | address $IP_RANGE.1 72 | netmask 255.255.255.0 73 | " 74 | echo "$INTERF_CONF" > /etc/network/interfaces 75 | ifconfig $WLAN $IP_RANGE.1 76 | 77 | # setup hostapd.conf 78 | CONF_HOST="interface=$WIFI 79 | ssid=$SSID 80 | hw_mode=g 81 | channel=6 82 | macaddr_acl=0 83 | auth_algs=1 84 | ignore_broadcast_ssid=0 85 | wpa=2 86 | wpa_passphrase=$PASSPHRASE 87 | wpa_key_mgmt=WPA-PSK 88 | wpa_pairwise=TKIP 89 | rsn_pairwise=CCMP" 90 | echo "$CONF_HOST" > /etc/hostapd/hostapd.conf 91 | # replace SSID and Passphrase 92 | 93 | # deamon config 94 | sed -i.bak 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd 95 | 96 | # add ip-forward=1 97 | echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf 98 | echo 1 > /proc/sys/net/ipv4/ip_forward 99 | 100 | # add iptables 101 | iptables -t nat -F 102 | iptables -F 103 | iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 104 | iptables -A FORWARD -i $INC -o $WIFI -m state --state RELATED,ESTABLISHED -j ACCEPT 105 | iptables -A FORWARD -i $WIFI -o $INC -j ACCEPT 106 | # save iptables 107 | iptables-save > /etc/iptables.ipv4.nat 108 | 109 | # load on boot 110 | echo '#!/bin/sh' > /etc/network/if-up.d/iptables 111 | echo "echo 'RUNNING iptables restore now'" >> /etc/network/if-up.d/iptables 112 | echo "iptables-restore < /etc/iptables.ipv4.nat" >> /etc/network/if-up.d/iptables 113 | echo "exit 0;" >> /etc/network/if-up.d/iptables 114 | 115 | chmod +x /etc/network/if-up.d/iptables 116 | 117 | # test access point 118 | echo "Installation done!" 119 | /usr/sbin/hostapd /etc/hostapd/hostapd.conf & 120 | --------------------------------------------------------------------------------