?
Solved

Set hostname in Linux

Posted on 2006-05-11
13
Medium Priority
?
901 Views
Last Modified: 2010-08-05
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 !!

0
Comment
Question by:plq
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 8

Author Comment

by:plq
ID: 16660620
Also, the box refuses to return a hostname using the winsock / C++ function gethostbyaddr

Is this normal for linux ?
0
 
LVL 9

Expert Comment

by:kfullarton
ID: 16660765
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
 
LVL 8

Author Comment

by:plq
ID: 16660819
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 7

Expert Comment

by:bstrauss3
ID: 16661468
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
 
LVL 7

Expert Comment

by:bstrauss3
ID: 16661501
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
 
LVL 9

Assisted Solution

by:kfullarton
kfullarton earned 500 total points
ID: 16661804
>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
 
LVL 7

Assisted Solution

by:bstrauss3
bstrauss3 earned 500 total points
ID: 16662303
"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
 
LVL 14

Accepted Solution

by:
canali earned 1000 total points
ID: 16662708
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
 
LVL 8

Author Comment

by:plq
ID: 16665548
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
 
LVL 7

Expert Comment

by:bstrauss3
ID: 16666924
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
 
LVL 8

Author Comment

by:plq
ID: 16666940
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
 
LVL 7

Expert Comment

by:bstrauss3
ID: 16667017
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
 
LVL 8

Author Comment

by:plq
ID: 16669777
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question