LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SSH from outside my network. (https://www.linuxquestions.org/questions/linux-newbie-8/ssh-from-outside-my-network-4175472149/)

Firerat 08-05-2013 03:47 PM

with the VPN you probably need to get your server to push routing information to client


Also is the VPN server running on your target, or somewhere else on your local network?

If 'somewhere else' you may need a tap bridge instead of a tunnel, or iptable rules

You could run into problems if you use a common IP address like 192.168.0.x
best to mix it up a little, e.g 192.168.219.x so your client doesn't endup talking to something local to it instead of your VPN

ilesterg 08-06-2013 08:09 AM

Not sure if you've already done this, but have you already tried pinging the other box?

Also, what verifications have you made to check that the port on the other box is visible from the local box?

NotAComputerGuy 08-12-2013 02:43 AM

Bit a of a delay with this, as it's "that time of the year" (interpret that as you like).

The VPN server is hosted through my employer so that I can work from home.

I've got two computers with SSH server running on them. I can log into both. I've changed my network to 192.168.168.xxx to ensure that it's less common. I've tried pointing my router at either computer for SSH, and neither respond from outside my network if the VPN client is connected. As soon as I disconnect the VPN, then I can connect from outside the network.

I believe (please remember I am not a computer person, just a regular guy who is a complete newbie with computers) that this, along with my router log, demonstrates my router port forwarding is working fine.

I need to be able to connect to my local network's public IP -> SSH, I'm sure if I talked really nicely to my work they would forward SSH traffic, but depending on which site I'm working for depends on which address I connect to for the VPN and therefore the public IP of that VPN would change too.

Firerat 08-12-2013 05:23 AM

Let me see I have this right..
  • Your router is setup as an OpenVPN Client to WorkOpenVPNServer
  • You are 'out and about' and want to ssh to a machine on your HomeNetwork
  • Your router is forwarding PublicIP:22 to 192.168.168.184:22
  • it fails

I think this is because your router is sending all traffic through the VPN

BUT lots of guessing going on there, I am probably way off.

please detail where the VPN Client is on your network

NotAComputerGuy 08-12-2013 05:28 AM

Very nearly.

My Broadband connection comes via my router into which all devices are plugged into.
I have one main 'server' (a grand word for a very old computer left on all the time), which runs as a SSH server and an OpenVPN client into my work.

I want to take my laptop out and about and SSH into my 'server'. I connect into my public IP/Router which forwards on the connection into my 'server'.

If OpenVPN isn't running, it works fine. If OpenVPN is running, it fails.

Firerat 08-12-2013 06:47 AM

hmm,
try adding this to your OpenVPN client.conf


Code:

route 192.168.168.1 255.255.255.255 net_gateway

wait, that will probably kill the VPN

OK, back to your sshd config

Code:

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
ListenAddress 192.168.168.184

restart sshd
Code:

sudo service ssh restart
cross fingers

NotAComputerGuy 08-12-2013 10:58 AM

I'll try this when I get home.

Thanks :)

Firerat 08-12-2013 11:33 AM

Quote:

Originally Posted by NotAComputerGuy (Post 5007863)
I'll try this when I get home.

Thanks :)

if that doesn’t work, then I'm sure something can be done with iptables PREROUTING

NotAComputerGuy 08-12-2013 02:19 PM

Quote:

Originally Posted by Firerat (Post 5007883)
if that doesn’t work, then I'm sure something can be done with iptables PREROUTING

It didn't work. :(

I'll have a look at Prerouting but I'm fairly sure it will make as much sense to me as iptables man page does.

Firerat 08-12-2013 02:40 PM

actually, preroute looks overkill

found this
http://serverfault.com/questions/425...nternal-server

which looks a perfect fit for you.

NotAComputerGuy 08-12-2013 02:53 PM

Goodness that does look pretty good!

In my journeys of searching trying to resolve this, I have changed the port to 443 (in case my ISP was blocking certain ports), which (I read) serves a two fold effect. 1) It will get round any public firewalls that try to restrict outgoing ports. 2) More importantly: It may assist in preventing anyone from trying to hack/crack/break into my SSH server as when they port scan me it doesn't look like an SSH server.

Would that interfere with my setup at all, as it's a machine with no monitor plugged in, so it's doubtfully any web browsing will occur on it.

Please feel free to re-educate me if either of these two 'facts' are not facts at all, as computers and their security are hardly my forté, but they certainly sound plausible.

NotAComputerGuy 08-13-2013 07:16 AM

Quote:

Originally Posted by Firerat (Post 5008009)
actually, preroute looks overkill

found this
http://serverfault.com/questions/425...nternal-server

which looks a perfect fit for you.

This has solved my problem. Unfortunately, it states that it's not permanent. Which bits will reset to default after a reboot and which bits won't? It states the tables will, but they all seem to mention table in. :(
Also, what's the best method of making it permanent in Debian? I've read about a few methods for making IP tables for example.

Thanks

Firerat 08-13-2013 08:04 AM

you need to execute those commands once your VPN is up,
( ok not all of them, e.g. you no longer need
echo "201 novpn" >> /etc/iproute2/rt_tables
)
so I would look at how you are starting VPN, and if it will run post scripts for you

if you are starting via init.d service you could add to that
You could also have it 'undo' when the vpn is stopped ( via init.d )

NotAComputerGuy 08-13-2013 08:12 AM

Thanks. The VPN starts through /etc/init.d/openvpn which runs at boot so it connects automatically for me. I had a look at that file and there doesn't seem to be anything obvious as to where to put extra commands. In fact, it looks horrifyingly complicated. None of the comments mention anything like "Run X once started" or words to that effect.

I have the commands I entered listed below a file with #!/bin/sh at the top. I have that saved in /etc/openvpn/ and it's executable.

Firerat 08-13-2013 08:54 AM

ok,
I'm on Debian jessie/sid
which is not a million miles away from Mint Debian.

This is a little crude,
using sed to add two functions
one to 'fix ssh' and the other to 'undo the fix'

to get it to write, add -i

Code:

sed -e '/start_vpn ()/ i fix_ssh () {\
ip rule add fwmark 65 table novpn\
ip route add default via YOUR.GATEWAY.IP.HERE dev eth0 table novpn\
ip route flush cache\
iptables -t mangle -A OUTPUT -p tcp --sport 22 -j MARK --set-mark 65\
iptables -A INPUT -i tun0 -p tcp -m tcp --dport 22 -j DROP\
}\
undo_fix_ssh () {\
iptables -D INPUT -i tun0 -p tcp -m tcp --dport 22 -j DROP\
iptables -t mangle -D OUTPUT -p tcp --sport 22 -j MARK --set-mark 65\
ip route del default via YOUR.GATEWAY.IP.HERE dev eth0 table novpn\
ip rule del fwmark 65 table novpn\
ip route flush cache\
}'\
  -e 's/start_vpn$/& \&\& fix_ssh/' \
  -e 's/stop_vpn$/& \&\& undo_fix_ssh/' \
/etc/init.d/openvpn

if you have it as a script some place 'safe' you can use it to 'patch' again if mint updates /etc/init.d/openvpn

I should point out, untested.


All times are GMT -5. The time now is 06:49 AM.