Monday, March 22, 2010

Internet over USB-OTG on BeagleBoard using NAT

 Firefox working in BeagleBoard

NAT stands for Network Address Translation. This concept allows to route a packet with changed address header so that the packet can be transported from one network to another.

Here is how it works for BeagleBoard.

Power up the BeagleBoard and connect it to your host computer using USART using minicom.
once you have logged in, enable g_ether.ko driver by

# cd /lib/modules/2.6.29-omap1/kernel/drivers/usb/gadget/
# insmod g_ether.ko

Now the driver is enabled. Now connect the USB-OTG cable between beagleboard and host computer. Configure the connection as follows:-

# ifconfig usb0 netmask
# route add default gw
# vi /etc/resolv.conf
    Add hostIP as nameserver, your hostIP will be as explained later
    -> nameserver

# export http_proxy=""

the last step set the variable to our local proxy and port number , change this according to the connection on your host machine.

On the Host computer:-

# ifconfig usb0 netmask
# sudo vi /etc/sysctl.conf
   uncomment the line   net.ipv4.ip_forward=1 , to enable forwarding of packets.
# sudo sysctl -p
# sudo cat /proc/sys/net/ipv4/ip_forward
   to check that the change has been made and routing is enabled
# sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j  MASQUERADE
# sudo iptables --append FORWARD --in-interface usb0 -j ACCEPT

This will establish the connection of beagleboard to the internet. Test the connection using ping command.

Now you can realise the power of opkg and install the packages, driver directly from the repositories


  1. Great post..! It was really helpful! thanx a lot!

  2. After i did all you said, I am not able to ping external URLs. I can successfully ping from beagleboard, and from the host. Also I am able to scp files from the host to the board, but not in the other way. Please help to get the internet working on my board.

  3. Hi Shubham,
    I am vipul from Bangalore. We have been experimenting with beagleboard since quite few days. So far, we could compile android source & have got bootable SD card. The next thing that we want to try is connect beagleboard to our laptop & possibly have ssh tunnel established to BB from host machine (ubuntu). Please, let me know how can this be done? Can u share contact detail (email/cell) so that i can get in touch with you.
    -Vipul (

  4. This is how I got it all to work, and what I have to do after every reboot:

    ON BEAGLEBOARD run the following:
    modprobe g_ether
    [Now insert the USB cable to your Linux computer]

    ON COMPUTER run:

    [The following commands assumes port usb0 is used and that eth1 (in my case my WLAN) is used. Since I'm using a router which has the subnet 192.168.1.* , I can't use this subnet, which is why I use subnet 192.168.2.*]

    sudo ifconfig usb0 netmask
    sudo iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE
    sudo iptables --append FORWARD --in-interface usb0 -j ACCEPT

    [nameserver ip is the default route of the Internet you get to your computer, in my case through a router. The http proxy ip is the ip my computer get its internet from.]

    ifconfig usb0 netmask
    route add default gw
    vi /etc/resolv.conf
    [paste the following and save file] nameserver
    export http_proxy=""

    Now everything should hopefully work. If you can ping your computer but not, ex, you should try to ping from your computer to get on of google's IPs. Then ping that IP from beagleboard, if that works you know it's just something wrong with your nameserver config above...


  5. Great ! Thank you !

  6. Guys, please help
    when I use this command (on computer):
    sudo iptables --append FORWARD --in-interface usb0 -j ACCEPT

    I get
    iptables: No chain/target/match by that name.

  7. Whenever I try to run the "sudo ifconfig usb0 netmask" on the beagle board it keeps telling me:
    "SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied"
    how do I fix this?

  8. This comment has been removed by a blog administrator.