1

I'm running a server that is using a VPN with port forwarding. The IP is only accessible to the outside internet through the port '12345'. So when I want to connect to the server I have to access it by '111.111.111.111:12345' or 'example.com:12345'.

I'm wondering if I can set up either a URL Forwarding (Redirect) or a DNS Type record where I can put a domain as 'ssh.example.com' so I can use that to ssh into the server.

I would want to run the command:

ssh [email protected]

4 Answers 4

2

You could use an SSH config file in ~/.ssh/config to set this up:

Host ssh.example.com
    Hostname 111.111.111.111
    Port 12345

With that, you should be able to use ssh [email protected] to connect with your server.

You could even add more SSH options, such as the User so you would not need to type that anymore.

If you really wanted to do this with DNS, you could add this line to your /etc/hosts file:

111.111.111.111 ssh.example.com

Your SSH command would then be ssh -p 12345 [email protected]

2

Simple answer is "no". At least not for every client. SSH has no forwarding mechanism like HTTP has. DNS domain names use an A or AAAA record which have an IP but no port number. The ssh client just expects port 22.

DNS does have SRV records which were designed for this type of purpose and contain a port number as well, but a lot of clients simply don't check for them.

At some point in the future all SSH clients might actually check for and use an SRV record but as I write this I believe OpenSSH on Linux and Putty on Windows do not. There are obscure reports that OSX/MacOS might support this but I couldn't confirm (https://serverfault.com/q/1004793/94158).

Short version though is that if you are not connecting to port 22 then you must explicitly provide the port when you connect.

You can configure your ssh client to do this automatically via ssh config as other answers suggest.

0

No, but you as a workaround we may use a DNS SRV record where specify the SSH port. Unfortunately this is not supported by any SSH client but some workarounds exists: https://serverfault.com/questions/960733/dns-record-for-ssh-docker

0

(This is an old question but Serverfault put it back on the front page today / answers here don't seem to address the question).

I'm wondering if I can set up either a URL Forwarding (Redirect) or a DNS Type record where I can put a domain as 'ssh.example.com' so I can use that to ssh into the server.

Leaving aside that you are trying to describe what you want to achieve in terms of a mechanism for achieving it (which does not exist)....

You seem to be trying to use "example.com" as a gateway device to access a different machine, "ssh.example.com". That you are talking about specific ports implies that "example.com" cannot act as an IP router. If so, then simply proxying example.com:12345 to ssh.example.com:22 would solve the connectivity part of the question, however this only works for a single address/port sitting behind example.com.

There are various proxy protocols designed for accommodating such multiplexing including SOCKs and HTTP. These need an appropriate server deployed on example.com and listening on port 12345. But (in the absence of any context to guide a choice of implementation) I would use an ssh server and relay the ssh connection (this also allows for port forwarding and other tricks) e.g. add this in ssh_config and you can ssh [email protected]

Host example.com
   Port 12345
   User jumpuser

Host ssh.example.com
   ProxyCommand ssh -q -W %h:%p example.com

OTOH if there is an HTTP proxy on example.com....

Host ssh.example.com
    ProxyCommand corkscrew example.com 12345 %h %p

DNS does not provide any mechanism for solving the routing/proxying/tunnelling issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .