Set up a wifi hotspot
| Set up a wifi hotspot|
Organic Design procedure
Sometimes it can be very useful to use a computer with wifi capability as an access point. A typical scenario is when only one computer can connect to the net for example if it were via a USB cellular connection, or if there were only a single cable connection and no hub available. This procedure allows the connected computer to use its wifi card to work as an access point that other systems can then connect to as usual. This procedure is designed for Debian based systems, but should work for any GNU/Linux system that has a reasonably modern wifi card in it. The procedure is based on the create_ap script which makes the process a breeze! big thanks to OBLiQUE, the author :-)
First we need to install a couple of small packages that the script uses.
apt-get install hostapd dnsmasq
Then download the create_ap script from here (we also have a local copy here in case that link is down or changes for any reason) and save into a path location such as /usr/bin, making sure that it has executable permission.
You need to stop the dnsmasq daemon first as the script calls dnsmasq directly instead. You may also want to prevent dnsmasq from starting automatically too, but if you're using dnsmasq for other purposes as well then you'll need to do your own configuration here. The following stops it and prevents it running on system bootup.
/etc/init.d/dnsmasq stop update-rc.d -f dnsmasq remove
Running the script
You're now ready to run the hotspot! To run it open a root terminal and then simply call the script with your network interface names (use ifconfig to find these, the first is your wifi interface and the second your internet interface) and SSID and a password. All the other default settings should be fine. The ampersand on the end makes it run in the background so you can close the terminal afterwards.
create_ap wlan0 eth0 OurHotspot OurSecretPassword &
Simply run this command whenever you want to start your hotspot and then clients will see the new wifi network appear in their list. When a client selects it and enters the password the hotspot will provide an IP address via DHCP in the 192.168.12.x range. The hotspot itself will be set to 192.168.12.1 on its wifi interface and will route packets between that and the internet-connected interface using the dnsmasq rules the script set up. It will be running on wifi channel 1 and be using WPA+WPA2 encryption.
These settings can be modified by adding options to the command, the available options can be seen by running the script with no parameters, but for most circumstances the defaults are fine.
Note: The create_ap command may not be able to access the wifi interface if the Network Manager has control of it. If this is the case it will tell you in an error message and you'll have to set it as unmanaged in /etc/NetworkManager/NetworkManager.conf by its MAC address.