Advertisement
metalx1000

Setup Wifi Hotstop with hostapd - Wireless Linux

Sep 30th, 2013
3,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.51 KB | None | 0 0
  1. #!/bin/bash
  2. aptitude install hostapd udhcpd -y
  3.  
  4. cat << EOF >/etc/udhcpd.conf
  5. start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
  6. end 192.168.42.20
  7. interface wlan0 # The device uDHCP listens on.
  8. remaining yes
  9. opt dns 8.8.8.8 8.8.4.4 # The DNS servers client devices will use.
  10. opt subnet 255.255.255.0
  11. opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
  12. opt lease 864000 # 10 day DHCP lease time in seconds
  13. EOF
  14.  
  15. echo 'DHCPD_OPTS="-S"' > /etc/default/udhcpd
  16.  
  17. ifconfig wlan0 192.168.42.1
  18.  
  19. cat << EOF >/etc/hostapd/hostapd.conf
  20. interface=wlan0
  21. ssid=FreeWifi
  22. hw_mode=g
  23. channel=6
  24. auth_algs=1
  25. wmm_enabled=0
  26.  
  27. EOF
  28.  
  29. cat << EOF >/etc/network/interfaces
  30. auto lo
  31.  
  32. iface lo inet loopback
  33. iface eth0 inet dhcp
  34.  
  35. #allow-hotplug wlan0
  36. #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
  37. #iface default inet dhcp
  38.  
  39. iface wlan0 inet static
  40.   address 192.168.42.1
  41.   netmask 255.255.255.0
  42.  
  43. up iptables-restore < /etc/iptables.ipv4.nat
  44. EOF
  45.  
  46. echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' > /etc/default/hostapd
  47.  
  48. sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  49. echo 'net.ipv4.ip_forward=1' > /etc/sysctl.conf
  50. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  51. iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  52. iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
  53.  
  54. sh -c "iptables-save > /etc/iptables.ipv4.nat"
  55.  
  56. service hostapd start
  57. service udhcpd start
  58.  
  59. update-rc.d hostapd enable
  60. update-rc.d udhcpd enable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement