Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Share your 3G Internet connection over wifi (Linux / iPod Touch)

Date: 2011-03-19 00:00:00 -0400

Introduction

I was in a situation the other day, where I needed to connect my iPod Touch to the internet but there was no wifi available so I think about using my 3G data plan. I have a data plan with my Laptop, I use a Huawei E156 B, to connect my laptop with the 3G network.

Of course I have a wifi network in my Laptop too, so what I needed to do was:

  • Connect my laptop to the 3G network
  • Enable my wifi network in Ad-Hoc mode
  • Configure DHCP server to give IP to my iPod Touch
  • Enable IP forwarding in the Linux kernel
  • Add the needed routes.
  • Add needed IPTables rules for NAT

Preparing the Laptop

Note: Maybe to configure your wireless card in master mode is better than doing it in Ad-Hoc mode, but mine and lots of cards does not support master while still support Ad-Hoc mode. Having said that, let’s continue.

First thing you need to do, is to configure your DHCP server, so you can assign an IP to the iPod that is going to connect.

Here is my configuration, a simple one is needed.

ddns-update-style none;
ignore client-updates;
authoritative;
option  local-wpad      code    252     =       text;

subnet  192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
      option routers                  192.168.1.1;
# --- Netmask
      option subnet-mask              255.255.255.0;
# --- Broadcast Address
      option broadcast-address        192.168.1.255;
# --- Domain Name, set the domain name for DHCP clients
      option domain-name              "go2linux.org";
# --- Domain name servers, tells the clients which DNS servers to use.
      option domain-name-servers      192.168.1.1, 8.8.8.8, 8.8.4.4, 4.2.2.2;
      option time-offset              0;      # Eastern Standard Time
      range 192.168.1.10 192.168.1.15;
      default-lease-time 1209600;
      max-lease-time 1814400;
}

Create the script that is going to enable your laptop to share 3G with iPod

Now, here is the script that does the job, you will have to run it as root, or with root privileges.

#Enable wireless lan card, replace  with your interface name.
ifconfig wlan0 up
#Configure it in Ad-Hoc mode
iwconfig wlan0 mode Ad-Hoc
#Set the ssid for your shared network
iwconfig wlan0 essid shared3G
#Assign an IP address to it, use a private one.
ifconfig wlan0 up 192.168.1.1 netmask 255.255.255.0
#Start your DHCP server, this line applies for Arch Linux, for Debian should be
#/etc/inid.d/dhcpd start
/etc/rc.d/dhcpd start
#Set the IP tables rules to run NAT
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan1 -j ACCEPT
#Temporaly enable IP forwarding in the Kernel
sysctl -w net.ipv4.ip_forward=1

You are done, now you can connect your iPod touch to the internet using your Laptop 3G data plan.

Conclusion

This resulted very useful to me, but unfortunately I could not share internet with my Android phone as it is not rooted, and it cannot see Ad-Hoc wifi networks, I should use master mode for that, will have to get a usb wifi interface that support master mode.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.