You are here

howto: setup a tethered router network aka internet connection for laptop via pc via android phone

it came to pass on one cold, snowy night that internet access from only one compute was no longer sufficient. i needed to put my old laptop on the internet too. however, my internet source was my t-mobile android phone. yes, i tether my pc or laptop to get on the internet. this brings up an interesting scenario because the android phone's usb cable has to go into a usb port, either on the laptop or the pc.

so there are 3 devices in this network

  1. the android phone - through which flows the internet tubes
  2. the linux pc - which will be the router for the laptop
  3. the laptop

and on the linux pc there will be the following interfaces:

  1. usb0
  2. eth0


the solution apparently is really old and has been around for a while

1. in /etc/sysctl.conf change the line to result in

net.ipv4.ip_forward = 1

2. add the following rule to your iptables


-A POSTROUTING -o usb0 -j MASQUERADE

the command for that is


iptables -A POSTROUTING -o usb0 -j MASQUERADE


then save it with


/etc/init.d/iptables save

3. set up a dhcp server (optional)


chkconfig dhcpd on

create /etc/dhcp/dhcpd.conf with the following contents:

#authoritative;
ddns-update-style interim;
default-lease-time 21600;
max-lease-time 43200;

        option routers                  192.168.1.2;
        option broadcast-address        192.168.1.255;
        option subnet-mask              255.255.255.0;
        option domain-name-servers      192.168.42.129;

        subnet 192.168.1.0 netmask 255.255.255.0 {
                range 192.168.1.200 192.168.1.220;
}

        subnet 192.168.42.0 netmask 255.255.255.0 {
}

        subnet 192.168.122.0 netmask 255.255.255.0 {
}


some explanation is required here.
the authoritative command is commented out because the android phone has a dhcp server on it. so you cant have 2 authoritative servers on the same network.

eth0 ip on the linux pc is statically set at 192.168.1.2 via system-config-network
the dns (domain-name-server) is the android phone at 192.168.42.129. i havent experimented to see if this a static ip or from the dhcp server on the phone.

for the eth0 subnet i gave it a range of 21 ips to use. from 192.168.1.200 to 192.168.1.220.

the 192.168.42.0 subnet is used by the usb0. it is declared only to avoid unnecessary messages and errors in the logs.

the subnet 192.168.122.0 is used by kvm and is declared for the same reason.

hmm..would an usb hub work? let me know in the coments section.