5

My hostname is localhost, reported by hostname command, and terminal prompt root@localhost:~#.

How can i change it to mismis.com with mismis alias? and what is the proper configuration.

I confused after reading some articles on web.

My /etc/hosts:

127.0.0.1       localhost
127.0.1.1       srv345.myweb.com      srv345
178.162.231.61  janstone.mismis.com    janstone
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

2 Answers 2

9

Try running the following command in a terminal.

sudo sysctl kernel.hostname=mismis.com

/etc/hosts:

127.0.0.1       localhost
127.0.1.1       mismis.com mismis srv345.myweb.com srv345
178.162.231.61  janstone.mismis.com    janstone

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
5
  • where to put the sudo sysctl kernel.hostname=mismis.com, to run on system start-up?
    – pylover
    Dec 12, 2012 at 7:44
  • you have run this command on the terminal Dec 12, 2012 at 7:44
  • 1
    after editing the kernel.domainname and kernel.hostname in /etc/sysctl.conf and reboot , hostname changed. thanks for kernel.hostname=mismis.com
    – pylover
    Dec 12, 2012 at 7:47
  • 1
    The /etc/hosts file given above is invalid. It is not permitted to have multiple lines starting with the same IP address, in this case 127.0.0.1. If multiple such lines exist then the results are, officially speaking, undefined. More pragmatically, the existence of multiple 127.0.0.1 generally indicates misconfiguration. Domain names like 'mismis.com' and 'mismis' should not normally resolve to the loopback address; but if this is really desired for some unusual reason then these domain names should be added as aliases of 'localhost' on the one and only line beginning with 127.0.0.1.
    – jdthood
    Dec 12, 2012 at 8:08
  • @Ammar: Thanks, /etc/hosts now looks intrinsically OK. Whether it's exactly what the questioner wants, I don't know.
    – jdthood
    Dec 12, 2012 at 8:30
5

The system hostname is configured in /etc/hostname. A change made to this file will take effect after reboot.

At boot time the string in /etc/hostname is loaded into the kernel using the hostname command. If you edit /etc/hostname then you should also set the system hostname manually using the hostname command.

sudo hostname mismis

Note that in Debian and Ubuntu the system hostname is the short hostname, not a fully qualified domain name.

If the machine has a static external IP address ADRS then this address and the hostname should appear on a line in /etc/hosts, as follows.

ADRS <hostname>

If the machine has a static fully-qualified domain name then this should appear first after the IP address on the line and the short hostname should follow it.

ADRS <fully-qualified-hostname> <short-hostname>

In the present case, assuming that the external IP address is 178.162.231.61 and the desired canonical hostname is "mismis.com", the /etc/hosts line should look like the following.

178.162.231.61 mismis.com mismis

If the machine has no static external IP address, but gets assigned addresses dynamically via DHCP, for example, then 127.0.1.1 should be used instead.

127.0.1.1 mismis.com mismis

or

127.0.1.1 mismis

In /etc/hosts, any IP address should appear on at most ONE line. On that line the first domain name that follows the IP address is the canonical hostname associated with that IP address, and any subsequent domain names are aliases for the canonical hostname.

6
  • thanks but not affected. terminal prompt and hostname command stil reporting localhost. but after editing kernel.hostname that works.
    – pylover
    Dec 12, 2012 at 8:25
  • 1
    (1) Note that you have to run hostname with sudo. (2) The prompt in an open terminal window won't pick up the new hostname, whether it is set using hostname or sysctl. A newly opened terminal window will show the new hostname.
    – jdthood
    Dec 12, 2012 at 8:29
  • how can make it persistent ?
    – pylover
    Dec 12, 2012 at 9:09
  • Edit /etc/hostname.
    – jdthood
    Dec 12, 2012 at 9:19
  • 1
    The norm is to set the hostname in /etc/hostname. On your machine editing the contents of this file has no effect because you earlier followed the advice in the other answer to add a "kernel.hostname" line to /etc/sysctl.conf. Because of way in which the system is initialised, the contents of /etc/sysctl.conf override the contents of /etc/hostname.
    – jdthood
    Dec 12, 2012 at 10:32

You must log in to answer this question.

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