Reply
Thread Tools
Posts: 186 | Thanked: 79 times | Joined on Feb 2010
#1
Helo,
I create a script for myself to connect my N900 to internet via my Ubuntu Laptop when I'm at job. It's poor coded but works.
I hope someone can find it usefull.

Just copy the code to text blank text file, name it how you want, add proper rights (chmod 777 for example) and run it as root.

It is necessary to create adhoc connection on your n900 first.
So go to settings -> connections -> new -> name it as you want choose ad-hoc mode -> go in to advanced -> set ip 192.168.0.2, mask 255.255.255.0, gw 192.168.0.3 (don't need to set dns, they doesn't work for some reason, you need to add them manually - see and of the script).

You need to modify names of your interfaces in the script and your "internet interface" ip adress.

Then connect your linux laptop to ad-hoc network, set the static ip, disable your firewall run sudo ./scriptname and it should work.


Warning: it will disable lot of iptables rules so shouldn't be run on servers. You need to manually run your firewall/masquarade script or reboot after use.

Code:
#!/bin/sh -e
echo 'cleaning iptables'
iptables -F -t nat
iptables -F INPUT
iptables -F FORWARD
iptables -F PREROUTING -t nat 
iptables -F POSTROUTING -t nat
iptables -F
echo '[done]'
echo 'setting up ip forwarding'

#here you need to put -i WIFI_INTERFACE_NAME -o INTERNET_INTERFACE_NAME
iptables -A FORWARD -i wlan0 -o eth0 -s 192.168.0.2 -j ACCEPT

#Put your INTERNET_INTERFACE_ADDRESS in place of 10.4.255.205
iptables -A POSTROUTING -t nat -s 192.168.0.2 -d 0.0.0.0/0 -j SNAT --to-source 10.4.255.205	

echo '[done]'
echo 'enabling kernel forwarding'
echo 1 > /proc/sys/net/ipv4/ip_forward
echo '[Done]'
echo '------------------------------------------------------------------' 
echo 'Set up AD-HOC network between this computer and your n900'
echo 'Your N900 should have following settings:'
echo 'IP: 192.168.0.2'
echo 'MASK: 255.255.255.0'
echo 'GW: 192.168.0.3'
echo 'DNS: 8.8.8.8'
echo 'You should disable power savings'
echo 'Your linux PC wireless interface should have following settings:'
echo 'IP: 192.168.0.3'
echo 'MASK: 255.255.255.0'
echo '------------------------------------------------------------------'
echo 'it may be nessesary to run on your N900 as root following command:'
echo "echo 'nameserver 8.8.8.8'>> /etc/resolv.conf"
echo 'If you have problems try to disable firewall.'
echo 'Re-run your firewall script or restart computer after use.'
echo '------------------------------------------------------------------'
echo 'Enjoy my crapy script:)' 
exit 0

#hardkorek
 

The Following 4 Users Say Thank You to hardkorek For This Useful Post:
arora.rohan's Avatar
Posts: 353 | Thanked: 166 times | Joined on Jun 2010 @ India
#2
its not that hard.. :/
create an adhoc connection in ubuntu.
then enable the share option (available to all users )on ur default internet connection..
connect ur n900 to the adhoc.. and thats it no scripting and all..yea disable firewall.. but thanks anyways!
 
Posts: 186 | Thanked: 79 times | Joined on Feb 2010
#3
But this method doesn't work with my atheros card for some reason.
It can by also used on other distros without gnome network manager
 
arora.rohan's Avatar
Posts: 353 | Thanked: 166 times | Joined on Jun 2010 @ India
#4
ermm.. hmm...yea dont know about Kde..
wait...lol..does ur nm-applet goes FUBAR as soon as u connect to the Adhoc?
 
Posts: 186 | Thanked: 79 times | Joined on Feb 2010
#5
Yes it is
 
arora.rohan's Avatar
Posts: 353 | Thanked: 166 times | Joined on Jun 2010 @ India
#6
ahah thats a sad bug i had to install an older version of nm-applet to get it work.. ><!
 
Posts: 186 | Thanked: 79 times | Joined on Feb 2010
#7
I have other problems with ad-hoc mode and monitor mode on this card.
Any way I'm trying to learn iptables so I don't mind if there is easier method.

It still may be useful on LXDE or FLUXBOX
 
manvik60's Avatar
Posts: 128 | Thanked: 46 times | Joined on Mar 2010 @ Switzerland
#8
Shouldn't is it be "How to" instead of "Announce" ? as I thought you have some auto program/widget to bridge wifi between n900 and pc.

Great work thought. keep it up.
 
Posts: 186 | Thanked: 79 times | Joined on Feb 2010
#9
So maybe moderator could change it?
I can not see any possibility of doing it.
 
Reply


 
Forum Jump


All times are GMT. The time now is 01:06.