{"id":921,"date":"2014-01-31T06:00:12","date_gmt":"2014-01-31T03:00:12","guid":{"rendered":"http:\/\/joseph.zikusooka.com\/?p=921"},"modified":"2014-01-31T17:46:57","modified_gmt":"2014-01-31T14:46:57","slug":"setup-quick-wireless-hotspot-using-linux","status":"publish","type":"post","link":"https:\/\/joseph.zikusooka.com\/?p=921","title":{"rendered":"How to setup a 3G Wireless Hotspot using Linux"},"content":{"rendered":"<p>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.<\/p>\n<p><a href=\"http:\/\/joseph.zikusooka.com\/wp-content\/uploads\/2014\/01\/hotspot_via_3g1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" alt=\"hotspot_via_3g\" src=\"http:\/\/joseph.zikusooka.com\/wp-content\/uploads\/2014\/01\/hotspot_via_3g1-300x154.png\" width=\"300\" height=\"154\" \/><\/a><\/p>\n<p>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 <a title=\"hostapd\" href=\"http:\/\/hostap.epitest.fi\/hostapd\/\" target=\"_blank\">hostapd<\/a>. It is already installed in most Linux distributions like Redhat\/Fedora, CentOS, Ubuntu, Debian, etc. If not simply install it as follows:<\/p>\n<p><code>yum install hostapd (or use apt get for Debian based systems like Ubuntu)<\/code><\/p>\n<p>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:<\/p>\n<p><code>iw list (Look for modes section to see if AP mode is supported on your Wireless device<\/code><\/p>\n<p>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 &#8216;wlan0&#8217; as the device name e.g.<\/p>\n<p><code>ifconfig wlan0 172.16.0.1<\/code> 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:<\/p>\n<p><code>vim \/etc\/sysconfig\/network-scripts\/ifcfg-wlan0<\/code>Add these parameters:<br \/>\n<em>TYPE=Wireless<br \/>\nBOOTPROTO=static<br \/>\nIPADDR0=172.16.0.1<br \/>\nNAME=&#8221;wlan0&#8243;<br \/>\nONBOOT=yes<br \/>\n<\/em><br \/>\nNow edit the configuration file for hostapd to suit your needs.<\/p>\n<p><code>vim \/etc\/hostapd\/hostapd.conf<\/code> A typical hostapd.conf file looks like this:<br \/>\n<em>ctrl_interface=\/var\/run\/hostapd<br \/>\nctrl_interface_group=0<br \/>\nmacaddr_acl=0<br \/>\nauth_algs=1<br \/>\nignore_broadcast_ssid=0<br \/>\nwpa=2<br \/>\nwpa_key_mgmt=WPA-PSK<br \/>\nwpa_pairwise=TKIP<br \/>\nrsn_pairwise=CCMP<br \/>\nwpa_passphrase=AVERYSECRETPASSPHRASE<br \/>\ninterface=wlan1<br \/>\nssid=MY-HOTSPOT<br \/>\nhw_mode=g<br \/>\nchannel=6<br \/>\ndriver=nl80211<br \/>\n<\/em><br \/>\nThe most important changes to make in the above file are:<br \/>\n<em>ssid<\/em>: The name you want your hotspot to be called<br \/>\n<em>wpa<\/em>: The encryption type. Use WPA2 and above always<br \/>\n<em>wpa_passphrase<\/em>: the password users will need to access your hotspot<\/p>\n<p>After you have modified and saved the above file, enable hostapd services, so they also start during boot time.<\/p>\n<p><code>systemctl enable hostapd.service or chkconfig hostapd on (old way)<br \/>\nsystemctl start hostapd.service or service hostapd start (old way)<\/code><\/p>\n<p>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.<\/p>\n<p><code>yum install dnsmasq<\/code> Once installed, edit the configuration file for dnsmasq to suit your environment:<\/p>\n<p><code>vim \/etc\/dnsmasq.conf<\/code>The most important changes to make in the above file are:<br \/>\n<em>interface=wlan0<br \/>\ndomain=example.com<br \/>\ndhcp-range=172.16.0.10,172.16.0.199,12h<br \/>\ndhcp-option=3,172.16.0.1<\/em><\/p>\n<p>Enable dnsmasq to start now and at boot time:<\/p>\n<p><code>systemctl enable dnsmasq.service or chkconfig dnsmasq on (old way)<br \/>\nsystemctl restart dnsmasq.service or service dnsmasq restart (old way)<\/code><\/p>\n<p>The next step is to dial your ISP using either the GUI (NetworkManager) or the CLI tools like the ones <a title=\"Dialup Scripts\" href=\"http:\/\/joseph.zikusooka.com\/linux-scripts-for-3g-internet-in-uganda\/\" target=\"_blank\">I wrote about <\/a> 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:<\/p>\n<p><code>\/bin\/echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward<br \/>\niptables -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)<\/code><\/p>\n<p>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.<\/p>\n<p>That&#8217;s it. Happy New year!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"footnotes":""},"categories":[6,8],"tags":[],"class_list":["post-921","post","type-post","status-publish","format-standard","hentry","category-apps","category-tools"],"_links":{"self":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=921"}],"version-history":[{"count":16,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":939,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions\/939"}],"wp:attachment":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}