Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed a Linux (Ubuntu) server inside my home LAN, initially it's automatically configured to use DHCP interface. I'm connecting to this server from another computer using that server's hostname. All OK, my router is configured to use DHCP inside my home network and gives an IPs automatically to each computer. But when I connect to this host using SSH, it warns me that I should accept a fingerprint from each newly assigned IP of the server, and it's a little annoying. So I configured it to use a static IP addressing editing the /etc/network/interfaces file like this:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0 iface eth0 inet static


All works well except that I can't connect to this server using it's hostname. When pinging I see that it's routed to the last assigned IP address that was given by DHCP dynamically, and of course Destination Host is Unreachable. I know that I can hardcode it in my /etc/hosts file, but I want to know -- why it works well with DHCP and it doesn't with static. Apparently, I don't understand something. Thanks in advance!

share|improve this question

closed as off topic by Michael Hampton, petrus, Zoredache, Ward, jscott Dec 12 '12 at 4:04

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 3 down vote accepted

Your router is probably acting as a DNS server for the local network handing out information about hosts that received an address via DHCP. Or to put it differently, when a DHCP request is handled out, the router dynamically updates the local DNS database. DNSMasq, is a common DHCP+DNS server on routers that does this.

By setting a static address, you are basically robbing your router of the information it needs to respond to DNS queries about your host.

If possible you should set a DHCP reservation in your router, not set a static address. If that isn't an option, then you simply are going to need to update your hosts files on all your machines, or run a local DNS server.

share|improve this answer
Thank you @Zoredache! I've discovered my router configs, and found manual IP reservation, that works :) – Dan K.K. Dec 11 '12 at 21:10

You can't connect to the server via the hostname because you haven't statically set any DNS servers. These servers are normally provided to clients when they obtain an address via DHCP, so as it stands you have no mechanism to resolve IP addresses to names. Your DNS server will also need to be aware of the hostname and IP address

You'll need to provide an internal DNS server in your /etc/resolv.conf file in a format similar to this

share|improve this answer
I tried to do this, added a line dns-nameservers in my interfaces file, than restart everything possible, but unfortunately nothing happened. The server is still pingable by, but not by hostname localserver :( – Dan K.K. Dec 11 '12 at 19:37
cat /etc/resolv.conf now outputs nameservers as need, but... – Dan K.K. Dec 11 '12 at 19:39
Different distro's have different networking files. Ensure you're putting the DNS servers in the correct files. – DKNUCKLES Dec 11 '12 at 19:54

This is not about DHCP but most probably about DNS. You have to have an address in /etc/resolv.conf where the hostname of your server is known so the resolution can work. I think the DHCP offer inserted something here that is missing (or different) when you are assigning the static ip.

Also, the file /etc/nsswitch.conf defines in which order your hosts file, mdns, DNS and such are tried. It's the line beginning with "hosts".

So find out how the resolution of the hostname to its IP address worked in first place (with dhcp) and continue to look on the machine that is mentioned in /etc/resolv.conf or the answering entity in /etc/nsswitch.conf.

share|improve this answer
I'm changed nothing neither the client machine, nor the gateway router, just on the server machine that is serves as a web-server for testing purposes. I tried to hardcode dns-nameservers as I mentioned earlier in comments, but it's still unreachable :( – Dan K.K. Dec 11 '12 at 19:48
As strange as it might sound, the server is not at all involved in the resolution of its address accross the network. See Zoredaches answer. Use DHCP reservation in your router and set the router as DNS server on your client or, if you want to use the static IP, update all host files. – Karma Fusebox Dec 11 '12 at 20:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.