-1

I am working with a Raspberry Pi model B. I have connected a 3G dongle (Huawei E3276) directly to the RPi with sakis3g. It works flawlessly. Now i want to connect to the RPi from my laptop running windows 7. The laptop is connected to a different Network, so i guess i need to connect to the RPi's public IP. In my 3G dongle i have a SIM card with a static public IP. How can i connect to the RPi?

The laptop is connected to one network through wifi and the RPi is connected to the internet through the 3G dongle. There is no physical connection between the RPi and the laptop.

It's important to notice that I want to do it without a router, so forwarding from a router ain't an option.

I have searched the web and found a solution where I should use Weaved.com to create a connection, but unfortunately that didn't work.

Any ideas how i can establish a SSH connection to the RPi through the 3G dongle?

  • How are you connecting your PI with your laptop? Wifi or Ethernet cable? – Havnar Aug 18 '15 at 10:12
  • Also: what do you mean with "connect"? SSH into it? Or another protocol HTTP/FTP/SMB/... ? – Havnar Aug 18 '15 at 10:20
  • I have edited my question to be more specific. but yes by connect i mean SSH into it. :) Up until now i have used SSH on a local network, but now i want to try to SSH into it, from another network. – Mattie Aug 18 '15 at 10:45
2

Should your ISP allow for ports to be used, you go about it like this:

sudo nano /etc/ssh/sshd_config

edit the port from what is probably 22 to what the ISP allows (i.e. 2222)

restart the SSH service

sudo service ssh restart

now you should be able to ssh into the machine (again if this is possible at all in your case)

a linux terminal example:

ssh -p 2222 <username>@<public-ip>

A workaround would be to attach a wifi dongle to the pi and use that to SSH into it from your local network, in case the public rout is blocked.

NOTE:

It would be wise to secure this with more then just a password since it's public and anyone could log in to this machine

More reading material on ssh and configuring it can be found here.

update you might need to comment out this line in the config file.

#ListenAddress 0.0.0.0
1

This is an extract from a guide I wrote a while back.

Connecting to your Raspberry Pi from “outside” may not be as straightforward as you’d expect.

With connecting, I mean of course using the ssh protocol, which has been the most common way to log into *nix systems for ages.

If you are using GPRS or 3G to connect your Pi to the internet, chances are that it is impossible to establish an ssh session to your Pi.

However, initiating an ssh session from the Pi itself to a computer elswhere on the internet, should in most cases not be a problem. In fact, once you have established a connection to another machine from your Pi via ssh, you can use this connection to connect back to your Pi.

This can be done by what is called reverse ssh port forwarding, a technique that at first eyesight looks very complicated and difficult to get ones head aroud.

I will now go through the steps that you need to perform to be able to log in to your Raspberry Pi from anywhere.

The first thing you need, is a Linux server. I highly recommend Amazon EC2, where you can get a server instance for free (well, almost). I do not cover the details on how to configure it, in this document.

Setting up the server

sudo vi /etc/ssh/sshd_config

Add the following line to the file:

GatewayPorts clientspecified

Then, restart the ssh daemon:

sudo vi /etc/init.d/sshd restart

The command above may give an error, because this procedure differs amongst Linux distributions. You may also try

sudo vi /etc/init.d/ssh restart

Next, you need to allow for incoming connections on TCP port 2222. In Amazon EC2, this is done by editing the security group used by your instance.

Setting up your Raspberry Pi

If you are running an Amazon EC2 Linux instance, you have a .pem-file, which was generated when you created your EC2 instance. This file contains your private key, and must be used when you log in to your EC2 instance.

Open an ssh connection to your Raspberry Pi.

Go to the /home/pi/.ssh folder. If you do not have this folder, create it.

On your host machine, copy the content of your .pem-file to the clipboard.

On your Raspberry Pi, type the following:

vi ec2.pem

Then press i, and paste the content of the clipboard into the file, by pressing CTRL+V, or right-click and Paste. Then save the file, by first pressing ESC, then :qw followed by ENTER.

Next, type the following:

chmod 400 ec2.pem

Next, we need to create the ssh config file. If not present, create it in /home/pi/.ssh folder, with the name config.

This example is assuming that you are running an Amazon EC2 instance. You will need the ip-address of your instance, to proceed. I highly recommend assigning an elastic IP address to your instance.

Into the config file, paste the following (change the ip address to that of your own Amazon EC2 instance):

host *.amazonaws.com 54.124.234.5
     user ec2-user
     StrictHostKeyChecking no
     UserKnownHostsFile /dev/null
     CheckHostIP no
     IdentityFile ~/.ssh/ec2.pem

Save the file. If everything is configured correctly, we should now be able to connect our Raspberry Pi to our server.

ssh -XfN2R 0.0.0.0:2222:localhost:22 ec2-user@54.124.234.5

The command should succeed without any error messages.

The following script is more convenient. It checks if a connection already exists, and spawn one if not. You could execute the script periodically from crontab, to ensure that the connection is always up.

#!/bin/sh
CMD="ssh -XfN2R 0.0.0.0:2222:localhost:22 ec2-user@54.124.234.5"
pgrep -f -x "$CMD" > /dev/null 2>&1 || $CMD
  • Thanks for the answer. I don't know where i got the idea from. But i was convinced that if I had a 3G dongle with a SIM card with a static public IP. It would be possible to connect to it remotely through the public IP. But that is a misunderstanding? – Mattie Aug 18 '15 at 11:03
  • You will have to ask your 3G provider if they allow it. – Werner Kvalem Vesterås Aug 18 '15 at 11:04
  • ISPs usualy close down port 22, you could try changing the default port (22) to something that is allowed by your ISP (i.e. 2222). Check with the ISP. – Havnar Aug 18 '15 at 11:08
  • So if my ISP allow it, what would i need to do then to be able to SSH into the RPi? – Mattie Aug 18 '15 at 11:11
  • If your ISP allows it you'll be able to connect to your Pi out of the box. If they close port 22, you'll just need to change the port number in /etc/ssh/sshd_config. If that doesn't work, they're probably blocking it. – EDP Aug 18 '15 at 13:12
1

Connecting to SSH on your Pi remotely will require a public IP address.

More and more ISPs use NAT for 2/3/4G connections, and therefore give you a private, non-routable IP on the client side.

The main reason for doing that is to limit the usage of Public IP spacing for the huge amount of mobile connections. There's nothing wrong with that, as it won't affect the functionality and/or usability of most - if not all - domestic users.

Many ISPs however have separate solutions for M2M (Machine 2 Machine) connectivity. These connections are routable (either via traditional public IP or via a specially assigned - but still Private - IP subnet). The latter will limit routing only within the ISP's network.

Another way of taking more money out of your pocket? Not quite. These type of subscriptions mostly are cheaper per connection compared with a normal domestic one, but mostly have to be bought in bulk.

What, if, and under which terms your ISP can give you a routable IP depends on your ISP. Some ISPs doing direct sales, others via their Business Solutions division, others only via VARs (Value Added Resellers).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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