= Replicant USB Networking =
This page explains how to connect your Replciant phone to the Internet via an USB connection to a computer connected to the Internet.
What you needTwo scripts are necessary: one to run on the host computer and one to run on the device.
=== Replicant USB Networking - PC ===
Here's the script to run on the computer. Copy the following text to a file named "run_pc.sh" (or any other name, you just need to keep the same name along the process):
{{{
#!/bin/sh
IPTABLES_CLEAN_RULES=true
USB_IFACE="usb0" 
INTERNET_IFACE="eth0"
USB_IFACE_IP="192.168.4.200"
iptables_rules_clean () {
    if [ $IPTABLES_CLEAN_RULES = false ]
    then
        return
    fi
iptables --flush
    iptables --table nat --flush
    iptables --delete-chain
    iptables --table nat --delete-chain
}iptables_forward_rules_apply () {
    iptables --table nat --append POSTROUTING --out-interface $INTERNET_IFACE -j MASQUERADE
    iptables --append FORWARD --in-interface $USB_IFACE -j ACCEPT
    echo 1 > /proc/sys/net/ipv4/ip_forward 
}
usb_networking_configure () {
    ifconfig $USB_IFACE up
    ifconfig $USB_IFACE $USB_IFACE_IP
}
usb_networking_disable () {
    ifconfig $USB_IFACE down
    echo 0 > /proc/sys/net/ipv4/ip_forward 
}
case $1 in
    "start")
        echo "Starting Replicant USB Networking" 
        iptables_rules_clean
        usb_networking_configure
        iptables_forward_rules_apply
    ;;
    "stop")
        echo "Stopping Replicant USB Networking" 
        usb_networking_disable
        iptables_rules_clean
    ;;
    *)#!/bin/sh
IPTABLES_CLEAN_RULES=true
USB_IFACE="usb0" 
INTERNET_IFACE="eth0"
USB_IFACE_IP="192.168.4.200"
iptables_rules_clean () {
    if [ $IPTABLES_CLEAN_RULES = false ]
    then
        return
    fi
iptables --flush
    iptables --table nat --flush
    iptables --delete-chain
    iptables --table nat --delete-chain
}iptables_forward_rules_apply () {
    iptables --table nat --append POSTROUTING --out-interface $INTERNET_IFACE -j MASQUERADE
    iptables --append FORWARD --in-interface $USB_IFACE -j ACCEPT
    echo 1 > /proc/sys/net/ipv4/ip_forward 
}
usb_networking_configure () {
    ifconfig $USB_IFACE up
    ifconfig $USB_IFACE $USB_IFACE_IP
}
usb_networking_disable () {
    ifconfig $USB_IFACE down
    echo 0 > /proc/sys/net/ipv4/ip_forward 
}
case $1 in
    "start")
        echo "Starting Replicant USB Networking" 
        iptables_rules_clean
        usb_networking_configure
        iptables_forward_rules_apply
    ;;
    "stop")
        echo "Stopping Replicant USB Networking" 
        usb_networking_disable
        iptables_rules_clean
    ;;
    *)
        echo "Usage: sh $0 {start|stop}" 
    ;;
esac
        echo "Usage: sh $0 {start|stop}" 
    ;;
esac
}}}
Then, set this file executable: {{{ chmod a+x run_pc.sh }}}
=== Replicant USB Networking - Device ===
Here's the script to run on the device. Copy the following text to a file named "run_dev.sh" (or any other name, you just need to keep the same name along the process):
{{{
#!/system/bin/sh
USB_IFACE="usb0"
USB_IFACE_IP="192.168.4.202" 
GATEWAY_IP="192.168.4.200" 
DNS1_IP="8.8.8.8"
usb_networking_enable () {
    echo 1 > /sys/class/usb_composite/rndis/enable
    ifconfig usb0 up
}
usb_networking_configure () {
    ifconfig $USB_IFACE $USB_IFACE_IP
    route add default gw $GATEWAY_IP dev $USB_IFACE
    setprop net.dns1 $DNS1_IP
usb_networking_disable () {
    echo 0 > /sys/class/usb_composite/rndis/enable
    ifconfig usb0 down
}
case $1 in
    "start")
        echo "Starting Replicant USB Networking" 
        usb_networking_enable
        usb_networking_configure
    ;;
    "stop")
        echo "Stopping Replicant USB Networking" 
        usb_networking_disable
    ;;
    *)
        echo "Usage: sh $0 {start|stop}" 
    ;;
esac
}}}
Now you need to copy it to your phone. Start adb server as root: {{{ # adb start-server }} and copy the file (as regular user): {{{ adb push run_dev.sh /sdcard/ }}} (you can change /sdcard/ to any other writable disk place, just remind where you put it).