The prevalent and most used type of Internet in Uganda currently is 3G via a USB modem or dongle. Have you found yourself somewhere; may be on travel, or at home, and you need to share your Internet connection with a friend or family members via WiFi? Do you wish you could just plug in your laptop, and just use your WiFi-enabled phone or tablet to surf? Are you a Linux user? Well its very easy to setup a WiFi hotspot for yourself using free and open source software.
There are several ways to do this, however, if you use Linux say on your laptop (or server), what you need is an application called hostapd. It is already installed in most Linux distributions like Redhat/Fedora, CentOS, Ubuntu, Debian, etc. If not simply install it as follows:
yum install hostapd (or use apt get for Debian based systems like Ubuntu)
Of course, you will need to have a Wireless device enabled on your laptop (or server box), and the chipset should support AP (Access Point) mode. To test this:
iw list (Look for modes section to see if AP mode is supported on your Wireless device
Also, you need to setup the Wireless interface device. In this post I am using an IP address of 172.16.0.1 for my Hotspot and ‘wlan0’ as the device name e.g.
ifconfig wlan0 172.16.0.1 Please remember that the above will not survive a reboot, so you need to permanently add it to your network configuration. On Redhat based systems:
vim /etc/sysconfig/network-scripts/ifcfg-wlan0Add these parameters:
Now edit the configuration file for hostapd to suit your needs.
vim /etc/hostapd/hostapd.conf A typical hostapd.conf file looks like this:
The most important changes to make in the above file are:
ssid: The name you want your hotspot to be called
wpa: The encryption type. Use WPA2 and above always
wpa_passphrase: the password users will need to access your hotspot
After you have modified and saved the above file, enable hostapd services, so they also start during boot time.
systemctl enable hostapd.service or chkconfig hostapd on (old way)
systemctl start hostapd.service or service hostapd start (old way)
You will need some facility to dynamically offer IP addresses to clients of your hotspot. One very useful tool is called dnsmasq. Dnsmasq is a lighweight DHCP and DNS server. You can install it using your package manager e.g.
yum install dnsmasq Once installed, edit the configuration file for dnsmasq to suit your environment:
vim /etc/dnsmasq.confThe most important changes to make in the above file are:
Enable dnsmasq to start now and at boot time:
systemctl enable dnsmasq.service or chkconfig dnsmasq on (old way)
systemctl restart dnsmasq.service or service dnsmasq restart (old way)
The next step is to dial your ISP using either the GUI (NetworkManager) or the CLI tools like the ones I wrote about earlier. If you use the GUI tools, you will need to allow the laptop (server) to act as a gateway. This can be achieved simply:
/bin/echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE (NOTE: This assumes you are connected using a 3G modem with an assigned interface node of ppp0)
Once you are connected, and gateway has been setup, your clients should be able to connect to your Hotspot using the SSID and passphrase you setup above.
That’s it. Happy New year!