Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Find and display a DHCP server's IP address UNIX
Have you ever needed to know the address of your DHCP server? I don't know how useful this will be to people, but it was surprisingly tough for a team of three of us to figure out, so I figured it's worth a post. Surprisingly, the address doesn't show up in the system log, ifconfig, NetInfo, or anywhere else that we thought to look (and we looked in quite a few places)!

So here's the solution,. Go to the Terminal and run this command (replace en0 with en1 if you're on AirPort):
ipconfig getpacket en0 
According to the manual page for ipconfig, this command appears to be unique to Mac OS X, first introduced in the Public Beta! The command will display a bunch of useful info, including:
  • server_identifier (ip): That's your DHCP server's IP address.
  • yiaddr: Your machine's IP address.
  • chaddr: Your machine's MAC address.
  • domain_name_server: Your domain name server(s).
There's much more in the output. Keep in mind that if you have entered an IP address manually, then you'll get no output from this command. I have tested this in both 10.4.4 and 10.3.9, and it works fine in both.
    •    
  • Currently 3.30 / 5
  You rated: 1 / 5 (10 votes cast)
 
[90,958 views]  

Find and display a DHCP server's IP address | 19 comments | Create New Account
Click here to return to the 'Find and display a DHCP server's IP address' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Find and display a DHCP server's IP address
Authored by: jsluys@mac.com on Jan 31, '06 07:30:17AM

I usually just go to my network preferences, in system preferences. The router listed should be the same as the DHCP-server. A lot easier than remembering any commands...



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: superdave98 on Jan 31, '06 07:38:51AM

Good thought, but not 100% correct. The DHCP server does not have to be the same as the router address. In a small network, i.e. at home, this will almost always be true, but in a larger network, the DHCP server is often another machine and not the router.

Dave



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: ntorda on Jan 31, '06 07:40:57AM

this is not the case... your dhcp server and router may not even be in the same subnet depending on how your network is configured.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: rameeti on Jan 31, '06 07:47:22AM

A router is a router and a server is a server. Don't confuse the two. A router *may* have a DHCP server built into it as well as a switch, but it need only be a router. And Excel is not a database regardless of how many people want to use it as one.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: Dolomite on Jan 31, '06 08:33:15AM

The DHCP server and router are not necessarily always going to be same thing.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: joebob on Jan 31, '06 08:17:20AM

You can also do something like 'ipconfig getoption en1 server_identifier', but replace en1 with your own interface (usually en0 = ethernet, en1 = airport on Macs).



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: tkw4u on Jan 31, '06 08:32:01AM

We had a need for this functionality when we started registering MAC addresses for the network.

I came up with this applescript so users can just double-click on it to get their DHCP server address. Obviously if you need to get a different interfaces DHCP server change "en0" to the interface needed.

Make sure to save it as an application:

do shell script "ipconfig getoption en0 server_identifier"
set theIP to the result
display dialog "Your DHCP server IP is: " & theIP




[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: designcoder on Jan 31, '06 01:20:07PM

Hmmm. Doesn't seem to work for me in Panther (10.3.9). I get nothing at all.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: piper on Jan 31, '06 01:53:34PM

If you get nothing when you run the command it probably means you have a static, not DHCP, IP address.

piper



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: sjk on Jan 31, '06 10:10:52PM
Yep, that's likely the reason. From the ipconfig man page:

     getpacket interface-name
                 Prints to standard output the DHCP/BOOTP packet that the
                 client accepted from the DHCP/BOOTP server.  This command is
                 useful to check what the server provided, and whether the
                 values are sensible.  This command outputs nothing if
                 DHCP/BOOTP is not active on the interface, or the attempt to
                 acquire an IP address was unsuccessful.


[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: designcoder on Feb 01, '06 10:54:43AM

Yep -- that's it. I forgot I had a static address on my at-work Mac!



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: xcgr on Feb 01, '06 05:35:58AM

We were using this at one of my former workplaces when 10.0 came out. It's worked on every Mac OS X version since then, all the way up to the present.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: macshome on Feb 01, '06 10:41:54AM

Well, it's unique to Mac OS X if you don't count Windows as an OS. ;)

---
http://www.afp548.com
Breaking my server to save yours.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: hamarkus on Feb 01, '06 03:41:35PM

Do I get in any of this the MAC address of my cable modem?



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: ian.kim on Feb 01, '06 07:51:14PM

not sure if this gets you what you need, but i use google to find out my "external" ip address when i'm behind a dhcp network.

just google "what's my ip address", and click on the first result.

that website will tell you what ip address it sees coming from you, which, if i'm not mistaken, is the ip of the dhcp server.



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: burro on Feb 01, '06 11:33:25PM

yeah in most cases this is simply router's IP. Now how about getting DNS primary and secondary addresses?



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: NeutronMonk on Feb 02, '06 04:37:19AM

When I do a google of "what's my ip", I got 3 different answers in the results, all of which don't match the wan ip in my widget...and none of them match the terminal output, go figure (small home network, cable modem, router as dhcp server)



[ Reply to This | # ]
Find and display a DHCP server's IP address
Authored by: skrawcke on Feb 26, '06 10:37:28AM

% ipconfig getpacket en0 (en1 for airport )

then look for
domain_name_server (ip_mult):



[ Reply to This | # ]
Find MAC address by IP address
Authored by: walsellers on Apr 04, '07 03:49:19PM

I had to hunt down a machine running DHCP today. I used the IPCONFIG tip to find the IP. Then, I used the "arp -a" command to get the MAC address. I matched it to the hardware by the sticker on the machine.

I think if the "arp -a" command didn't show the IP-MAC pairing, you could get it back into the list by pinging the IP address, then using arp to get the MAC address.

I'm pretty sure that this requires the other computer to be on the same subnet. Otherwise, arp might return the MAC of the gateway or router.



[ Reply to This | # ]