I am referencing the following question because it's similar but not the same:

On my CentOS 7 system, I get a strange IP address from "hostname -i" after I change my hostname, and I am trying to figure out why this is the case.

I change the hostname with following command:

# hostnamectl set-hostname saturn
# systemctl restart systemd-hostnamed

My /etc/hosts file shows:   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

The following is in my /etc/nsswistch.conf file:

hosts:      files dns myhostname

My server IP address is, but "hostname -i" returns strange a IP address:

# hostname -i

However, "hostname -I" is fine:

# hostname -I

Why does hostname -i return Is it a random dynamic IP assigned to my system by the DNS? Can someone explain? Thanks!


1 Answer 1


Unlike the hostname -I command, which just lists all configured IP addresses on all network interfaces, the hostname -i command performs name resolution (see the hostname man page).

Since your newly assigned hostname cannot be resolved using the /etc/hosts file, running hostname -i will cause your system's name resolver to generate a DNS query to an external DNS server. At this server (which I presume belongs to your ISP), this query comes up empty (NXDOMAIN result: i.e. non-existent domain). Because your ISP has partnered up with Barefruit, rather than receiving the NXDOMAIN result, you receive a Barefruit IP address in response to your query:

$ dig +short -x

I imagine that adding your new hostname to your /etc/hosts file will make the weird Barefruit IP address disappear when you run the hostname -i command. If not, you may disregard this answer : )

Just for the fun of it: using the dig command, you can interrogate different name servers. To see the difference in response, you could run the following two commands:

$ dig saturn
$ dig @ saturn

The first causes name resolution via your system's preconfigured DNS server, and likely results in a Barefruit IP address being returned. The second command asks Google Public DNS to resolve the name, and returns with an NXDOMAIN status. Or not?

If so, your ISP may be involved in the dubious practice of DNS hijacking, and you may want to figure out if there is an opt-out possibility, or change your DNS service provider.

  • thanks for the explanation. I tried everything you suggested and and the results are as you said. I accepted your answer. One quick question. How do edit the /etc/hosts file so that the barefruit IP address disappears? How should I add "saturn" into the /etc/hosts? Should it be on a new line, different from the localhost? What's the rule of thumb for editing the /etc/hosts file?
    – s2000coder
    Commented Jan 10, 2019 at 19:47
  • @s2000coder Indeed, that is what you could do. E.g. enter a new line reading something like saturn (assuming you have a static local IP address). Otherwise, you could just add 'saturn' to the lines already listed in your hosts file starting with and ::1. See man hosts for the rules of thumb.
    – ozzy
    Commented Jan 10, 2019 at 20:49

You must log in to answer this question.

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