Set hostname in Linux

When I built this PC with latest fedora I didn't give it a hostname so it named itself as something link localhost.localdomain

Now I changed the hostname to xxx2222.development. I have turned off firewall and SELinux. Have also rebooted

I can ping the box's IP (and I can snmp query it from windows) - but I cannot ping the computer by name from windows. I have tried xxx2222 and xxx2222.development

hostname correctly returns "xxx2222.development" and uname returns "Linux"

I don't really understand linux very well so apologies !!

LVL 8
plqAsked:
Who is Participating?
 
canaliCommented:
The solution to edit c:\windows\system32\drivers\etc\hosts  and add
1.2.3.4     xxx2222.development xxx2222 mylininuxbox whateveryouwant
after this modification yuo are able to ping al the name in the hosts line...

If you want your linux act as a windows box, you should install samba (nmbd damon is incaricate to broadcast NetBios name as windows do )

I think your cisco 501 acting as DNS proxy not as DNS server, (windows machine aren't in DNS server but in netbios cache ah resolution is via netbios).
 
I'm curious try this command: nslookup name_of_windowsbox
Unable to resolve? If I'm right you receive a message "Non-existent domain" (netbios over tcpip is enabled )
 so explain because  gethostbyaddr give you an error (linux box name is not in NetBios name cache,dns,hosts,wins )

If NetBIOS over TCP/IP is enabled, Windows by default attempts to resolve host names using NetBIOS methods when standard methods fail. NetBIOS name resolution methods include the NetBIOS name cache, configured WINS servers, NetBIOS broadcasts, and the Lmhosts file. For more information about NetBIOS over TCP/IP name resolution.

You can find how windows resolve name following this link:
http://www.microsoft.com/technet/itsolutions/network/evaluate/technol/tcpipfund/tcpipfund_ch07.mspx
extract from link above:
When an application uses Windows Sockets and either the application or a user specifies a host name, TCP/IP for Windows XP and Windows Server 2003 attempts to resolve the name in the following order when NetBIOS over TCP/IP is enabled:
1. Windows checks whether the host name is the same as the local host name.
2. If the host name and local host name are not the same, Windows searches the DNS client resolver cache.
3. If the host name cannot be resolved using the DNS client resolver cache, Windows sends DNS Name Query Request messages to its configured DNS servers.
4. If the host name cannot be resolved using the configured DNS servers, Windows converts the host name to a NetBIOS name and checks its local NetBIOS name cache.
5. If Windows cannot find the NetBIOS name in the NetBIOS name cache, Windows contacts its configured WINS servers.
6. If Windows cannot resolve the NetBIOS name by querying its configured WINS servers, Windows broadcasts as many as three NetBIOS Name Query Request messages on the directly attached subnet.
7. If there is no reply to the NetBIOS Name Query Request messages, Windows searches the local Lmhosts file.
 


 
0
 
plqAuthor Commented:
Also, the box refuses to return a hostname using the winsock / C++ function gethostbyaddr

Is this normal for linux ?
0
 
kfullartonCommented:
Does the hostname of the fedora box reside in DNS or in the hosts file of your Windows box?  If not, you will not be able to ping it by name.  If you want to add it to the local hosts file, it is located at c:\windows\system32\drivers\etc\hosts.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
plqAuthor Commented:
DNS is provided by a cisco 501 firewall, with a 32 port unmanaged switch inside it.

I just need to understand - do Linux/Unix machines actually publish their own hostname to the LAN in the same way that Windows machines do ?

It would be great if I can pull the hostname (computername) from winsock using the ip in the same way you can with windows computers

thanks
0
 
bstrauss3Commented:
Pinging by hostname requires a DNS server that knows about your box.  That isn't something you have in place, so it doesn't work.

The hostname command looks locally (on the Linux box) first so the absence of DNS doesn't matter.

-----Burton
0
 
bstrauss3Commented:
This is fedora, right?

Add this line:

DHCP_HOSTNAME=whatever....

to /etc/sysconfig/network-scripts/ifcfg-eth0

That will add the desired hostname to the dhcp request.  If the 501 is doing DHCP too, it should then respond to DNS queries...  If something else is handling DHCP or you have static addressing, you will have to edit the hosts file on windows (c:\windows\system32\drivers\etc\hosts  IIIRC).

-----Burton

0
 
kfullartonCommented:
>I just need to understand - do Linux/Unix machines actually publish their own hostname to the LAN in the same way that Windows machines do ?

Windows machines are capable of registering their names with a DNS server.  The server needs to be configured for dynamic updates for this to work.  Linux is also capable, here's a link as I'm not that familiar with it on Linux:

http://www.linuxhomenetworking.com/linux-hn/dns-dynamic.htm
0
 
bstrauss3Commented:
"Publish" smells a lot like AD.

It's more correct to say as kfullarton indicates that dynamic updates are allowed.

Part of the DHCP request is a (optional) hostname which can be fully qualified or just the last qualifier.

"Hey I'm Bob, give me an address"
vs.
"Hey I'm Bob.Somewhere.Local, give me an address"

Assuming the DHCP server is configured to do so, this dynamic mapping of name <-> address is entered into the tables.  That way, a subsequent DNS request for 'Bob' should return the dhcp assigned address.  But it doesn't HAVE to be that way.

Under windows it 'just works' because the default active directory DHCP service is integrated with the DNS service.

-----Burton
0
 
plqAuthor Commented:
Let me give you a bit of background.

The purpose/basis of this question is network discovery. Broadly meaning that I cant change each linux box in advance, as that would involve knowing its there already - which defeats the object. My network discovery software allows ping scans and/or netbios tree walks (WNetOpenEnum. WNetOpenResource). Netbios gives you the name first, then you can lookup the ip using gethostbyname. I can optionally get further info using snmp if required. IP scans use gethostbyaddr to get the name of a windows box.

Now I can certainly use snmp to pull the hostname of the linux box, but snmp is often turned off these days. The hostname really is key because its generally unique to the box and the admin guys using the software know a box by its hostname better than they'd know its ip address.


My network discovery program is written to run on windows only but I'm hoping it call pull the hostname from linux boxes

So in a nutshell what I'm wanting is an API way of pulling hostname without making any changes to the linux box.

--------------------------------------

I appreciate all the contributions so far. I've upped the points to 500 so I can split points. Now back to the detail.

canali's comment above hits the nail on the head... And effectively I think it says that my need for " an API way of pulling hostname without making any changes to the linux box " is not possible.

I have both domain and non domain environments, and the cisco 501 is the dhcp server, Actually the domain server dns is a bit screwy at the moment, so when some winxp clients long in they get stuck for a few minutes - thats another issue. So I currently have the linux box and the windows test boxes outside of the domain.

So before we close this off - can anyone please comment if you believe there is a way of pulling hostname from linux using some api call ?

thanks
0
 
bstrauss3Commented:
Sure ... I do it all the time... use hostname.

There is both the shell script function you have found AND/OR a glibc function, gethostname().

-----Burton

0
 
plqAuthor Commented:
Sorry, the discovery process is running on a windows box - not on the linux box. Given an IP I am hoping to discover the linux box hostname through api calls from the windows box ????
0
 
bstrauss3Commented:
So you are running on windows and want to ask the Linux box for it's host name?

That, me bucko, is what DNS does.

If the DHCP server supports dynamic DNS updating, and the hierarchy is setup right, then a nslookup type query will return the hostname:

C:\Documents and Settings\Burton>nslookup tigger
Server:  vroo.vm.burtonstrauss.local
Address:  192.168.xxx.1

Name:    tigger.burtonstrauss.local
Address:  192.168.xxx.xxx

-----Burton
0
 
plqAuthor Commented:
Some good news. I asked a customer with a few hundred ux boxes to try discovering them and it worked fine with gethostbyaddr because they were obviously in the DNS already. So my piddly network with a dysfunctional nt dns server was the main part of the probelm

But they did tell me that UX machines get added to dns manually

Time to split points.

Thanks for all your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.