I have worked for about 1 month on an instresting project. It has something to do with the captive portal.
I’m really a rookie in these technologies, though I have studied something about the network technologies, but never so deeply as this time.
After these days learning, I found out how powerful the Linux kernel is, and here is something I learned.
How to setup a wireless ap using Linux and an antenna using the bridge mode
If you want to make a Linux box to be a wireless ap, in the most easy mode(the bridge mode), you should have something like this:
- A Linux Box, have at least Linux Kernel 2.6 installed (I’m using CentOS 6.4, a pleasant distro to play on)
- An Ethernet card for the Linux Box, so it can connect to the router you want it to connect to
- An wireless antenna, and have the driver installed as a module of the kernel (it’s a long story, I’ll write another article about that)
Beware: Make sure your antenna supports running at the mode of master or monitor, you can check the running mode using iw tool, if your antenna
didn’t support at least master or monitor mode, you are doomed, you can’t make the antenna used as ap antenna
Then you can begin like this:
- You need to have hostapd installed, hostapd is needed to host your wireless antenna as an ap antenna, unfortunately,
you can’t install this using yum, you must download the source code and compile it(not so hard).
- You need to create a bridge to bridge ethernet interface(say eth0) and wireless interface (say wlan0), it is very easy to create a bridge like this in RedHat, just edit the file /etc/sysconfig/network-scripts/ifcfg-eth0, and configuration added the bridge=br0, and change the wlan0’s file too, doing the same change, after that, restart the network, you have the bridge
- Configuration for hostapd is not very straight forward, and many options are there, you need to choose the wireless interface(wlan0 in most cases), the channels for the wireless ap, the password settings for the ap, and the running mode (802.11n or 802.11ac if your antenna supports it), there are many blogs about how to configure hostapd(like this), I won’t bother to make it detailed here
- You must give the bridge the ip, so you have to change the /etc/sysconfig/network-scritps/ifcfg-br0, so you need to using ifconfig to bring it up first, then change the file, give it a static ip or using DHCP to get an ip from the router
Then you are done.
Since this ap is running like a bridge, a bridge between wireless and ethernet, it is the most easy and robost way to run your linux box as an access point.
How to setup a wireless router using Linux and an antenna
Set up a wireless router is more complex than just an access point, but the first steps are the same, you need to have the hostapd installed and configured and then:
- Have dnsmasq intalled(you can install dhcpd as you want, since dnsmasq is more easy to config)
- Give a static ip to your wireless interface (make it an lan router, so give it the ip somehing like this 192.168.0.1)
- Make dnsmasq provide the listen on the wlan0 interface, so every device connect to the wlan0, can get its ip address and router(192.168.0.1) from it
- Configure iptables, allow devices access port for dhcp
For now, the device(phones or notebooks) can connect to your router, but they can’t get access to the wan, since your router don’t know how to get to the wan in your wlan0.
So you need:
- Add a NAT rule, something like this
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE, this is allow anything come from any interface have disguise that they are send from eth0(the WLAN port of you linux box router)
- Don’t forget, let kernel allow ip forward,
- And don’t forget, let ip tables allow forward from wlan0 too,
iptables -A FORWARD -i wlan0 -j ACCEPT
After this, every ip packet come from wlan0 can have its way to eth0 and go out from the kernel, and this is the basic router working mode for your home router too.
It is not so hard(yet not very easy) to setup a linux box into a wireless router, but if you finally make it done, you won’t get it more better than the router you have purchased at the same price(since it has tunned kernel and hardware), but you can gain as many controll as you want, and keep hacking.
So, in a few