20

I have this server (44.44.44.44, for instance) running a webserver. I have routed pollnote.com to the server to access my webserver. Everything works fine.

To access the server, I added my Public Key to .ssh/authorized_keys so I can do ssh root@44.44.44.44 to log in without problems.

The issue comes when I try it like this: ssh root@pollnote.com. The terminal just displays nothing, and it waits for me until I decide to abort the command.

What do I need to do to access the server using the domain name as reference?

UPDATE

I should have mentioned, I am accessing the server through CloudFlare. Maybe it is relevant..?

data

➜  ~  dig pollnote.com

; <<>> DiG 9.9.5-9ubuntu0.1-Ubuntu <<>> mydomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56675
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;pollnote.com.          IN  A

;; ANSWER SECTION:
pollnote.com.       299 IN  A   104.27.165.70
pollnote.com.       299 IN  A   104.27.164.70

;; Query time: 54 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Thu Jul 30 19:12:38 CEST 2015
;; MSG SIZE  rcvd: 73

➜  ~  ssh -vvv root@pollnote.com
OpenSSH_6.7p1 Ubuntu-5ubuntu1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to pollnote.com [104.27.165.70] port 22.

5 Answers5

31

When you connect by IP address the SSH connection goes directly to your server but if you use the domain name it goes through Cloudflare defenses. My suggestion would be to either use direct.pollnote.com (I think CloudFlare creates it automaticaly but people often remove it) or add your own alias like ssh.pollnote.com and disable CloudFlare protection on it.

dtoubelis
  • 4,797
  • 1
  • 31
  • 32
3

dtoubelis's answer definitely solves this problem.

Friendly amendment, consider using something other than ssh.yourserver.com so that potential attackers have a harder time identifying your host's IP address.

For example, secret-circus-monkey.yourserver.com.

See, e.g., A Proper Server Naming Scheme; notably the author's comment regarding attack vectors:

In the article, we mentioned that our naming scheme also allows you to prevent inadvertent information disclosure by publicly exposing only the short random hostname while resolving the functional names solely on the internal network.

Jeremy
  • 131
2

You can use something like is outlined here.

If I try to SSH to the domain, our IPs will show & that will cause issues (the same would go for something like ftp).

damoncloudflare
  • 471
  • 2
  • 5
1

I found a tricky way. I created a script using the cloudflare API, to get the real IP of my server, then i can use the IP to connect on my server. This way, all addresses on cloudflare remain proxied.

You need to have curl and jq installed (sudo apt install jq). Create your API token with permissions Zone.DNS.Read.

#!/bin/bash

connect via cloudflare API to get real IP of home server

IP=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/<YOUR_ZONE_ID>/dns_records?type=A&name=<YOUR_DOMAIN>&match=all"
-H "Authorization: Bearer <API_TOKEN_HERE>"
-H "Content-Type: application/json" | jq -r '.result[].content')

use recovered IP Address to connect on server from remote.

ssh -i ~/.ssh/<YOUR_KEY_FILE> <USER>@"$IP" -p <PORT_NUMBER>

Enjoy!

rakso
  • 103
  • 3
Toli
  • 11
1

I wanted to add this as a comment to @dtoubelis's answer but the text formatting was too restrictive so I'm adding it as an answer instead.

In my case I added the following DNS Record to the "DNS" screen in Cloudflare:

Type     Name    Value                            TTL           Status
CNAME    ssh     is an alias of mywebsite.com     Automatic     Grey

I still couldn't get it to work until I realised you then have to change your ssh login command from:

ssh user@mywebsite.com

to

ssh user@ssh.mywebsite.com.

I then added similar CNAME records for ftp and sftp so for example the ftp hostname in your ftp client changes from:

mywebsite.com

to

ftp.mywebsite.com.

I'm not sure if instead of a CNAME you can create an A record but it seems so according to Cloudflare.

Many thanks to @dtoubelis for the answer.