View Single Post
Posts: 197 | Thanked: 101 times | Joined on Dec 2009 @ Netherlands
#29
Based on the usb wiki by dartarrow I setup my n900 as a router so I can access internet on my fedora 12 laptop via the cellular network without dun or wvdial. So the n900 is still fully usable. See below script that includes all the documentation.

Code:
#!/bin/sh
#
# usbnet.sh - script to setup the N900 as an ip router
#
# Author:   Mirakels 
#
# Date:     may 2010
#
# This script and documentation sets up the N900 as a router
# between your PC and the wlan/cellphone on your n900.
#
# We need to setup the usb device, allow forwarding and
# masquerade all traffic going outside...
# to get simple dns working on your PC we als need to update
# dnsmasq on the n900.
# 
#
# Preparations
# ============
# So you need the iptables package (apt-get install iptables)
# and a kernel that supports iptables (don't know if the
# default kernel supports iptables. I use the titan overclock
# kernel)
#
# Note the preparation woork needs to be done as root...
# 
#
# SETUP USB0
# ----------
# Changed usb0 definition in /etc/network/interfaces
# from:
#      auto usb0
#      iface usb0 inet static
#              address 192.168.2.15
#              netmask 255.255.255.0
#              gateway 192.168.2.14
#
# to:
#      auto usb0
#      iface usb0 inet static
#              address 192.168.50.1
#              netmask 255.255.255.0
#
# I just picked the 192.168.50.x subnet to act as the intermediate
# network. It should be a subnet that is not used within your campus.
#
# SETUP DNSMASQ
# -------------
# Changed dnsmasq exec line in /etc/event.d/dnsmasq
# from:
#      exec /usr/sbin/dnsmasq -k -i lo -a 127.0.0.1 -z 
#
# to:
#      exec /usr/sbin/dnsmasq -k -i lo -a 127.0.0.1 -z -i usb0
#
# So it also listens on the usb0 network interface for dns queries
#
#
# With above steps the n900 is prepared to act as a router.
#
# STARTUP
# =======
# Connect the n900 with the usb cable to your laptop.
# When the n900 asks for 'mass storage' or 'PCsuite',
# select 'PCsuite'.
#
# Run this script without options, e.g.:
#
#       sudo gainroot
#       /home/user/usbnet.sh
#
# This will start he usb0 network device, allow
# ip forwarding and sets up masquerading.
#
# Now it is time to do some steps on your laptop/PC.
# The steps depend on your laptop OS. For my Fedora 12
# system I will see a new network interface called usb0.
# All I need to do now as root is:
#
#   ifconfig usb0 192.168.50.2
#   route add default gw 192.168.50.1
#   echo "nameserver 192.178.50.1" > /etc/resolv.conf
#
# and I have internet access from the laptop through the n900
# while the n900 still can be used as fully functional network
# device and phone.
#
# The nice thing in this setup is that I can still monitor the
# total traffic  through the cell phone network via the n900
# dataplan tool.
#
# PS: I tried to defined the usb0 network in network manager
#     but then I need a MAC address of the usb0 device to define
#     the connection. Unfortunately the MAC address seems to
#     be a random address so changes every time the usb connection
#     is recreated.
#
#
# To stop acting as a router run this script again with some
# dummy command line argument
#
#       sudo gainroot
#       /home/user/usbnet.sh done

if [ -z "$1" ] ; then
    echo "Starting network and forwarding through usb0"
    ifup usb0
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -t nat -A POSTROUTING -o gprs0  -j MASQUERADE
    iptables -t nat -A POSTROUTING -o wlan0  -j MASQUERADE
else
    echo "Stopping network and forwarding through usb0"
    ifdown usb0
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -t nat -D POSTROUTING -o gprs0  -j MASQUERADE
    iptables -t nat -D POSTROUTING -o wlan0  -j MASQUERADE
fi

#
# The End
#
 

The Following User Says Thank You to mirakels For This Useful Post: