Set up a hotspot with Linux

From Linuxintro
Note
This guide is old, but we keep it here in order to show how things used to be. Today, you would typically use your mobile phone to provide a personal hotspot.

This is an example how to turn your computer into an accesspoint for wireless networks. My typical usecase for this is that I am in a place where I have to set up an UMTS connection to the internet and I want to share this internet connection as WLAN with others. You do not care about security, those considerations come later.

what you need

  • a Linux distribution with a kernel greater than about 2.6.30
  • a WLAN adapter, in this example we use a Conceptronic USB device with a RaLink chipset

SUSE Linux 13.1

This guide is based on SUSE Linux 13.1 but should work same or similar for every distribution. We will use the software HostAPD for this.

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: wlan0
  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
  • create a network bridge on your computer
  • 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 ppp0 -j MASQUERADE
# iptables -A FORWARD -i br0 -j ACCEPT
# iptables -A FORWARD -i wlan0 -j ACCEPT

SUSE Linux 12.1

This guide is based on SUSE Linux 12.1 but should work same or similar for every distribution. We will use the software HostAPD for this.

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: wlan0
  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
  • create a network bridge on your computer
  • 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 ppp0 -j MASQUERADE
# iptables -A FORWARD -i br0 -j ACCEPT
# iptables -A FORWARD -i wlan0 -j ACCEPT

Knoppix 7.02

create connectivity

  • install hostapd
sudo apt-get install hostapd
zcat /usr/share/doc/hostapd/examples/hostapd.conf.gz >/etc/hostapd.conf
  • configure hostapd
Edit the lines in /etc/hostapd.conf:
driver=nl80211
channel=3
hw_mode=g
auth_algs=1
  • install a dhcp server:
sudo apt-get install udhcpd
  • configure the dhcp server to start automatically:
vi /etc/default/udhcpd.conf
  • configure your wlan interface:
ifconfig wlan1 192.168.0.5
  • configure the dhcp server:
vi /etc/udhcpd.conf
  • start the dhcp server
/etc/init.d/udhcpd start

Set up NAT

Set up NAT like this:

# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -A POSTROUTING -o wwan0 -j MASQUERADE
# iptables -A FORWARD -i wlan1 -j ACCEPT

See also