My laptop (use's Ubuntu 13.10) is connected to internet using a wired connection at eth0 with ip and it also acts as a wifi hotspot at wlan0 with the ip (i used airbase-ng to set up the ap). Now I have an android device that needs to get connected to that wifi. I see that my android is able to connect to the hotspot and receive the following network settings from the dhcp server I set up. (I used a tool call Net Info II from PlayStore to see the below details on my android).

# My android network settings (connected to the wlan0 of my laptop):
ip address:
gateway   :
ap-mac    : xx:xx:xx:xx:xx:xx

# My pc's eth0 configuration
ip address:
gateway   :
iface mac : yy:yy:yy:yy:yy:yy

# My pc's wlan0 (hotspot interface) configuration
ip address:
gateway   :
iface mac : zz:zz:zz:zz:zz:zz

This thread here talks about a similar problem. I see that I need to forward packets between eth0 and wlan0 network to connect my wireless ap's devices to internet. Now How do I forward the packets I receive from wlan0 to eth0 and eth0 to wlan0 to get my device connected to internet ?

  • 1
    You might have another problem: why does your Android device list as its gateway? I thought you only had two interfaces in your set-up – MariusMatutiae Dec 5 '13 at 13:17
  • I might not have configured my dhcpd.conf properly. I should set it to I guess. Thanks for the correction !!! – vikkyhacks Dec 5 '13 at 13:20
  • Another thing: do you have a rule in your pc's routing table telling it to use IF wlan0 for the network? – MariusMatutiae Dec 5 '13 at 13:22
  • No I dont, How do I add it ? and is it necessary that I add it, since is tied to to wlan0 will that rule be necessary ? – vikkyhacks Dec 5 '13 at 13:30
  • 1
    It is necessary. The command is sudo route add -net dev wlan0 – MariusMatutiae Dec 5 '13 at 13:33

You first need to enable IP forwarding on your system. To do it just this once, use

sysctl -w net.ipv4.ip_forward=1


echo 1 > /proc/sys/net/ipv4/ip_forward

as root. If you want to make it permanent, edit


and add a line containing

net.ipv4.ip_forward = 1

This will be applied on reboot or when you run

sysctl -p /etc/sysctl.conf

Once that is done, you probably need to NAT connections, as it is unlikely your router knows that the network is accessible through If is static, you can use

iptables -t nat -A POSTROUTING -i wlan0 -s -j SNAT --to-source

otherwise use

iptables -t nat -A POSTROUTING -i wlan0 -s -j MASQUERADE

Check the Ubuntu IptablesHowTo for how to save those rules when rebooting.

  • many thanks for your answer, but I am very new to iptables. The way I see your rule you seem to redirect traffic from wlan0 to but am I not supposed to do the reverse as well, to forward traffic from to wlan0. Or is that done automatically ? – vikkyhacks Dec 5 '13 at 13:02
  • 1
    @vikkyhacks When you set up SNAT, returning packets are automatically returned to their proper destination. Netfilter tracks the connections to know which IP originally sent the packet and forward the replies back to that address. – user2313067 Dec 5 '13 at 18:14
  • 4
    I couldn't use iptables -i option together with POSTROUTING. This command helped me out: iptables -t nat -A POSTROUTING -s -j MASQUERADE – Pablo López Torres Jun 13 '14 at 10:44

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.