hostname: Name or service not known?!

So this isn’t like a very big problem, but I just noticed when I run the commands

$ hostname -i
hostname: Name or service not known
$ hostname -d
hostname: Name or service not known

I get the error “hostname: Name or service not known”, but when I give just

$ hostname
hostname.domain

I get the get my “hostname.domain”, just wondering whats going on, I recently installed Hamachi VPN (Beta 64-Bit Version 2), but thats working fine and so is services like SSH and so, just these commands give me the not desired error, can anyone tell me whats going on. Oh also couple days back I changed the random hostname that openSuSE gave me upon installation, that went well too, no problem. I’m using openSuSE 12.1 64-Bit, if that’s of help.

Am 13.08.2012 10:46, schrieb havock07:
> $ hostname -i
> hostname: Name or service not known

What do you get when you tell it to give you more verbose output?


hostname -iv


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

When I do that , I get the following…


$ hostname -iv
gethostname()=`hostname.domain'
Resolving `hostname.domain' ...
hostname: Name or service not known

I see the gethostname function is doing ok…but something wrong with the next step? ie, Resolving… ?

PS: “hostname.domain” is a generic name I’m giving while posting in the forums. My actualy host and domain “openSUSElaptop.site” , but I guess that doesn’t make difference, so incase any one wonders, “openSUSElaptop.site” is what i get in place of “hostname.domain”

I am really not sure to what service hostname refers here (I never used
it with -i). Seems something it expects is not started on your machine?
You have to wait for someone with more insight into that.

If you have the package bind-utils installed you can fake the same
functionality with


dig +short $(hostname)


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

Well I just want to know the ip address, so I use hostname -i, it been long since I used that command, but since I was trying personal VPNs with Hamachi, I used it only to find that error I was getting, is there any other command that would do the job? “apropos ip” isn’t very helpful, not to mention my awful "grep"ing skills! Just want a command that tells me my ip. I know there are lots of non-terminal ways, but just curious.

Ah yes I hope someone tells me what’s going with that “hostname -i” command though, I’m very sure it was working well before, not sure what happened suddenly.

Am 13.08.2012 13:06, schrieb havock07:
> Just want a command
> that tells me my ip
I gave you an alternative command, did you try it?


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

Am 13.08.2012 12:27, schrieb Martin Helm:
> dig +short $(hostname)

If that also does not work for you with your VPN, you can try


/sbin/ifconfig | sed -n '/inet / { s# *inet ##; s# .*##p }'

in that case it makes sense to put it into a small script, since it is
not too easy to remember and to retype it every time.


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

This works for me.


% hostname -i
192.168.254.101 127.0.0.2

It appears to be looking up the hostname in “/etc/hosts” (and perhaps also in DNS nameservers, but it won’t find my hostname in the nameservers).

When I manually assigned a hostname via Yast, I checked the box to add a line to “/etc/hosts”. That’s how the “127.0.0.2” entry shows up. The other entry shows up because I edited “/etc/hosts” (as root) and also added that. I use “sendmail” for email, and sendmail complains if it cannot find a fully qualified hostname.


% grep nwr2 /etc/hosts
192.168.254.101 nwr2 12-345-678-abc.lightspeed.cicril.sbcglobal.net nwr2.lan
127.0.0.2       nwr2.lan nwr2

I “munged” one of those lines to hide the information about the public IP assigned by my ISP.

Just for the files, I tried that now on my business laptop where I have a vpn connection and the last command works

martinh@pyxis:~> /sbin/ifconfig | sed -n '/inet / { s# *inet ##; s# .*##p }'
Adresse:127.0.0.1
Adresse:192.168.1.220
Adresse:192.168.178.24

It shows the loopback , the ip in my own LAN and the ip in the vpn.
The “hostname -i” fails as yours and the dig command also.

Resolvolving mean to find the IP address whe the hhosname (better the QDN) is known. So it consults /etc/nsswitch.conf and /etc/host.conf to decide whether to read information in /etc/sysconfig/network or /etc/hosts. Is you hotcrrectluy mentioned in /etc/hosts?

This totally works for me, infact much better than what “hostname -i” would give, In my case,

# /sbin/ifconfig | sed -n '/inet / { s# *inet ##; s# .*##p }'
addr:192.168.1.X
addr:5.XXX.XXX.XXX
addr:127.0.0.1

The second “addr” is something to do with VPN I guess, but yeah this is not easy to remember, and also you need to be root, oh well this works, you think its good idea to alias this or run the whole thing as some script? And about the “hostname -i” , I also tried it on my other openSuSE on a VM and that gave the same error, I hope nothing of these errors are pointing to my router for a mistake?!

Yes and I do have the “dig” command, but unfortunately

dig +short $(hostname)

did not yield anything for me!

Hmmmm but you know I also tried that as mentioned above on my VM , that I’m running inside Win7, it failed. Oh and I dont have Hamachi/VPN on there. But strange, at least I’m not alone. I’m just concerned because it was something working normally and now it doesn’t. :\

Well thanks first of all of that info and I did check /etc/host file, and I do see there 127.0.0.1, what would in my case be the output for “hostname -i” I guess? So yeah I do see in that file, 127.0.0.1, but you say the command “hostname -i” refers to that? But it still doesnt give me 127.0.0.1

I remember that was the output “hostname -i” gave me long time back, when it used to work.

Am 13.08.2012 21:56, schrieb havock07:
> and also you need to be root

No - never, you run it as a normal user, not as root, if it does not
work as normal user your Linux boxes are heavily screwed up!
So run it again as your normal user.

Forget the dig and hostname in combination with the vpn connection for
the moment, both of them work for me at any time with the exception when
a vpn connection to my company is established (since I cannot influence
how that works and what features it provides I did not investigate further).

If both of them do not work for you even without the vpn connection then
I’ld guess that something in your network setup is not as it should be,
but to find out what or how to diagnose that is beyond me and maybe
worth another thread where you describe your network setup and your
network related settings on your machines.


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

Yes sorry, my mistake, you’re right you need not be root, it works fine for normal users! I just got confused because early yesterday I tried

$ ifconfig
Absolute path to 'ifconfig' is '/sbin/ifconfig', so running it may require superuser privileges (eg. root).

Since I got the error I though you need to be root, when using the command you gave me, anyway just noticed that you used absolute path name! :wink:

Am 13.08.2012 22:36, schrieb havock07
> Yes sorry, my mistake, you’re right you need not be root, it works
> fine for normal users! I just got confused because early yesterday I
> tried
That works for a bunch of commands in /sbin and /usr/sbin, as long as
you retrieve only information and do not use them to set something they
will work as normal user, you just have to call them with the absolute
path, /sbin/lspci would be another example.
Some others do not even allow information retrieval when you are not
root like “fdisk -l”.
So it is not completely self evident :wink:


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10


% /sbin/fdisk -l pmagic_2012_07_28.iso

Disk pmagic_2012_07_28.iso: 246 MB, 246415360 bytes
64 heads, 32 sectors/track, 235 cylinders, total 481280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x71088a47

                Device Boot      Start         End      Blocks   Id  System
pmagic_2012_07_28.iso1   *           0      481279      240640   17  Hidden HPFS/NTFS
 % 

Works for me.

The problem with plain “fdisk -l” is that only root can access the raw device. But anyone can use it to examine an iso image.

Am 13.08.2012 23:26, schrieb nrickert:
> % /sbin/fdisk -l pmagic_2012_07_28.iso

You know that this is cheating :wink:


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

Yes, but it was fun.