Changing domain name in linux

How to change Debian Linux domainname

The way I deal with it is like so; assuming your hostname is covfefe . First run this command:

Then edit /etc/hostname and change the value in there:

Finally check your hostname with sysctl like this:

And if the value is not covfefe , change it to covfefe like this:

sudo sysctl kernel.hostname=covfefe 

Solution 2

For setting the domain name in Debian, you can edit /etc/hostname . For a host hulefu in domain somewhere.co.uk you simply set /etc/hostname to hulefu.somewhere.co.uk . This should work for most other Linux distributions too.

Now a hostname -d should give somewhere.co.uk as an answer.

Update: You can add instead a domain alias to /etc/hosts . Following the previous example, this would be the first line of /etc/hosts : 127.0.0.1 localhost localhost.somewhere.co.uk

IMHO directly setting kernel parameters should be the last resort.

Domain Name Server with debian linux

How to Change the Hostname and FQDN on Ubuntu

How to change localhost to custom domain name in Linux | Ubuntu

How to change Debian Linux domainname? (2 Solutions!!)

How to configure a hostname and dns domain name on Linux Ubuntu Server

How to change your domain name in Debian

xpt

Updated on September 18, 2022

Comments

I have never been able to fully understand how to change Linux hostname and domainname, and now it comes back and bites me again — my Linux domainname is blank ( domainname gives (none) ) and I just cannot change it back:

$ hostname coral $ hostname -f coral $ hostname -d $ hostname -d | wc 0 0 0 $ domainname (none) $ dnsdomainname $ dnsdomainname | wc 0 0 0 $ cat /etc/hostname coral $ head -1 /etc/hosts 127.0.0.1 localhost.my.domain.org localhost $ cat /etc/resolv.conf # Fixed resolv.conf file domain my.domain.org search my.domain.org nameserver 192.168.2.102 $ time dig coral ;; ANSWER SECTION: coral. 0 IN A 192.168.2.102 real 0m0.038s user 0m0.032s sys 0m0.004s 
  1. Using alias the host name in /etc/hosts to specific the FQDN seems to be the correct answer, however, I’ve already done that see the above localhost.my.domain.org entry. I didn’t put my host name (coral) in /etc/hosts because I don’t want my host name to resolve to 127.0.0.1 but to real IP instead, which I obtained from my DNS server.
  2. I did a trace on hostname -f , but can’t figure any problem out of the log. I can put it here if anyone interested.

As a consequence, there is an extensive (network) delay to start and stop my sendmail server.

Today, the hostname -f , hostname -d & dnsdomainname are all working fine now. I didn’t do anything, except I traced again the hostname -f . I should have traced to a new file, but I didn’t. So now it is working, and I still do not know why it is working now, and why it didn’t work before. Moreover, even when everything is working, my sysctl kernel.domainname is still reporting (none) . This is so strange and convoluted.

$ uptime 21:33:36 up 2 days, 1:36, 5 users, load average: 0.22, 0.43, 0.29 $ sysctl kernel.domainname kernel.domainname = (none) 

And the above (network) delay to connecting to my sendmail server is gone too. So my conclusion is that all I was doing above was correct, but somehow it mystically take a great amount of time for my Ubuntu 17.04 to realized it.

Anyway, I’ll accept JakeGould’s answer as he has something new in how to use sysctl and kernel.hostname .
Thank you all who helped!

Источник

How to change Debian Linux domainname

I have never been able to fully understand how to change Linux hostname and domainname, and now it comes back and bites me again — my Linux domainname is blank ( domainname gives (none) ) and I just cannot change it back:

$ hostname coral $ hostname -f coral $ hostname -d $ hostname -d | wc 0 0 0 $ domainname (none) $ dnsdomainname $ dnsdomainname | wc 0 0 0 $ cat /etc/hostname coral $ head -1 /etc/hosts 127.0.0.1 localhost.my.domain.org localhost $ cat /etc/resolv.conf # Fixed resolv.conf file domain my.domain.org search my.domain.org nameserver 192.168.2.102 $ time dig coral ;; ANSWER SECTION: coral. 0 IN A 192.168.2.102 real 0m0.038s user 0m0.032s sys 0m0.004s 
  1. Using alias the host name in /etc/hosts to specific the FQDN seems to be the correct answer, however, I’ve already done that see the above localhost.my.domain.org entry. I didn’t put my host name (coral) in /etc/hosts because I don’t want my host name to resolve to 127.0.0.1 but to real IP instead, which I obtained from my DNS server.
  2. I did a trace on hostname -f , but can’t figure any problem out of the log. I can put it here if anyone interested.
Читайте также:  Linux топ дистрибутивов 2022

As a consequence, there is an extensive (network) delay to start and stop my sendmail server.

Today, the hostname -f , hostname -d & dnsdomainname are all working fine now. I didn’t do anything, except I traced again the hostname -f . I should have traced to a new file, but I didn’t. So now it is working, and I still do not know why it is working now, and why it didn’t work before. Moreover, even when everything is working, my sysctl kernel.domainname is still reporting (none) . This is so strange and convoluted.

$ uptime 21:33:36 up 2 days, 1:36, 5 users, load average: 0.22, 0.43, 0.29 $ sysctl kernel.domainname kernel.domainname = (none) 

And the above (network) delay to connecting to my sendmail server is gone too. So my conclusion is that all I was doing above was correct, but somehow it mystically take a great amount of time for my Ubuntu 17.04 to realized it.

Anyway, I’ll accept Giacomo1968’s answer as he has something new in how to use sysctl and kernel.hostname .

Источник

How to set the domain name on GNU/Linux?

I want to change my domain name. I can use the domainname command, but is there a way to make it permanent across reboots? I think it can be configured in /etc/resolv.conf but this file is generally generated and I don’t know exactly the difference between search and domain directives. And at what time exactly the information there is passed to the domainname program to set the domain name?

Do you have any ideas on that?

I’d like to be mostly compatible across distributions. So if if anyone has pointers on the different distributions flavours, I’d gladly accept them.

Every distribution does this differently. Which ones are you interested in? And did you read their documentation?

Mostly RedHat and Debian flavours. And I couldn’t find relevant information in the documentation. But perhaps I haven’t looked hard enough, I admit I don’t know exactly where in the documentation it could be (or even if it is in the docs).

That’s fair. In Red Hat’s documentation, it’s buried in an appendix. While in Debian’s it’s not buried in an appendix, but it is confusing.

@Michael This link on the debian mailing list is mostly useful, especially So to finally answer your question, you configure your FQDN wherever you want names resovled. If you want it in files on the box itself, then it goes in /etc/hosts. If you run your own name server like I do (I run dnsmasq for simplicity) then you only have to record the information in

Читайте также:  How to update git on linux

On red hat 7 and derived systems you should use hostnamectl to set up the hostname. cyberciti.biz/faq/rhel-redhat-centos-7-change-hostname-command/…

3 Answers 3

Set FQDN

I’m using Debian 7 and this is what worked for me; thanks to Fernando Ribeiro.

server # here's where you put the server's host name 

activate hostname

add domain name and address to the server

192.168.1.2 server.domain server 

VERIFY

> hostname --short server > hostname --domain domain > hostname --fqdn server.domain > hostname --ip-address 192.168.1.2 

after changing server name in /etc/hostname you might not be able to edit /etc/hosts . In this case you have to use xauth add as stated in this answer stackoverflow.com/questions/20611783/…

When you use redhat-base systems, linux uses /etc/sysconfig/network file and you should set variable HOSTNAME to FQDN , when you use FQDN , linux itself determines domain name.

But when you use debian-base systems, you should fill /etc/hostname file with FQDN :

NOTE: if you want to set domain name be sure set FQDN (Fully Qualyfied Domain Name)

When you set, hostname -d shows you the domain name .

Thank you, but I was under the impression that these files should only contain the hostname without the domain part. If I do what you suggest, hostname will return the fqdn directly (no difference between hostname and hostname -f ).

oh by the way, i forget to say you should set hostname by hand hostname web.mydomain.com after configure your files. because when you configure your file memory can’t apply changes.(if it was useful, don’t forget useful flag)

man hostname , being cited from its end to beginning

FILES /etc/hostname Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname. /etc/hosts Usually, this is where one sets the domain name by aliasing the host name to the FQDN. 
 THE FQDN The FQDN (Fully Qualified Domain Name) of the system is the name that the resolver(3) returns for the host name, such as, ursula.example.com. It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname. You cannot change the FQDN with hostname or dnsdomainname. The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using /etc/hosts, DNS, or NIS. For example, if the hostname was "ursula", one might have a line in /etc/hosts which reads 127.0.1.1 ursula.example.com ursula Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot. Therefore it depends on the configuration of the resolver (usually in /etc/host.conf) how you can change it. Usually the hosts file is parsed before DNS or NIS, so it is most common to change the FQDN in /etc/hosts. If a machine has multiple network interfaces/addresses or is used in a mobile environment, then it may either have multiple FQDNs/domain names or none at all. Therefore avoid using hostname --fqdn, hostname --domain and dnsdomainname. hostname --ip-address is subject to the same limitations so it should be avoided as well. 

I’d say it does describe the whole thing thoroughly.

Читайте также:  Настройка прокси сервера linux mint

Источник

Creating custom domain name instead of localhost in Ubuntu

In ubuntu, the local server by default is referred by the name “localhost”. However, you can also create a custom domain name for your local server instead of using localhost. This article explains the process to create your own custom domain name instead of using localhost. Here ‘hackdx.md’ is created as our domain, which can be taken as per need.

Note: This article is compiled focusing on Linux users but the process is similar for windows user with some minor changes.

Below are the steps to create your own custom domain name instead of using localhost, in Ubuntu:

    Step 1: If you are new to Linux you can install apache server and PHP as given below otherwise skip this step. Apache is used to host PHP script. If you have already installed then also skip this step.

You can check your server by typing ‘localhost’ into your browser. If you get apache ubuntu default page i.e you have successfully installed apache2 server.
Step 2:Create a folder which you want to use as root directory of your server. Here I am using /home/md/www as my root directory. You can name it anything you like, naming www is not mandatory. Creating server folder

Update hosts file

Step 4: Now copy default apache2 configuration file for your new domain name configuration as given below. You can do for as many domain as you want. This step is required so that you can see your newly created domain at hachdx.md or your own domain. You can also add in default conf but creating new file is recommended as you may mess up with original default file. This can be done with the below command:

create config file for new domain

Step 5: Now add entries to our configuration file ‘hackdx.md.conf’ as given in the figure. We are creating /home/md/www as root directory and giving hacdx.md as domain name or server name. All different domain can also be added to this file if you want to create at a different location. Like /home/md/sample etc, a corresponding entry must exist in the /etc/hosts file.

new config

Step 6:Disable the default configuration and enable our new configuration for newly created domain hackdx.md.conf.


Step 7:update apache2 config file also in case you get forbidden error. You may get this error because apache2 is not recognizing new root document location /home/md/www, by adding these lines apache know about the root location. Run this command to edit apache2.conf

update config file

Add these lines to your apache2.conf file as given in the figure.
Step 8: Finally, reload the apcahe2 service put this command in your terminal.

final result

  • Step 9: You are ready now check by typing your URL to the browser. You can test by writing a simple PHP script in www folder. Now you can put your files in www directory and enjoy using the PHP server.
  • Источник

    Оцените статью
    Adblock
    detector