Make your PC link the Ben to the Internet, Automagically!

A familiar pain for Ben Nanonote users is connecting the Ben online every-time they plug it in. udev can remove this pain with a simple rule to run all the commands on the host the Ben is connected to when its connected. To get this done, you will need 2 pieces: a udev rule, and a script.

Your udev rule can be a file under  /etc/udev/rules.d/ . I called mine “72-BenNanoNnote-net.rules”

It’s content should look like this:

SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0525", ATTR{idProduct}=="a4a1", RUN+="/usr/local/bin/"
# where RUN+= points to your script

The script should look like this, and can feel comfortable under /usr/local/bin :

if (/usr/bin/lsusb -t -d "0525:a4a1"); then
        echo .
        echo "Ben NanoNote found, setting up USB network ... "
        if !( /sbin/lsmod | grep 'ip_tables' ) && ( /sbin/modprobe -l ip_tables ); then
                /sbin/modprobe ip_tables
                echo "ip_tables is now loaded"
                echo "ip_tables already loaded"
        if ( grep '0' /proc/sys/net/ipv4/ip_forward ); then
                echo "1" > /proc/sys/net/ipv4/ip_forward
                echo "IP forwarding is now enabled"
                echo "IP forwarding already enabled"
        if !( /usr/sbin/iptables -L | grep $GATEWAY_IF ); then
                /usr/sbin/iptables -t nat -A POSTROUTING -o $GATEWAY_IF -j MASQUERADE
                echo "Routing is now enabled"
                echo "Routing already setup on "$GATEWAY_IF
        /sbin/ifconfig usb0 netmask
# where GATEWAY_IF is the interface that is connected to your LAN or the Internet.

Leave a comment

Filed under Ben Nanonote

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s