# Domainname and how to deal with /etc/hosts [Solved]

## nein

Hi,

I did not set the domain name for my laptop during the installation, but yesterday I decided I did not want to see the greeting "This is myhost.(none)" at the login prompt.

I edited  /etc/dnsdomainname and wrote "valhala"  in it and added dnsdomainname to the defualt boot level.

Next time I rebooted I expected to see "This is myhost.valhala" but I still get "(none)" as domain. In my desktop box it did work but for that box I have a real domain name and not just a fake one. 

Any ideas about what is happening ?Last edited by nein on Wed Jun 16, 2004 6:34 pm; edited 2 times in total

----------

## yosi

shouldn't you have this line

domain valhala

before "nameserver" in resolv.conf?

thats what I have

----------

## nein

I don't have my laptop here. I will report later but it sounds good. I forgot about resolv.conf

----------

## smart

 *Quote:*   

> 
> 
> shouldn't you have this line
> 
> domain valhala
> ...

 

not related.

While i'd expect those scripts to use /etc/dnsdomainname actually, if i rememerb right, it used /etc/hosts.

try like this in /etc/hosts:

127.0.0.1 imin.valhalla.drinkingfromskullstill.drunk imin localhost

----------

## nein

I edited the /etc/hosts file and it did the trick . Thanks

Now the question is, do I need to change /etc/hosts manually if I get my ip address by DHCP ? Is there a way to get this file updated automatically after eth0 gets configured.

I know how  to patch /etc/hosts with a script or by editing /etc/init.d/net.eth0, but I was wondering if this has already been solved

----------

## smart

 *Quote:*   

> 
> 
> do I need to change /etc/hosts manually if I get my ip address by DHCP ?
> 
> 

 

No you don't. This is a mini-trick actually, since originially, you will often find the advice to have a line in /etc/hosts like

yourrealip yourmachinename

instead we went:

127.0.0.1 machinename localhost

which will always stay valid.

so no change should be needed ever with respect to your own machine. for all the other stuff it would go to DNS or whatever you chose in /etc/nsswitch.conf.

----------

## nein

Thank you very much. First I was surprised because that was how my /etc/hosts looked like before posting. So I thought I had to add another entry with the eth0 ip address.

Having a look at my backups I noticed the change that makes the difference:

I had:

```

127.0.0.1 localhost machinename

```

instead of

```
127.0.0.1 machinename localhost 
```

Notice the change in the order

Now I see my domain name and even openoffice starts fast even if I unplug my net cable.

----------

## powdahound

Incoming noob questions here...

I set /etc/dnsdomainname and I still get "atomic.(none)" when I boot up. How do I add dnsdomainname to startup? I don't see any script for it in /etc/init.d/

When I start up I see the line "Setting DNS domainname to powdahound.com... [ok]" but I still show up as atomic.(none)...

Thanks.  :Smile: 

----------

## nein

See my previous post. In /etc/hosts you need a line like this one:

127.0.0.1  atomic.powdahound.com   localhost

It seems that the domain name is read form /etc/hosts so you have to give the full name of your computer in that file.

----------

## powdahound

Ah ok. I had 127.0.0.1 atomic localhost

Didn't know I needed the full thing.  :Smile:  Think it'd be a little more clear...

Although now when I start up apache2 fails to start saying 

```
[Thu Jul 15 10:19:22 2004] [alert] (EAI 2)Name or service not known: mod_unique_id: unable to find IPv4 address of "atomic"

Configuration Failed
```

And my computer shows as atomic.unknown_domain... hmm

----------

## cdunham

This seems so un-Gentoo like.

What I really want to be able to do is manage machine names through dnsmasq, and do as little locally as possible, and have other things work. To wit:

- /etc/ethers contains MAC to IP mappings (works, optional)

- dnsmasq server /etc/hosts has IP to A mappings (works)

- workstations get IP address, ntp server, proxy server, host name, routes, etc. etc. through DHCP (works)

- workstations know that 'localhost' is 127.0.0.1 and login prompts, etc. all show host name or fqdn (not working)

If /etc/hosts contains

```
127.0.0.1   localhost
```

then the prompts, etc. are all wrong.

If /etc/hosts contains

```
127.0.0.1  imahost.int.example.com localhost
```

then the prompts work, but connections to local mySQL servers break because gethostbyaddr('127.0.0.1') returnd the fqdn, not localhost.

Yes, the local mySQL server config can be changed, but that's not very clean. There should be a way for gethostbyaddr to to the right thing, and everything else work also....

----------

## cdunham

Oh, and having the fqdn in /etc/hosts, the hostname in /etc/hostname, the domain in both /etc/resolv.conf AND /etc/dnsdomainname (where is is aparently ignored by everyone except dnsdomainname(1), for some reason), is both redunant and counter to the desire to centrally manage host names without having to set them in the workstations.

----------

