LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Resolve hostname from IP (https://www.linuxquestions.org/questions/linux-networking-3/resolve-hostname-from-ip-590735/)

cornish 10-10-2007 04:24 AM

Resolve hostname from IP
 
Simple questions can I resolve a hostname from an IP address

When I work with windows at work I can ping -a to resolve a hostname but I would like to do this with linux?

bathory 10-10-2007 04:33 AM

You can use nslookup (deprecated) or dig:
Code:

nslookup xx.xx.xx.xx
dig -x xx.xx.xx.xx


cornish 10-10-2007 04:34 AM

Cheers mate I will try that later

cornish 10-10-2007 05:07 AM

I tired both of those options but neither of them work

bathory 10-10-2007 05:12 AM

Please define "neither of them work". Did the commands ran, or they do not exist? You can also try
Code:

host xx.xx.xx.xx

cornish 10-10-2007 05:15 AM

Yes they both ran but neither displayed the hostname afterwards

host didnt work either

bathory 10-10-2007 05:36 AM

You should get an answer like this:
Code:

dig -x 209.85.135.147

; <<>> DiG 9.2.2 <<>> -x 209.85.135.147
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49976
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 0

;; QUESTION SECTION:
;147.135.85.209.in-addr.arpa.  IN      PTR

;; ANSWER SECTION:
147.135.85.209.in-addr.arpa. 86165 IN  PTR    mu-in-f147.google.com.

;; AUTHORITY SECTION:
135.85.209.in-addr.arpa. 86165  IN      NS      ns1.google.com.
135.85.209.in-addr.arpa. 86165  IN      NS      ns4.google.com.
135.85.209.in-addr.arpa. 86165  IN      NS      ns3.google.com.
135.85.209.in-addr.arpa. 86165  IN      NS      ns2.google.com.

;; Query time: 2 msec
;; SERVER: 193.0.0.195#53(193.0.0.195)
;; WHEN: Wed Oct 10 13:29:15 2007
;; MSG SIZE  rcvd: 152

host 209.85.135.147
147.135.85.209.in-addr.arpa domain name pointer mu-in-f147.google.com.


cornish 10-10-2007 05:44 AM

I get this

Quote:

mark@nb10001L:/etc$ dig -x 10.179.108.11

; <<>> DiG 9.3.4 <<>> -x 10.179.108.11
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 55919
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;11.108.179.10.in-addr.arpa. IN PTR

;; AUTHORITY SECTION:
10.in-addr.arpa. 600 IN SOA prisoner.iana.org. hostmaster.root-servers.org. 2002040800 1800 900 604800 604800

;; Query time: 44 msec
;; SERVER: 10.179.104.46#53(10.179.104.46)
;; WHEN: Wed Oct 10 11:42:09 2007
;; MSG SIZE rcvd: 121
The host should be myPC

jschiwal 10-10-2007 05:45 AM

Cornish might be wanting to do this on his lan without a nameserver running.

Maybe try "arp <ipaddress>" which will return the name and MAC address if the target is listed in the kernel arp table.

If it doesn't exist in the table, you could ping the ip first:
Code:

arp 192.168.1.103
192.168.1.103 (192.168.1.103) -- no entry
> ping -c 1 192.168.1.103
PING 192.168.1.103 (192.168.1.103) 56(84) bytes of data.
64 bytes from 192.168.1.103: icmp_seq=1 ttl=64 time=10.5 ms

--- 192.168.1.103 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 10.551/10.551/10.551/0.000 ms
> arp 192.168.1.103
Address                  HWtype  HWaddress          Flags Mask            Iface
laser                    ether  00:0E:7F:42:6C:65  C                    eth0


cornish 10-10-2007 05:52 AM

There is a DNS running on the LAN as I can ping the device via its hostname

farslayer 10-10-2007 10:21 AM

is the rDNS entry in the DNS server ? just because it can resolve a forward lookup doesn't mean they setup the reverse..

Your dig query shows 1 Question and 0 Answers.
Dig queried your internal DNS server (10.179.104.46) and your server basically responded "I don't Know"


All times are GMT -5. The time now is 04:08 PM.