How to Setup a Wireless Ubuntu Router 02/22/08

Router brokeThis morning I was moving some stuff around and my router fell, smashing to pieces. Oh no! I need a wireless connection today. The router was a noisy (the fan drives you crazy), older (but faithful) boat anchor. I was in a pinch, with no time to buy a new one (it’s a long drive). So, I thought a quicker (and for me “fun”), fix would be to set up a temporary router on an old PC.

Here’s how to do that; I hope this helps others and gives hobbyists a fun project.
Here’s the hardware used:
Celeron based PC (755MHz)
512MB RAM
10GB ATA HDD
Realtek 10/100 NIC (2 of them)
There is an integrated NIC on the motherboard, but I couldn’t find any drivers that worked.
AtlantisLand I-Fly A02WP54G (which I borrowed from another PC).

A Basic Server Install:

First thing you’ll need to complete is a base server install on the PC (don’t use LAMP or DNS). From googling, I found out that the wireless card I’m using will work from Ubuntu versions 5.10 (Breezy) and newer.

After the installation of the server is complete, make sure that you configure your repositories to use “Universe”.
Edit this file: /etc/apt/sources.list

sudo nano -w /etc/apt/sources.list

And add this: universe
The lines you edit, will look something like this:

deb http://ca.archive.ubuntu.com/ubuntu/ edgy main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ edgy main restricted

Make sure you create a backup copy of this file BEFORE you do anything. I should also note that when examining your sources.list, if you see an entry for CD,remove it. (For people interested in enhancing their repositories, please see here: http://ubuntulinuxhelp.com/the-best-ubuntu-linux-repository-list/)

After editing the sources.list file, use this command to update, so that you will receive the most recent versions of updates as we complete the installation:

sudo apt-get update

The Network:

This PC needs to work like the broken router did. Therefore:

eth0 = (Which is on the motherboard) is not working, and I think it’s a driver related issue.
eth1 = The external WAN connection to my ISP.
eth2 = Is the internal LAN connection to the network.
ath0 = Wireless connection.
br0 = The virtual bridge connecting eth2 (LAN) to ath0 (Wireless) – So that wireless connections can communicate on the network, which in turn can communicate with the Internet.

Adding the bridge is not too difficult. First we need to get the package like this:

sudo apt-get install bridge-utils

Now edit the network configuration file (interfaces) with this command (you don’t have to use nano, you can use any text based editor):

sudo nano /etc/network/interfaces

Edit the open file like this:
(I have included notes in this code below, please make sure that you check them).

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#The loopback network interface
auto lo
iface lo inet loopback

#etho is on the motherboard and the driver is not available? So… I had to disable this section.
#auto eth0
#iface eth0 inet dhcp
#pre-up iptables-restore < /etc/iptables.conf

#This is the WAN section. It connects to the Internet.
#Normally this uses DHCP from your ISP, so leave it as DHCP if your ISP uses DHCP.
#The “pre-up” command loads up the firewall iptables. Leave it enabled.
auto eth1
iface eth1 inet dhcp
pre-up iptables-restore < /etc/iptables.conf

#This is the Wireless section.
auto ath0
iface ath0 inet manual
wireless-mode master
#You must enter your own ESSID below – Change the word “nomadic” to your own ESSID.
wireless-essid nomadic

#This is the Bridge section. You don’t have to use the 10.1.1.0, which is a proper private IP (LAN) network range, you can change it to your needs.
auto br0
iface br0 inet static
address 10.1.1.1
network 10.1.1.0
netmask 255.255.255.0
broadcast 10.1.1.255
bridge-ports eth2 ath0

Save the file and exit.
With regards to the “eth1″ section, if your ISP does not use DHCP, then they can provide you with the correct information. That section should then be configured to look like this:

auto eth1
iface eth1 inet static
address 72.138.51.135
netmask 255.255.254.0
gateway 72.138.50.1
pre-up iptables-restore < /etc/iptables.conf

Note: DNS settings for the LAN (to be able to access web sites), is covered further down in the DHCP section.

Get WiFi Working:

The network card uses a madwifi driver and you can check here to see how to detect and install it: https://help.ubuntu.com/community/Router/Madwifi
I should point out that this resource helps to tell if your WiFi card is compatible: https://help.ubuntu.com/community/WifiDocs/WirelessCardsSupported but I don’t think it is an exclusive list. You can also try here: http://ubuntulinuxhelp.com/ubuntu-hardware-compatability-list-hcl/

We need WAP in Master mode, from one of the help.Ubuntu.com links (above):

“If you are plan on using this wireless network adapter in “master” mode (i. e. for the purposes of setting up a wireless router)…”

So, let’s do this to install the madwifi drivers:

wget http://umn.dl.sourceforge.net/sourceforge/madwifi/madwifi-0.9.3.1.tar.gz
tar -xvzf madwifi-0.9.3.1.tar.gz
cd madwifi-0.9.3.1

And this to install the tools + compile and install the needed module:
Just as the link said, we need to switch to master mode. We do this by creating the required file:

sudo nano /etc/modprobe.d/madwifi

And adding this code to the madwifi file:

options ath_pci autocreate=ap

Our wireless card is now in Master mode and we just have to load it by doing this:

sudo modprobe ath_pci

Time to move on…

The Firewall Needs to Forward Data:

We are setting up this firewall to simply forward data, not to protect the network! (Network protection is a whole other topic).
As with the WiFi section above, Ubuntu also has a great resource for that here: https://help.ubuntu.com/6.10/ubuntu/serverguide/C/firewall-configuration.html
And again, I am able to use their help in this guide.

Remember that eth0 is the WAN (Gateway) connection to the Internet, so (using the Ubuntu information), we need to do this:

sudo iptables -t nat -A POSTROUTING -s 10.1.1.0/24 -o eth1 -j MASQUERADE

sudo iptables -A FORWARD -s 10.1.1.0/24 -o eth1 -j ACCEPT

sudo iptables -A FORWARD -d 10.1.1.0/24 -m state --state ESTABLISHED,RELATED -i eth1 -j ACCEPT

Logging is a good idea. Logs should be found here:

/var/log/messages
/var/log/syslog
/var/log/kern.log.

And to enable the logging, use this code:

sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j LOG --log-prefix "NEW_HTTP_CONN: "

Remember when we entered this line “pre-up iptables-restore < /etc/iptables.conf” into the network setup? Let’s make sure we save the file accordingly (so that this works):

sudo iptables-save > /etc/iptables.conf

We need the router to be able to forward data (packets) using IPv4 (which most everyone uses). You can edit this file:

sudo nano /etc/sysctl.conf

To change this line:

#net.ipv4.conf.default.forwarding=1

So that it looks like this:

net.ipv4.conf.forwarding=1

DHCP needs to run so PC’s can connect easily.

Install DHCP:

sudo apt-get install dhcpd

Edit the configuration file for DHCP:

sudo nano /etc/dhcpd.conf

To look like this (your LAN based IP network address might be different, just make sure it matches what you set up in the “Network” section above):
(I use openDNS: http://www.opendns.com/)

#/etc/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
#Change the following to the DNS from your ISP or use openDNS
option domain-name-servers 208.67.222.222, 208.67.220.220;
#I don't need this but if I wanted an internal web server or something via FQDN...
option domain-name "nomad.int";
#Subnet for DHCP clients
subnet 10.1.1.0 netmask 255.255.255.0 {
#Range of 10 machines - If you need more, increase the range
range 10.1.1.20 10.1.1.29;
option subnet-mask 255.255.255.0;
option broadcast-address 10.1.1.255;
option routers 10.1.1.1;
}

DHCP failed to work properly, that’s when I forgot that DHCP listens for address requests on the first physical NIC and I still need it to work with wireless (eth0 is dead). That means it needs to work with the virtual bridge connecting eth2 (LAN) to ath0 (Wireless) – So that wireless connections can communicate on the network, which in turn can communicate with the Internet. Edit the DCHP file:

sudo nano /etc/default/dhcp

And add the bridge:

INTERFACES="br0"

Everything should be done now.

After restarting – a cold restart get’s the whole thing working – (I had to reboot and restart a few times before writing this – I made a few mistakes), everything should work.
A case in point, I’m posting this blog through the new (temporary) wireless connection. Now I’m happy. Besides… It’s Friday!!

Sharing is loving!


You can leave a response, or trackback from your own site.

12 Responses to this article

 
Pete March 6, 2008 Reply

This actually helped. Easy to follow. Thanks mate!

 
Michael June 5, 2008 Reply

Thank you so much for writing this! I am using DHCPd … where should I add this line?

INTERFACES=”br0″

Have a wonderful week,

Michael

 
 
UbuntuLinuxHelp June 5, 2008 Reply

@Michael – DHCPd is a daemon (service) used by servers to dynamically configure TCP/IP information for client systems. The “INTERFACES=br0″ line should be in /etc/default/dhcp :)

 
Michael June 5, 2008 Reply

Oops! I mean … I don’t seem to have this file:

sudo nano /etc/default/dhcp

Thanks!

 
 
UbuntuLinuxHelp June 5, 2008 Reply

@Michael – Oh… :)
That’s very strange, have you installed DCHP(d) are your network cards working?
Have you tried manually creating the /etc/default/dhcp?
The dhcp file is created by default.
Hopefully these suggestions and questions might help? :)

 
Blake July 28, 2008 Reply

For the dhcp configuration file, try the following path
/etc/dhcp3/dhcpd.conf

To set what interfaces the dhcp server listens on, try the following file:
/etc/default/dhcp3-server

Also keep in mind that the dhcp server is set up differently on different linux distributions.

If you didn’t find the file, try this.
Type in the following
/etc/dhcp
Press the tab key. This will autocomplete for you.
Get rid of the space it places after the last character and type
/dhcp
Press tab again. You may need to do it more than once. The file ending in .conf should be the configuration file.

Do something similar if you want to find the file in which the interfaces the dhcp server will listen on.
/etc/default/dhcp
tab again, not enter.
Delete the space after the last character, and you have your file pathname.

To open either of these files, press home and type
nano

You could have typed
nano
to begin with, as well.
If anyone wants to talk to me, e-mail me.
I found this on google, and probably won’t come back.
I found the information here quite useful, though, accept for the fact that my wireless card doesn’t support master mode.

I can use the rest of it, though.

 
 
UbuntuLinuxHelp July 31, 2008 Reply

@Blake – Thanks for the input.
I looked at your site… What is “VRN Software”? Is it for audio editing?

 
hehe August 26, 2010 Reply

what to do if it say duplicate interfaces

 
 
UbuntuLinuxHelp August 26, 2010 Reply

@hehe

?? Change the info for one of the interfaces?

Not sure what you’re referring to?
:)

 
sayed October 23, 2010 Reply

please guide me!
how can i configure a wireless access point by using of a pc, that the mentioned pc have ability of dhcp,routing.

 
 
UbuntuLinuxHelp November 19, 2010 Reply

@sayed

Install DHCP on the PC. If I remember, the command is something like:

sudo aptitude install dhcp3-server

 
Ashley January 8, 2011 Reply

Hello,

I am currently using Ubuntu 9.10 – the Karmic Koala on my Laptop as a normal OS. I would like to use this very laptop as a wireless router to allow my second laptop to access internet.

would the method outlined above work?

I am new to this,
please let me know
Cheers
A.

Leave a Reply

close comment popup

Leave A Reply