View Single Post
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: