大网数据广告活动
服务器运维问答

Changing the hostname of a debian server using a subdomain

· 52CE 我爱测

I own a domain name mydomain.example , which I use CloudFlare for DNS. The domain is configured to point to my website hosted on GitHub. In parallel, I have a Debian VPS from OVH, and I would like associate to it a fully qualifie…

问题原文

原帖链接 · f10w · CC BY-SA 4.0

I own a domain name mydomain.example, which I use CloudFlare for DNS. The domain is configured to point to my website hosted on GitHub.

In parallel, I have a Debian VPS from OVH, and I would like associate to it a fully qualified domain name (FQDN) (instead of vps123456.ovh.net), which I would like to be subdomain.mydomain.example.

My long-term plan is to host my website (mydomain.example) on this VPS as well, but for now to avoid messing things up, I would like to keep the website unchanged.

After some research using Google, I came up with the following steps:

  1. Create an A record in CloudFlare to point subdomain.mydomain.example to the IP address 192.0.2.91 of the VPS.
  2. Change the hostname of the VPS into subdomain.mydomain.example:

    1. Change the content of /etc/hostname from vps123456.ovh.net to subdomain.mydomain.example.
    2. Change the content of /etc/hosts from

      127.0.0.1   localhost
      192.0.2.91  vps123456.ovh.net   vps123456
      

      to

      127.0.0.1   localhost
      192.0.2.91  subdomain.mydomain.example  subdomain
      
    3. Apply the change without rebooting:

      /etc/init.d/hostname.sh start
      

After this, when doing hostname I obtained subdomain.mydomain.example, which is good. But when I opened a new terminal and try ssh [email omitted], it didn't work (timeout).

Update: To clarify, my final goal is not exactly to be able to SSH to the machine using ssh [email omitted], but rather to associate the IP address of the machine with a FQDN (which is needed for some paperwork: I have to connect to some institutional server through a machine, and for security reason, the IP address of this gateway machine must be associated to a FQDN. I am trying to set my VPS up for that purpose).

已采纳解答

原帖链接 · Piotr P. Karwasz · CC BY-SA 4.0

CloudFlare might take some (short) time to distribute your new A record to its DNS servers. Moreover the old A record for subdomain.domain.example (or its previous absence) might still be in the cache of the DNS recursive resolvers you use, for the amount of time indicated by the TTL of the old record (or the last number in the SOA record if it didn't exist before). Check with dig subdomain.domain.example to see if the IP address is already correct.

However you probably need the reverse lookup for your IP address to return your domain name (check with dig -x 192.0.2.91). This is done by adding a PTR record by the IP address owner (OVH). Usually you can change your reverse lookup through some web interface.

The line you added to /etc/hosts:

192.0.2.91  subdomain.mydomain.example  subdomain

locally (on your machine) functions as three DNS records:

subdomain.mydomain.example. IN A 192.0.2.91
subdomain.                  IN A 192.0.2.91
91.2.0.191.in-addr.arpa.    IN PTR subdomain.mydomain.example.

Now you need the real PTR record.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-03-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。