auto lo
iface lo inet loopback

#allow-hotplug eth0
iface eth0 inet manual

allow-hotplug wlan0
mapping wlan0
  script /usr/local/bin/apscan.sh
  map YOUR_ESSID1,home
# map YOUR_ESSID2,home
# map YOUR_ESSID3,office
  map hotspot0

iface home inet manual
  post-up service dhcpcd restart
  post-down service dhcpcd restart

#iface office inet manual
#  post-up service dhcpcd restart
#  post-down service dhcpcd restart

# Hotspot settings wlan0 and eth0
iface hotspot0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
  pre-up service dhcpcd stop
  post-up ifup nat0
  post-up ifup services0
  post-up service dhcpcd restart
  pre-down ifdown services0
  pre-down ifdown nat0
  post-down service dhcpcd restart

# Nat eth0
iface nat0 inet manual
  up sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
  up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  up iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  up iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
  down iptables -D FORWARD -i wlan0 -o eth0 -j ACCEPT
  down iptables -D FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  down iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
  down sh -c 'echo 0 > /proc/sys/net/ipv4/ip_forward'

# Hotspot services
iface services0 inet manual
  up service hostapd start /etc/hostapd/hostapd.conf
  up service udhcpd start
  down service udhcpd stop
  down service hostapd stop