LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Manually sharing Internet connection with phone via USB (https://www.linuxquestions.org/questions/linux-newbie-8/manually-sharing-internet-connection-with-phone-via-usb-4175479495/)

klglhqcw 10-03-2013 02:50 PM

Manually sharing Internet connection with phone via USB
 
Hi.

I'm not a total newcomer to Linux, but to networking, with which I have a very small problem, it sadly is so.

I have a phone (SE J108i) which I want to use my PC's Internet connection via USB. The phone has that feature, and in fact, it works on Ubuntu, easily (auto)configured in its GUI according to this page I found:

http://kenyangeekboy.blogspot.com/20...son-w890i.html

Thing is, I use Slackware 14, and I'd rather not install any extra software for that purpose, GUI or not. So, my question is: how to enable that sharing on it manually (say, in a script) after I plug the phone in?

Here are the details of the connection on Ubuntu:

Ethernet (usb0)
hardware address: 02:80:37:ec:02:00
driver: cdc_ether
IP: 10.42.0.1
broadcast address: 10.42.0.255
subnet mask: 255.255.255.0
"IPv4 Settings: Shared to other computers"
(that line I believe might be the most important)

How can I recreate that manually? The furthest I found was that after
ifconfig usb0 10.42.0.1
I could ping 10.42.0.1 and the phone would respond. But I don't know what to do next. If I knew which files contain the relevant network settings, I could compare them between the systems, but I don't.

I'm sorry for such a direct request for such a small problem, but I'd really like to have that feature.

Thanks.

corp769 10-03-2013 04:00 PM

If you are seeing your usb0 device, you should be able to run dhcpcd on that device, and have it use your phone as the gateway, and should be good. Once you get to the point where you can see usb0 in your ifconfig output, run "dhcpcd usb0", and check the output of the "route" command - you should see a reference to the gateway (phone)

klglhqcw 10-03-2013 04:34 PM

Quote:

Originally Posted by corp769 (Post 5039533)
have it use your phone as the gateway

But it's my PC that's the gateway, IIUC. It's it that provides the connection to the phone.

Besides, I'm not sure what DHCP has to do with anything. After the Googling I did today, I came to imagine that ifconfig can be used to provide the phone with the data that's normally provided with DHCP, as quoted in my first post. But I might be wrong here.

Meanwhile, here's the output of route and iptables -L (which I Googled might have to do with it, too) on Ubuntu, if it helps:
http://pastebin.com/ntZVczMZ

I'm trying to think of ways in which I could discover what the Ubuntu network manager is doing when I set the "Shared to other computers" option (which in fact is the only thing that I have to do manually for the sharing to work).

Oh, and one more thing: the live Ubuntu that I'm using actually has neither dhcpd nor dhcpcd installed at all. So whatever it does, it does without them.

klglhqcw 10-03-2013 07:43 PM

Also, I found

http://forum.xda-developers.com/show....php?t=2287494 ,

which basically says (claiming confidently that nothing more is needed)

sudo /etc/rc.d/rc.ip_forward start # i.e., echo 1 > /proc/sys/net/ipv4/ip_forward
sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE


Now, although my phone's OS isn't Android I think (which is the system that that guide assumes), the fact the IP address mentioned in it is the same that Ubuntu automatically assigns to the phone suggests that this might be close to what should be done. But it doesn't work (although in route output on Slackware there appeared a line identical to the line in Ubuntu's output from my previous post, only with metric = 0 instead of 1). Still, I'm posting it hoping that maybe it's missing something obvious, which somebody will point out.

(In fact, I made two changes; I replaced the penultimate line with
Quote:

sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
, for a good measure, and the ultimate line with
Quote:

sudo iptables -t nat -A POSTROUTING -j MASQUERADE -o wlan0
sudo iptables -A FORWARD -j ACCEPT -i usb0
, a similar code that I found here on LQ, because the original broke my PC's Internet connection.

klglhqcw 10-04-2013 02:29 AM

Sorry for bumps.

Solved. :)

It appears, naturally, that you were right about DHCP being involved/invoked, corp769 - sorry for that.

I read Ubuntu logs and used ps to look for programs that its network manager runs in the background, and included them in my script. Here it is:

Code:

sudo /etc/rc.d/rc.ip_forward start

sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0

sudo iptables -t filter -F
sudo iptables -t filter -X
sudo iptables -t nat -F
sudo iptables -t nat -X

sudo iptables --table filter --insert INPUT --in-interface usb0 --protocol tcp --destination-port 53 --jump ACCEPT
sudo iptables --table filter --insert INPUT --in-interface usb0 --protocol udp --destination-port 53 --jump ACCEPT
sudo iptables --table filter --insert INPUT --in-interface usb0 --protocol tcp --destination-port 67 --jump ACCEPT
sudo iptables --table filter --insert INPUT --in-interface usb0 --protocol udp --destination-port 67 --jump ACCEPT
sudo iptables --table filter --insert FORWARD --in-interface usb0 --jump REJECT
sudo iptables --table filter --insert FORWARD --out-interface usb0 --jump REJECT
sudo iptables --table filter --insert FORWARD --in-interface usb0 --out-interface usb0 --jump ACCEPT
sudo iptables --table filter --insert FORWARD --source 10.42.0.0/255.255.255.0 --in-interface usb0 --jump ACCEPT
sudo iptables --table filter --insert FORWARD --destination 10.42.0.0/255.255.255.0 --out-interface usb0 --match state --state ESTABLISHED,RELATED --jump ACCEPT
sudo iptables --table nat --insert POSTROUTING --source 10.42.0.0/255.255.255.0 ! --destination 10.42.0.0/255.255.255.0 --jump MASQUERADE

sudo dnsmasq --conf-file --no-hosts --bind-interfaces --except-interface=lo --clear-on-reload --strict-order --listen-address=10.42.0.1 --dhcp-range=10.42.0.10,10.42.0.100,60m --dhcp-option=option:router,10.42.0.1 --dhcp-lease-max=50 --pid-file=/var/run/nm-dnsmasq-usb0.pid

(Only dnsmasq was originally run with --keep-in-foreground).

There surely are problems with that script, but I'll manage that now.

corp769 10-04-2013 12:20 PM

It's all good! And cheers figuring it out!

Josh


All times are GMT -5. The time now is 11:41 PM.