View Single Post
Viqsi's Avatar
Posts: 115 | Thanked: 136 times | Joined on Mar 2008 @ Central Ohio
#235
This script, for whatever reason, wasn't working effectively for me and my iPad when I tried - and I wanted something that required less intervention. So I took bits of it (notably, the whole setting-up-dnsmasq bit for DHCP) and shoehorned it into a method described here: http://hacker.klever.net/n/2011/06/0...n#.T1ew6-XipJa. It works beautifully for me.

The advantage of this method is that there is no script that has to be run at any time. It Just Works Automatically, whether my n900 is connected via 3G or WiFi (that's 'cause the iptables setup is very subtly different, going by subnets rather than interface; it could probably be adapted to the OP's script as well).

The disadvantages are twofold:
1) pc-connectivity-manager potentially conflicts with this method (it occasionally likes to modify one of the files in question by itself), so if you're using it for other purposes then this won't work for you, and
2) it requires modifying system files and so a typo can potentially screw up your system. If you're at all worried about possible screwups along the way, I'd suggest sticking to the script in the OP.

There might be a way to make this work with pc-connectivity-manager (if it can be used to make the necessary changes to /etc/network/interfaces itself). I leave this as an exercise for the reader, as I have no interest in messing with that package again.


Quick and dirty steps follow...

Preqs needed: rootsh, Kernel-Power, iptables. pc-connectivity-manager should NOT be installed!

FIRST: As root, modify the file "/etc/network/interfaces". Make a backup copy first! By default, it'll look something like this:
Code:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
There may be more in the file; don't be alarmed. The thing to watch out for is whether or not a "bnep0" appears anywhere in the file - so long as "bnep0" isn't in there yet, there's no worries. (It shouldn't appear, but if you've used pc-connectivity-manager and it's still installed then this problem has a good chance of showing up, in which case this will not work and you might not be able to use this method.)

You need to add the following section to the bottom of the file:
Code:
auto bnep0
iface bnep0 inet static
        address 192.168.100.10
        netmask 255.255.255.0
        pre-up sh -c "/usr/sbin/iptables -t nat -F ; /usr/sbin/iptables -t nat -A POSTROUTING -s 192.168.100.0/24 ! -d 192.168.100.0/24 -j MASQUERADE ; echo 1 >/proc/sys/net/ipv4/ip_forward"
SECOND: As root, create a new file, "/etc/udev/rules.d/50-bnep.rules". The contents should be as follows:
Code:
KERNEL=="bnep0", ACTION=="add", RUN+="/bin/sh -c '/sbin/ifup -f %k ; /sbin/start-stop-daemon -S -p /var/run/btpan.pid -m -b -x /usr/sbin/dnsmasq -- -k -I lo -z -a 192.168.100.10 -F 192.168.100.100,192.168.100.105 -b'"
KERNEL=="bnep0", ACTION=="remove", RUN+="/bin/sh -c '/sbin/ifdown -f %k ; /sbin/start-stop-daemon -K -p /var/run/btpan.pid'"
THIRD: Pair your n900 and PC (or iPad, or any other such device).

FOURTH: Enjoy!

Hopefully this will work for all y'all as well as it did for me.

Last edited by Viqsi; 2012-03-07 at 19:46. Reason: Minor change to the second part - that also has to be done as root.
 

The Following 3 Users Say Thank You to Viqsi For This Useful Post: