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.
- Create an ad-hoc wireless network
- Bridge eth0 <----> eth1 and allow packet forwarding
- 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.
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:***********
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.
tip: To revert back,
comment the "net.ipv4.ip_forward = 1" in /etc/sysctl.conf and
type "/etc/init.d/ipmasq stop"