Ask / Submit

Network sharing from PC to Phone [Answered]

asked 2014-10-15 13:27:31 +0200

Luca gravatar image

updated 2014-10-23 10:45:18 +0200

Hi all, at the moment I have Sailfish OS on my Nexus 4 (I think I'll buy a Jolla later). I usually connect the phone with usb cable to the PC (Slackware Linux) and use the PC internet connection to allow the phone going to internet.

This is what I do after connecting the phone (USB cable):

(To the PC)


ifconfig usb0

sh /etc/rc.d/rc.ip_forward start

iptables -t nat -A POSTROUTING -o eth0 -s -j MASQUERADE

(to the phone after connecting via ssh)


route add default gw

echo "nameserver" > /etc/resolv.conf

This way my phone has an internet connection without connecting to mobile network.

The problem is that some app doesn't go to internet without mobile connection. For example browser works fine and I can access website using PC connection while mail client app always require me to connect to mobile network even if already connected via usb.

What so you think about? Is there a possible solution?


edit retag flag offensive close delete


There is a How To here on TJC to get the internet connection of your Pc through the USB cable but I am not sure if you will suffer the problem thst you are only able to use the internet partly...

Alex ( 2014-10-15 15:07:49 +0200 )edit

What is your /etc/rc.d/rc.ip_forward?

Sebix ( 2016-08-04 22:01:08 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-10-16 09:54:04 +0200

rainisto gravatar image

updated 2015-05-28 12:09:32 +0200

Edit on latest 1.1.6+ images there has been changes in connman so you dont need to hack connmanctl anymore, just use normal route commands.

Unfortunately some applications check with connman about the network status. So you need to connect your phone to for example non-working open wlan accesspoint, and just use usb connection as default route.

Following is only for advanced users. Don't blame me if you mess up your networking. Remember to take backups of your connman config so you can recover back to normal.

More complicated answer if you really want to do it. Is first remove blacklisted usb and rndis interfaces from /etc/connman/main.conf (and append gadget to PreferredTechnologies line if you want)

And after reboot install connman-tools package, and use "connmanctl services" to get list of your usb gadget line and then use

/usr/lib/connman/tools/connmanctl config gadget_[identifierFromServicescommand]_usb --ipv4 manual --nameservers
/usr/lib/connman/tools/connmanctl connect gadget_[identifierFromServicescommand]_usb

After that connmanctl state should be "ready" and email client should not be asking network connect queries anymore.

Here is example script that I use on my phone (start with " start" vs " stop"):

#### in /etc/networking/interfaces-file I have the following lines in Linux PC:
#allow-hotplug usb0
#auto usb0
#iface usb0 inet static
#        address
#        netmask
#        up iptables -A POSTROUTING -t nat -s -j MASQUERADE
#        up echo 1 > /proc/sys/net/ipv4/ip_forward
#        down iptables -D POSTROUTING -t nat -s -j MASQUERADE
#        down echo 0 > /proc/sys/net/ipv4/ip_forward

if [ -f /usr/lib/connman/tools/connmanctl ]; then
  echo "please install connman-tools first"
  exit 1
check=`grep usb /etc/connman/main.conf`
if [ "$check" == "" ]; then
  echo /etc/connman/main.conf seems ok.
  echo please fix /etc/connman/main.conf by for example running following command:
  echo "# sudo sed -i 's/usb,//g' /etc/connman/main.conf" 
  echo "and reboot machine"
  exit 1

if [ "$*" == "start" ]; then
  $ctl enable gadget > /dev/null 2>&1 
  gadget=`$ctl services|grep gadget|cut -b 26-|tail -1`
  if [ "$gadget" == "" ]; then
    echo "did not find any connected gadget"
    echo "lets rock and roll. Disconnect cellular and wifi connections..."
    $ctl disable wifi > /dev/null 2>&1
    $ctl disable cellular > /dev/null 2>&1
    echo "lets try figure out pc side ip..."
    pc_ip=`netstat -a -n|grep 15:22|cut -d: -f8|tail -1`
    if [ "$pc_ip" == "" ]; then 
      echo "reverting to default"
      echo "found it: $pc_ip"
    $ctl config $gadget --ipv4 manual $pc_ip --nameservers
    $ctl connect $gadget > /dev/null 2>&1
  echo "stopping"
  $ctl enable wifi > /dev/null 2>&1
  $ctl enable cellular > /dev/null 2>&1 
edit flag offensive delete publish link more


Hi rainisto, thanks for the detailed answer. The reason why I like Jolla is the possibility to do what you'd like to do...

This evening I'll try your suggestion and give some feedback.

Luca ( 2014-10-16 16:39:58 +0200 )edit

It doesn't works. After "connect" command the ssh session freeze and I can't navigate. With "ifconfig" in the phone terminal app I see that all network interfaces go down. The only one listed is "lo".

I must unplug and plug again USB to be able to ssh to the phone.

Luca ( 2014-10-16 17:17:29 +0200 )edit

This is the error I get after "connect":

Method "Connect" with signature "" on interface "net.connman.Service" doesn't exist

Luca ( 2014-10-16 17:30:23 +0200 )edit

and you did notice that In my example I used .14 as gw and in your exaple you should use .12? Edited the answer with a sript that should automaticly dig the ssh ip from active connection.

rainisto ( 2014-10-16 17:34:32 +0200 )edit

Yes, I used .12 . I get the same problem. It seems usb0 interface in the phone go down when executed "connect" command. How do you connect to phone before executing connman commands?

Luca ( 2014-10-16 18:04:20 +0200 )edit
Login/Signup to Answer

Question tools



Asked: 2014-10-15 13:27:31 +0200

Seen: 2,191 times

Last updated: May 28 '15