Jump to content

[Request] The script used to automatically change from eth0 to usb0 for android teathering


inTheDMZ
 Share

Recommended Posts

Why: Because I'm lazy and Don't want to write it myself!

I noticed when the pineapple has a usb0 device (android phone) it automatically adjusts its iptables rules to use this at the gateway to the internet.

Wondered if i could have this script so i can use it on a personal project.

Background for those who are interested: I have a internet connection with Virgin Media, which constantly drops out. I also have unlimited teathering on my Galaxy S3 with ThreeUK, so want to be able to plug it into my WR1043N and have it automatically foward all traffic over the usb0 connection. I want to also edit the script so when usb0 is removed the WAN ethernet port is once again used as the internet access gateway.

Many Thanks,

IntheDMZ

Link to comment
Share on other sites


Looked at the Github repository for a script but think it may be beyond the webui!

edit: Don't have my pineapple with me at the moment so will have a look on it when I get hold of it again, unless anyone else knows how it does it?

Edited by inTheDMZ
Link to comment
Share on other sites

Looked at the Github repository for a script but think it may be beyond the webui!

edit: Don't have my pineapple with me at the moment so will have a look on it when I get hold of it again, unless anyone else knows how it does it?

I'll start looking for it soon

Help a brother out!

-Foxtrot

Link to comment
Share on other sites

First, you will need to set up a USB0 Interface. See the pineapple's /etc/config/network file:

config interface usb
    option ifname usb0
    option proto dhcp
    post-up sh /path/to/iptables/script.sh

To be able to do this you WILL need to have the appropriate driver installed. Then, you will need to run these IPtable commands (or put them in a script to automate with the above post-up):

iptables -t nat -A POSTROUTING -s 172.16.42.0/24 -o usb0 -j MASQUERADE
iptables -A FORWARD -s 172.16.42.0/24 -o usb0 -j ACCEPT
iptables -A FORWARD -d 172.16.42.0/24 -m state --state ESTABLISHED,RELATED -i usb0 -j ACCEPT

Of course, you will need to adjust these to your liking..

Link to comment
Share on other sites

Cheers Seb,

Am I correct in saying the pineapple automatically detects usb0 and sets up iptable rules according?

Actually not right now but it will in 2.8.0.

You can fulfil that requirement by having a postup part in your network config.

I have edited my previous reply.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...