How to correctly set hostname and domain name?
Clash Royale CLAN TAG#URR8PPP
up vote
21
down vote
favorite
I am renting a server, running Ubuntu 16.04 at a company, let's name it company.org.
Currently, my server is configured like this:
- hostname:
server737263
- domain name:
company.org
Here's my FQDN:
user@server737263:~ $ hostname --fqdn
server737263.company.org
This is not surprising.
I am also renting a domain name, let's name it domain.org
. What I would like to do would be to rename my server as server1.domain.org
.
This means configuring my hostname as server1
and my domain name as domain.org
.
How can I do it correctly?
Indeed, the manpage for hostname
is not clear. To me at least:
HOSTNAME(1)
[...]
SET NAME
- When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses
the sethostname(2) function, while all of the three domainname,
ypdomainname and nisdomainname use setdomainname(2). Note, that this
is effective only until the next reboot. Edit /etc/hostname for
permanent change.
[...]
THE FQDN
- You cannot change the FQDN with hostname or dnsdomainname.
[...]
So it seems that editing /etc/hostname
is not enough? Because if it really changed the hostname, it would have changed the FQDN. There's also a trick I read to change the hostname with the command sysctl kernel.hostname=server1
, but nothing says whether this is the correct way or an ugly trick.
So:
What is the correct way to set the hostname?
What is the correct way to set the domain name?
ubuntu hostname domain
add a comment |Â
up vote
21
down vote
favorite
I am renting a server, running Ubuntu 16.04 at a company, let's name it company.org.
Currently, my server is configured like this:
- hostname:
server737263
- domain name:
company.org
Here's my FQDN:
user@server737263:~ $ hostname --fqdn
server737263.company.org
This is not surprising.
I am also renting a domain name, let's name it domain.org
. What I would like to do would be to rename my server as server1.domain.org
.
This means configuring my hostname as server1
and my domain name as domain.org
.
How can I do it correctly?
Indeed, the manpage for hostname
is not clear. To me at least:
HOSTNAME(1)
[...]
SET NAME
- When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses
the sethostname(2) function, while all of the three domainname,
ypdomainname and nisdomainname use setdomainname(2). Note, that this
is effective only until the next reboot. Edit /etc/hostname for
permanent change.
[...]
THE FQDN
- You cannot change the FQDN with hostname or dnsdomainname.
[...]
So it seems that editing /etc/hostname
is not enough? Because if it really changed the hostname, it would have changed the FQDN. There's also a trick I read to change the hostname with the command sysctl kernel.hostname=server1
, but nothing says whether this is the correct way or an ugly trick.
So:
What is the correct way to set the hostname?
What is the correct way to set the domain name?
ubuntu hostname domain
add a comment |Â
up vote
21
down vote
favorite
up vote
21
down vote
favorite
I am renting a server, running Ubuntu 16.04 at a company, let's name it company.org.
Currently, my server is configured like this:
- hostname:
server737263
- domain name:
company.org
Here's my FQDN:
user@server737263:~ $ hostname --fqdn
server737263.company.org
This is not surprising.
I am also renting a domain name, let's name it domain.org
. What I would like to do would be to rename my server as server1.domain.org
.
This means configuring my hostname as server1
and my domain name as domain.org
.
How can I do it correctly?
Indeed, the manpage for hostname
is not clear. To me at least:
HOSTNAME(1)
[...]
SET NAME
- When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses
the sethostname(2) function, while all of the three domainname,
ypdomainname and nisdomainname use setdomainname(2). Note, that this
is effective only until the next reboot. Edit /etc/hostname for
permanent change.
[...]
THE FQDN
- You cannot change the FQDN with hostname or dnsdomainname.
[...]
So it seems that editing /etc/hostname
is not enough? Because if it really changed the hostname, it would have changed the FQDN. There's also a trick I read to change the hostname with the command sysctl kernel.hostname=server1
, but nothing says whether this is the correct way or an ugly trick.
So:
What is the correct way to set the hostname?
What is the correct way to set the domain name?
ubuntu hostname domain
I am renting a server, running Ubuntu 16.04 at a company, let's name it company.org.
Currently, my server is configured like this:
- hostname:
server737263
- domain name:
company.org
Here's my FQDN:
user@server737263:~ $ hostname --fqdn
server737263.company.org
This is not surprising.
I am also renting a domain name, let's name it domain.org
. What I would like to do would be to rename my server as server1.domain.org
.
This means configuring my hostname as server1
and my domain name as domain.org
.
How can I do it correctly?
Indeed, the manpage for hostname
is not clear. To me at least:
HOSTNAME(1)
[...]
SET NAME
- When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses
the sethostname(2) function, while all of the three domainname,
ypdomainname and nisdomainname use setdomainname(2). Note, that this
is effective only until the next reboot. Edit /etc/hostname for
permanent change.
[...]
THE FQDN
- You cannot change the FQDN with hostname or dnsdomainname.
[...]
So it seems that editing /etc/hostname
is not enough? Because if it really changed the hostname, it would have changed the FQDN. There's also a trick I read to change the hostname with the command sysctl kernel.hostname=server1
, but nothing says whether this is the correct way or an ugly trick.
So:
What is the correct way to set the hostname?
What is the correct way to set the domain name?
ubuntu hostname domain
ubuntu hostname domain
edited Nov 12 '16 at 23:56
Jeff Schaller
35.2k952115
35.2k952115
asked Nov 12 '16 at 23:38
titsou
108114
108114
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
21
down vote
accepted
Setting your hostname:
You'll want to edit
/etc/hostname
with your new hostname.Then, run
sudo hostname $(cat /etc/hostname)
.
Setting your domain:
Then, in
/etc/resolvconf/resolv.conf.d/head
, you'll add then linedomain your.domain.name
(not your FQDN, just the domainname).Then, run
sudo resolvconf -u
to update your/etc/resolv.conf
(alternatively, just reproduce the previous change into your/etc/resolv.conf
).
Both:
Finally, update your /etc/hosts
file. There should be at least one line starting with one of your IP (loopback or not), your FQDN and your hostname. grepping out ipv6 addresses, your hosts file could look like this:
127.0.0.1 localhost
1.2.3.4 service.domain.com service
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent/etc/resolv.conf
from being rewritten.
â SYN
Jan 4 '17 at 1:04
6
Both those conf files sayDO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).
â Walf
May 1 '17 at 1:26
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting/etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.
â njbair
Jan 6 at 23:24
1
This doesn't seem to apply to 18.04 LTS - there's no such file/etc/resolvconf/resolv.conf.d/head
and there's no such utilityresolvconf
.
â inopinatus
Jun 4 at 3:42
 |Â
show 1 more comment
up vote
0
down vote
sudo nano /etc/hostname
hostname.domain.com
sudo nano /etc/hosts
127.0.0.1 hostname.domain.com hostname localhost
REBOOT!
MUST HAVE SINGLE HOSTNAME after FQDN in /etc/hosts file. Works fine on Ubuntu 18.04.1 and all other versions. On EC2 and elsewhere.
Didn't mess with resolve file or anything else.
That shows hostname in shell and then has the FQDN when you need it.
New contributor
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
21
down vote
accepted
Setting your hostname:
You'll want to edit
/etc/hostname
with your new hostname.Then, run
sudo hostname $(cat /etc/hostname)
.
Setting your domain:
Then, in
/etc/resolvconf/resolv.conf.d/head
, you'll add then linedomain your.domain.name
(not your FQDN, just the domainname).Then, run
sudo resolvconf -u
to update your/etc/resolv.conf
(alternatively, just reproduce the previous change into your/etc/resolv.conf
).
Both:
Finally, update your /etc/hosts
file. There should be at least one line starting with one of your IP (loopback or not), your FQDN and your hostname. grepping out ipv6 addresses, your hosts file could look like this:
127.0.0.1 localhost
1.2.3.4 service.domain.com service
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent/etc/resolv.conf
from being rewritten.
â SYN
Jan 4 '17 at 1:04
6
Both those conf files sayDO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).
â Walf
May 1 '17 at 1:26
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting/etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.
â njbair
Jan 6 at 23:24
1
This doesn't seem to apply to 18.04 LTS - there's no such file/etc/resolvconf/resolv.conf.d/head
and there's no such utilityresolvconf
.
â inopinatus
Jun 4 at 3:42
 |Â
show 1 more comment
up vote
21
down vote
accepted
Setting your hostname:
You'll want to edit
/etc/hostname
with your new hostname.Then, run
sudo hostname $(cat /etc/hostname)
.
Setting your domain:
Then, in
/etc/resolvconf/resolv.conf.d/head
, you'll add then linedomain your.domain.name
(not your FQDN, just the domainname).Then, run
sudo resolvconf -u
to update your/etc/resolv.conf
(alternatively, just reproduce the previous change into your/etc/resolv.conf
).
Both:
Finally, update your /etc/hosts
file. There should be at least one line starting with one of your IP (loopback or not), your FQDN and your hostname. grepping out ipv6 addresses, your hosts file could look like this:
127.0.0.1 localhost
1.2.3.4 service.domain.com service
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent/etc/resolv.conf
from being rewritten.
â SYN
Jan 4 '17 at 1:04
6
Both those conf files sayDO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).
â Walf
May 1 '17 at 1:26
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting/etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.
â njbair
Jan 6 at 23:24
1
This doesn't seem to apply to 18.04 LTS - there's no such file/etc/resolvconf/resolv.conf.d/head
and there's no such utilityresolvconf
.
â inopinatus
Jun 4 at 3:42
 |Â
show 1 more comment
up vote
21
down vote
accepted
up vote
21
down vote
accepted
Setting your hostname:
You'll want to edit
/etc/hostname
with your new hostname.Then, run
sudo hostname $(cat /etc/hostname)
.
Setting your domain:
Then, in
/etc/resolvconf/resolv.conf.d/head
, you'll add then linedomain your.domain.name
(not your FQDN, just the domainname).Then, run
sudo resolvconf -u
to update your/etc/resolv.conf
(alternatively, just reproduce the previous change into your/etc/resolv.conf
).
Both:
Finally, update your /etc/hosts
file. There should be at least one line starting with one of your IP (loopback or not), your FQDN and your hostname. grepping out ipv6 addresses, your hosts file could look like this:
127.0.0.1 localhost
1.2.3.4 service.domain.com service
Setting your hostname:
You'll want to edit
/etc/hostname
with your new hostname.Then, run
sudo hostname $(cat /etc/hostname)
.
Setting your domain:
Then, in
/etc/resolvconf/resolv.conf.d/head
, you'll add then linedomain your.domain.name
(not your FQDN, just the domainname).Then, run
sudo resolvconf -u
to update your/etc/resolv.conf
(alternatively, just reproduce the previous change into your/etc/resolv.conf
).
Both:
Finally, update your /etc/hosts
file. There should be at least one line starting with one of your IP (loopback or not), your FQDN and your hostname. grepping out ipv6 addresses, your hosts file could look like this:
127.0.0.1 localhost
1.2.3.4 service.domain.com service
edited Apr 25 at 17:11
Benjamin Moore
32
32
answered Nov 12 '16 at 23:51
SYN
1,824415
1,824415
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent/etc/resolv.conf
from being rewritten.
â SYN
Jan 4 '17 at 1:04
6
Both those conf files sayDO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).
â Walf
May 1 '17 at 1:26
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting/etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.
â njbair
Jan 6 at 23:24
1
This doesn't seem to apply to 18.04 LTS - there's no such file/etc/resolvconf/resolv.conf.d/head
and there's no such utilityresolvconf
.
â inopinatus
Jun 4 at 3:42
 |Â
show 1 more comment
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent/etc/resolv.conf
from being rewritten.
â SYN
Jan 4 '17 at 1:04
6
Both those conf files sayDO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).
â Walf
May 1 '17 at 1:26
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting/etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.
â njbair
Jan 6 at 23:24
1
This doesn't seem to apply to 18.04 LTS - there's no such file/etc/resolvconf/resolv.conf.d/head
and there's no such utilityresolvconf
.
â inopinatus
Jun 4 at 3:42
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
does this work for AWS or other VPS?
â Thufir
Jan 3 '17 at 7:52
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent
/etc/resolv.conf
from being rewritten.â SYN
Jan 4 '17 at 1:04
Running on EC2, note that you may want to set some DHCP options to your VPC, pushing the proper domain name - or disable DHCP client from your AMIs - to prevent
/etc/resolv.conf
from being rewritten.â SYN
Jan 4 '17 at 1:04
6
6
Both those conf files say
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).â Walf
May 1 '17 at 1:26
Both those conf files say
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
on my server (same version).â Walf
May 1 '17 at 1:26
4
4
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in
/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting /etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.â njbair
Jan 6 at 23:24
Don't be fooled by the fact that the "DO NOT EDIT" warning appears in
/etc/resolvconf/resolv.conf.d/head
. Everything in the head file is prepended to the resulting /etc/resolv.conf
output file, so that's why the warning is in there, so that it shows up in the final result. Threw me for a loop at first.â njbair
Jan 6 at 23:24
1
1
This doesn't seem to apply to 18.04 LTS - there's no such file
/etc/resolvconf/resolv.conf.d/head
and there's no such utility resolvconf
.â inopinatus
Jun 4 at 3:42
This doesn't seem to apply to 18.04 LTS - there's no such file
/etc/resolvconf/resolv.conf.d/head
and there's no such utility resolvconf
.â inopinatus
Jun 4 at 3:42
 |Â
show 1 more comment
up vote
0
down vote
sudo nano /etc/hostname
hostname.domain.com
sudo nano /etc/hosts
127.0.0.1 hostname.domain.com hostname localhost
REBOOT!
MUST HAVE SINGLE HOSTNAME after FQDN in /etc/hosts file. Works fine on Ubuntu 18.04.1 and all other versions. On EC2 and elsewhere.
Didn't mess with resolve file or anything else.
That shows hostname in shell and then has the FQDN when you need it.
New contributor
add a comment |Â
up vote
0
down vote
sudo nano /etc/hostname
hostname.domain.com
sudo nano /etc/hosts
127.0.0.1 hostname.domain.com hostname localhost
REBOOT!
MUST HAVE SINGLE HOSTNAME after FQDN in /etc/hosts file. Works fine on Ubuntu 18.04.1 and all other versions. On EC2 and elsewhere.
Didn't mess with resolve file or anything else.
That shows hostname in shell and then has the FQDN when you need it.
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
sudo nano /etc/hostname
hostname.domain.com
sudo nano /etc/hosts
127.0.0.1 hostname.domain.com hostname localhost
REBOOT!
MUST HAVE SINGLE HOSTNAME after FQDN in /etc/hosts file. Works fine on Ubuntu 18.04.1 and all other versions. On EC2 and elsewhere.
Didn't mess with resolve file or anything else.
That shows hostname in shell and then has the FQDN when you need it.
New contributor
sudo nano /etc/hostname
hostname.domain.com
sudo nano /etc/hosts
127.0.0.1 hostname.domain.com hostname localhost
REBOOT!
MUST HAVE SINGLE HOSTNAME after FQDN in /etc/hosts file. Works fine on Ubuntu 18.04.1 and all other versions. On EC2 and elsewhere.
Didn't mess with resolve file or anything else.
That shows hostname in shell and then has the FQDN when you need it.
New contributor
New contributor
answered 5 mins ago
Richard Westby-Nunn
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f322883%2fhow-to-correctly-set-hostname-and-domain-name%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password