Tuesday, July 24, 2007

Ubuntu : Creating a wireless home network to share internet without router

System : Ubuntu Feisty/Centrino HP laptop
Broadband : BSNL 2 MBps ADSL
Connection type : Internet connected via pppoE on eth0 (our internet gateway)
wireless adapter eth1

Other Devices on the network : Nokia N80, Hp tablet pc, HP Desktop (with a wifi card)

Aim : To create an ad-hoc wireless network using the wifi card and share internet. Eth0 is connected directly to internet. Eth1 will be used to interface with the other devices in the network by creating the ad-hoc wireless network.

Basic Steps:
  1. Create an ad-hoc wireless network
  2. Bridge eth0 <----> eth1 and allow packet forwarding
  3. Assign IP statically or dynamically to clients on the network.

Creating an ad-hoc connection

1. From shell
# sudo iwconfig eth1 essid "WirelessNetworkName" mode Ad-Hoc key s:***********

where **************** is the WEP key in ASCII. Replace eth1 with the interface of your wireless card.

2. Your adhoc network should be up and your devices can start connecting to it. They still cannot start accessing the internet.


Sharing internet

Note: Type all the following commands in a root terminal, DO NOT use sudo.

1. Start by configuring the network card that interfaces to the other computers on you network:

# ifconfig ethX ip

where ethX is the network card and ip is your desired server ip address (Usually 192.168.0.1 is used) eth1 in our case.

2. Then configure the NAT as follows:

# iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE

where ethX is the network card that the Internet is coming from

# echo 1 > /proc/sys/net/ipv4/ip_forward

3. Install dnsmasq and ipmasq using apt-get:

# apt-get install dnsmasq ipmasq

4. Restart dnsmasq:

# /etc/init.d/dnsmasq restart

5. Reconfigure ipmasq to start after networking has been started:

# dpkg-reconfigure ipmasq

6. Repeat steps 1 and 2.

7. Add the line "net.ipv4.ip_forward = 1" to /etc/sysctl.conf

# gedit /etc/sysctl.conf

8. # sudo iwconfig eth1 essid "WirelessNetworkName" mode Ad-Hoc key s:***********


Assigning IPs
1 .Either assign static IPs to the clients eg. 192.168.0.x
2. Or run a dhcp server on the host.

Note : In some devices like my Nokia N80, assigning static IPs could be tricky. Hence, dhcp is the best way to go.

We are done....
Now, all your devices can access internet without any need for an additional hub/switch/router.
Enjoy surfing,

tip: To revert back,
comment the "net.ipv4.ip_forward = 1" in /etc/sysctl.conf and
type "/etc/init.d/ipmasq stop"

10 comments:

Anonymous said...

I've tried this with my N80 and I keep getting "No gateway reply"! I see the active adhoc connection in the connection manager

This is using the following settings on my N80

IPv4 settings:
phone ip: 192.168.0.2
subnet mask: 255.255.255.0
default gateway: 192.168.0.2
primary DNS: 192.168.0.2
secondary DNS 192.168.0.2

Doesn't one have to add

#route add 192.168.0.2 dev eth1

Would it be easier to run DHCP? How can I set this up....?

Anoj said...

Sorry for this really late reply

IPv4 settings (phone):
phone ip: 192.168.0.2
subnet mask: 255.255.255.0
default gateway: 192.168.0.1
primary DNS: 192.168.0.1
secondary DNS 192.168.0.1

Ad-hoc Wifi settings (eth1):
eth1 ip: 192.168.0.1
subnet mask: 255.255.255.0

Anonymous said...

I would like to be able to allow my computer to sleep or just go into screensaver mode without having to reboot my computer and starting up the ad-hoc again. Is there a way to restart it without having to reboot?

Anonymous said...

thanks - this works great on ibex with my n95. FYI for all other N95 owners the ip can be set statically under advanced settings of the wifi connection..

Anonymous said...

I still cant connect to my network what i created in ubuntu. PC what cant connect is Windows XP.

i used command:
sudo iwconfig wlan0 essid "internet" mode Ad-Hoc

NOTE: i dont have password on this network.
Xp machine can see connection, but just wont connect! :S

Anonymous said...

Just use wifi-radar and firestater to make this simple, see http://niotech.blogspot.com/2009/05/ubuntu-adhoc-connection-with-internet.html

Nokia N80 Features said...

Nokia N80 user friendly phone comes with great sound, great picture quality and main draw back of this phone is sliding problem.

Anoj said...

Yeah it was a great phone for its time. Mine lasted just over a year but I hacked around it a lot :)

portable wireless router said...

Super! Just what I was looking for. :-)

Unknown said...

Great tips and have shared internet without router. superb dude! Laptop Specifications