Set up wifi hotspot - mysteriousHerb/WaterScope-note GitHub Wiki
To do it automatically with a shell script
echo "Configure: /etc/hostapd/hostapd.conf" | tee -a ${log_file}
if [ ! -f /etc/hostapd/hostapd.conf ]; then
# -f = True if FILE exists and is a regular file. !-f = file does not exist
touch /etc/hostapd/hostapd.conf
#The touch command is the easiest way to create new, empty files.
fi
echo "interface=$NIC" > /etc/hostapd/hostapd.conf
#echo "something" > file Erase the file and add a line
echo "ssid=${AP_SSID}" >> /etc/hostapd/hostapd.conf
#echo "something" >> file Append the file and add a line
echo "channel=${AP_CHANNEL}" >> /etc/hostapd/hostapd.conf
echo "# WPA and WPA2 configuration" >> /etc/hostapd/hostapd.conf
echo "macaddr_acl=0" >> /etc/hostapd/hostapd.conf
echo "auth_algs=1" >> /etc/hostapd/hostapd.conf
echo "ignore_broadcast_ssid=0" >> /etc/hostapd/hostapd.conf
echo "wpa=2" >> /etc/hostapd/hostapd.conf
echo "wpa_passphrase=${AP_WPA_PASSPHRASE}" >> /etc/hostapd/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> /etc/hostapd/hostapd.conf
echo "wpa_pairwise=TKIP" >> /etc/hostapd/hostapd.conf
echo "rsn_pairwise=CCMP" >> /etc/hostapd/hostapd.conf
echo "# Hardware configuration" >> /etc/hostapd/hostapd.conf
#Setting required for config files for hostapd, dhcp-server and iptables Based on tutorial here: http://raspberry-at-home.com/hotspot-wifi-access-point/
sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server iptables
sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
ssid=WaterScopi3
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=waterscope
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo nano /etc/default/hostapd add
DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo nano /etc/dhcp/dhcpd.conf
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.5 10.0.0.55;
option broadcast-address 10.0.0.255;
option routers 10.0.0.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;
}
sudo nano /etc/udhcpd.conf
INTERFACES="wlan0"
sudo nano /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
up iptables-restore < /etc/iptables.ipv4.nat
sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
Finally
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
sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable