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;
option  local-wpad      code    252     =       text;

subnet netmask {

# --- default gateway
      option routers        ;
# --- Netmask
      option subnet-mask    ;
# --- Broadcast Address
      option broadcast-address;
# --- Domain Name, set the domain name for DHCP clients
      option domain-name              "";
# --- Domain name servers, tells the clients which DNS servers to use.
      option domain-name-servers,,,;
      option time-offset              0;      # Eastern Standard Time
      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 netmask
#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.


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.