Advertisement
v1ral_ITS

raspberry pi static IP wifi server!

May 5th, 2019
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.13 KB | None | 0 0
  1. The Pi-Point Raspberry Pi Wireless Access Point
  2.  
  3. HomePi-Point HowToHostapd configsClosed Cloud HowToGet in touchSD Card
  4. Setting up a Raspberry Pi as a Wireless Access Point
  5.  
  6.  
  7. If you would rather just get an SD Card with the Pi-Point image on it then go straight to getting the SD Card.
  8.  
  9.  
  10. Please note this HowTo is now updated to relate primarily to using a Raspberry Pi 3.
  11.  
  12. You will need:
  13.  
  14. A Raspberry Pi (of course!)
  15. An SD Card for your Pi – I use 4GB for this but whatever you have should be good
  16. A USB Wifi Dongle if not using a Raspberry Pi 3 – mine was originally a ZyXEL Communications Corp. ZyAIR G-202 802.11bg though I now use V3 PIs
  17.  
  18.  First install Raspbian from the Raspberry Pi site - http://www.raspberrypi.org/downloads – at the time of writing the current version is 'Wheezy'.
  19.  
  20. Install the image to your SD card as explained here - http://elinux.org/RPi_Easy_SD_Card_Setup
  21.  
  22. NB Since November 2016 the default Raspberry Pi configuration no longer has SSH running at start-up. You will need to put a file called 'ssh' (lower case, no extension) into the 'Boot' partition of your SD card after writing the image to it. This will cause SSH to be enabled at boot up.
  23.  
  24. Log in to your Pi – I did mine via SSH but no reason why you can't do it via a keyboard and screen if you have it connected that way. The default login is username 'pi' and password 'raspberry'. You'll be wanting to change these later for security. If not logging in via SSH make sure you have a network connection with internet access. If you're using SSH then you'll need to locate your Pi's IP address on your LAN using (on Linux systems, at least) sudo nmap -sP 192.168.0.0/24 you may need to install nmap with sudo apt-get install nmap) which will list all IP's on your network (if your network is 192.168.1.x then change the network range in the command to 192.168.1.0/24 and so on). You'll get a list along the lines of...
  25.  
  26. Nmap scan report for UNKNOWN (192.168.0.54)
  27. Host is up (0.65s latency).
  28. MAC Address: 00:24:2C:12:62:55 (Hon Hai Precision Ind. Co.)
  29. Nmap scan report for UNKNOWN (192.168.0.55)
  30. Host is up (0.23s latency).
  31. MAC Address: B8:27:EB:9E:CA:4D (Raspberry Pi Foundation)
  32. Nmap scan report for UNKNOWN (192.168.0.57)
  33. Host is up (0.0036s latency).
  34. MAC Address: 00:A0:DE:86:D3:6B (Yamaha)
  35.  
  36. In this case the Pi is at 192.168.0.55 so I'd login with ssh pi@192.168.0.55.
  37.  
  38.  Firstly run sudo raspi-config if you haven't yet, to setup your Pi (you'll likely want to at least change your memory split to 16) then reboot and set a root password using sudo passwd (or perhaps sudo -i if you don't want root to have a password) and enter a decent (i.e. not 'password'!) password for the root user. From this point on I'll assume you're logged in as root.
  39.  
  40. I prefer using aptitude for package installs and will be using it throughout this HowTo – if you're happier using apt-get then you'll be wanting to alter some of the installation commands to suit. Install aptitude with apt-get install aptitude.
  41.  
  42. Bring your Pi up to date using aptitude update; aptitude safe-upgrade – this may take a little while and also depend on your internet connection speed.
  43.  
  44. You'll need to install a few packages:
  45.  
  46. aptitude install rfkill zd1211-firmware hostapd hostap-utils iw dnsmasq
  47.  
  48. These are:
  49. rfkill – Wireless utility
  50. zd1211-firmware – Software for dealing with zd1211-based Wireless hardware
  51. hostapd – The hostap wireless access point daemon
  52. hostap-utils – Tools that go with hostap
  53. iw – Wireless config utility
  54. dnsmasq – a DHCP and DNS utility
  55.  
  56. You may also want to add 'vim' to that list which is a nicer console editor than the default 'vi'.
  57.  
  58. If you're using a dongle then the zd1211-firmware package is hardware-specific but is a very common implementation for wifi dongles. Your dongle will also need to support 'AP' mode which you can verify by typing iw list and under the 'Supported interface modes' you will hopefully see 'AP' listed along with others like 'managed' and 'monitor'. If not you're out of luck with your particular dongle.
  59.  
  60. Next you must add these lines to the end of your /etc/dhcpcd.conf file:
  61.  
  62. interface wlan0
  63. static ip_address=192.168.1.1/24
  64. static routers=192.168.0.1
  65. static domain_name_servers=8.8.8.8 8.8.4.4
  66.  
  67. These lines instruct dhcpcd to statically configure the WLAN0 interface with an IP address of 192.168.1.1 (the /24 is important, don't remove it, it's like the netmask entry in old /etc/network/interfaces). Change this IP address to whatever you're intending you use for your wireless network if you want something different. It also sets the gateway to 192.168.0.1 which you should change to be the gateway on your normal LAN which the wired ETH0 interface is connected to. Leave the domain_name_servers as-is, that's the Google DNS farm which should always work.
  68.  
  69. Now to configure hostap. Edit /etc/hostapd/hostapd.conf (it may not already exist but this will create it, anyway) to look like this:
  70.  
  71. interface=wlan0
  72. driver=nl80211
  73. ssid=test
  74. channel=1
  75.  
  76. The settings are pretty obvious, 'driver' being the only exception, just leave it as it is but change the other values as you see fit though these should do for an initial test. One thing to bear in mind is that hostap seems to be very literal about reading its configuration file so make sure you have no trailing spaces on the end of any lines!
  77.  
  78. Note (thanks to user 'wiak' for this):
  79.  
  80. Hello Guys, You need
  81. driver=rtl871xdrv in the /etc/hostapd/hostapd.conf file to get realtek cards to work :)
  82. and maybe a updated hostapd from https://github.com/jenssegers/RTL8188-hostapd
  83.  
  84. You might want to add
  85. ht_capab=[HT40-][HT40+][SHORT-GI-40][DSSS_CCK-40]"
  86. to hostapd.conf to get 11n 150mbps speed
  87.  
  88. There is a realtek guide here
  89. http://willhaley.com/blog/raspberry-pi-hotspot-ew7811un-rtl8188cus/
  90.  
  91.  
  92.  
  93. The final step is to configure dnsmasq so you can obtain an IP address from your new Pi-Point. Edit your /etc/dnsmasq.conf file to look like this:
  94.  
  95. # Never forward plain names (without a dot or domain part)
  96. domain-needed
  97.  
  98. # Only listen for DHCP on wlan0
  99. interface=wlan0
  100.  
  101. # create a domain if you want, comment it out otherwise
  102. #domain=Pi-Point.co.uk
  103.  
  104. # Create a dhcp range on your /24 wlan0 network with 12 hour lease time
  105. dhcp-range=192.168.1.5,192.168.1.254,255.255.255.0,12h
  106.  
  107. # Send an empty WPAD option. This may be REQUIRED to get windows 7 to behave.
  108. #dhcp-option=252,"\n"
  109.  
  110. Remember to change the dhcp-range option for the network IP range you're using. If you're having problems with Windows7 machines then try uncommenting the last line.
  111.  
  112. To ensure your Pi-Point works from a reboot you'll need to create a run file to turn on forwarding, nat and run hostap at boot time. Create a file /etc/init.d/pipoint with these contents:
  113.  
  114. #!/bin/sh
  115. # Configure Wifi Access Point.
  116. #
  117. ### BEGIN INIT INFO
  118. # Provides: WifiAP
  119. # Required-Start: $remote_fs $syslog $time
  120. # Required-Stop: $remote_fs $syslog $time
  121. # Should-Start: $network $named slapd autofs ypbind nscd nslcd
  122. # Should-Stop: $network $named slapd autofs ypbind nscd nslcd
  123. # Default-Start: 2
  124. # Default-Stop:
  125. # Short-Description: Wifi Access Point configuration
  126. # Description: Sets forwarding, starts hostap, enables NAT in iptables
  127. ### END INIT INFO
  128.  
  129. # turn on forwarding
  130. echo 1 > /proc/sys/net/ipv4/ip_forward
  131.  
  132. # enable NAT
  133. iptables -t nat -A POSTROUTING -j MASQUERADE
  134.  
  135. # start the access point
  136. hostapd -B /etc/hostapd/hostapd.conf
  137.  
  138. Next make the script executable with chmod +x /etc/init.d/pipoint. Edit your crontab with the command crontab -e and add this line at the end:
  139.  
  140. @reboot PATH=$PATH:/sbin:/usr/sbin && /etc/init.d/pipoint
  141. This should ensure your Pi-Point will reboot as a functioning wifi access point.
  142.  
  143. Further things you may wish to try:
  144.  
  145. Add wireless WEP/WPA authentication via the hostap configuration
  146. Strengthen firewalling between the Pi-Point and your LAN with iptables
  147. Add a Squid proxy to reduce traffic across your LAN
  148. Add a MAC filter with iptables or dnsmasq
  149. Don't forget to change your default login password!
  150. Deny root login via SSH config file
  151.  
  152.  
  153.  
  154.  
  155. Site and contents ©2012 by Guy Eastwood - web-dev, internet gun-for-hire and general nerdy dogs-body and gagdet-tinkerer
  156. Surefyre Design
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement