Set up a hotspot with Linux

From Linuxintro
Revision as of 20:07, 3 July 2012 by imported>ThorstenStaerk (→‎Set up NAT)

This is an example how to turn your computer into an accesspoint for wireless networks. It is based on SUSE Linux 11.4 but should work same or similar for every distribution. We will use the software HostAPD for this.

what you need

  • a Linux kernel, greater than about 2.6.30
  • a Linux computer that has a bridge br0 as networking device
  • a USB wireless adapter, in this example we use a Conceptronic device with a RaLink chipset

what you do

create connectivity

  • plug in your USB wireless network adapter
  • find out how to activate the driver:
linux-noqb:~ # hwinfo --usb
[...]
22: USB 00.0: 0000 Unclassified device
  [Created at usb.122]
  Unique ID: doL0.gHs6xlT8BAF
  Parent ID: FKGF.0j9+vWlqL56
  SysFS ID: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-1.6:1.0
  SysFS BusID: 2-1.6:1.0
  Hardware Class: unknown
  Model: "Ralink 802.11 bg WLAN"
  Hotplug: USB
  Vendor: usb 0x14b2 "Ralink"
  Device: usb 0x3c22 "802.11 bg WLAN"
  Revision: "0.01"
  Driver: "rt73usb"
  Driver Modules: "rt73usb"
  Device File: wlan1
  Speed: 480 Mbps
  HW Address: 00:80:5a:4e:1a:eb
  Link detected: yes
  Module Alias: "usb:v14B2p3C22d0001dc00dsc00dp00icFFiscFFipFF"
  Driver Info #0:
    Driver Status: rt73usb is active
    Driver Activation Cmd: "modprobe rt73usb"
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #12 (Hub)
  • Activate the driver
modprobe rt73usb
  • Activate the NIC
ifup wlan0
  • Install HostAPD
yast -i HostAPD
  • Do the following settings in /etc/hostapd.conf
driver=nl80211
bridge=br0
channel=3
hw_mode=g
auth_algs=1
Note
channel=3 and hw_mode=g will work on almost all modern wireless USB adapters, however it may be possible to find one that does not work.
  • Start hostapd
hostapd /etc/hostapd.conf
  • verify that you see a wireless LAN with the ESSID test, e.g. on your mobile phone
  • assign an IP address to your bridge br0 like this:
brctl addif br0 wlan0
ifconfig br0 192.168.0.5
  • set up a dhcp server listening on your network bridge br0. As name server, use 8.8.8.8 which is google's name server in the internet
  • verify you can connect to the LAN test and get an IP address

Set up NAT

Set up NAT like this:

# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -A POSTROUTING -o <html>ppp0</html> -j MASQUERADE
# iptables -A FORWARD -i <html>br0</html> -j ACCEPT
# iptables -A FORWARD -i <html>wlan0</html> -j ACCEPT

See also