Monthly Archives: July 2013

The words about setup linux box into wireless router

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:

  1. A Linux Box, have at least Linux Kernel 2.6 installed (I’m using CentOS 6.4, a pleasant distro to play on)
  2. An Ethernet card for the Linux Box, so it can connect to the router you want it to connect to
  3. 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:

  1. 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).
  2. 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
  3. 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
  4. 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:

  1. Have dnsmasq intalled(you can install dhcpd as you want, since dnsmasq is more easy to config)
  2. 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)
  3. 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
  4. 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:

  1. 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)
  2. Don’t forget, let kernel allow ip forward, net.ipv4.ip_forward=1
  3. 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.

Conclusion

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

About the mod_perl and perl-Apache-Test conflict in installing Packetfence

It’s been a very long time since my last post.

Very busy these days. Now I’m working for a company try to create captive portal, I make packetfence a try.

It is a very nice application based on CentOS.

I started with CentOS 6.4, added the repositories it needed, and then:

yum install -y packent fence

What a nice day!

But bang!!!! what!?

file /usr/share/man/man3/Apache::Test.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestConfig.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestMB.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestMM.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestReport.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestRequest.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestRun.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestRunPHP.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestRunPerl.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestServer.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestSmoke.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestTrace.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

file /usr/share/man/man3/Apache::TestUtil.3pm.gz conflicts between attempted installs of perl-Apache-Test-1.30-2.el6.rf.noarch and mod_perl-2.0.4-10.el6.x86_64

The conflict in man!!! Man!!!

You got conflict in the Fcking manual that I wasn’t suppose to read and **failed!!!!!! the installation completely!!!!

I tried to google for that, and plenty of the problem like this

And, they won’t get anything as fixed….

So how can I go on?

I tried a dirty way.

First, I install the mod_perl and perl-devel using yum:

yum install -y mod_perl perl-devel

Then let’s download the perl-Apache-Test from CPAN:

wget http://search.cpan.org/CPAN/authors/id/P/PH/PHRED/Apache-Test-1.38.tar.gz

Then let’s install it:

perl Makefile.PL

make install

But, even we installed the f*cking perl-Apache-Test, we can’t be done, yet.

Yum won’t know you have installed the perl-Apache-Test, and will still try to download it and install it and failed your installation.

So, you need to test yum to skip it, adding 1 line to /etc/yum.conf

exclude=perl-Apache-Test

Then try the yum install again, you’ll be done.

It cost me 1 hour to do this investigation and how frustrated I was, so I wrote this blog to record it down, if this can helps anyone, the time and energy of mine won’t be wasted.