Difference between revisions of "Set up a wifi hotspot"

From Organic Design
Jump to: navigation, search
m (Running the script)
(Change source-code blocks to standard format)
Line 4: Line 4:
 
== Dependencies ==
 
== Dependencies ==
 
First we need to install a couple of small packages that the script uses.
 
First we need to install a couple of small packages that the script uses.
{{code|<bash>apt-get install hostapd dnsmasq</bash>}}
+
<source lang="bash">
 +
apt-get install hostapd dnsmasq
 +
</source>
  
  
Line 10: Line 12:
  
 
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.
 
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.
{{code|<bash>
+
<source lang="bash">
 
/etc/init.d/dnsmasq stop
 
/etc/init.d/dnsmasq stop
 
update-rc.d -f dnsmasq remove
 
update-rc.d -f dnsmasq remove
</bash>}}
+
</source>
  
 
== Running the script ==
 
== 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.  
 
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.  
{{code|<bash>
+
<source lang="bash">
 
create_ap wlan0 eth0 OurHotspot OurSecretPassword &
 
create_ap wlan0 eth0 OurHotspot OurSecretPassword &
</bash>}}
+
</source>
  
 
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.
 
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.

Revision as of 18:11, 22 May 2015

Procedure.svg 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 :-)

Dependencies

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.

See also