[comp.unix.questions] How do I find out my Ethernet address?

andy@syma.sussex.ac.uk (Andy Clews) (05/03/90)

From article <1606@dinl.mmc.UUCP>, by noren@dinl.uucp (Charles Noren):
: On a Sun 3 (SunOS 4.0.3), how do I find out what my
: Ethernet address is?  One answer is rebooting, but how
: do you find out without rebooting?  
: Is there a command executable from sh(1)?

You could try           grep `hostname` /etc/hosts

(assuming you have such a file, or similar)

-- 
Andy Clews, Computing Service, Univ. of Sussex, Brighton BN1 9QN, England
JANET: andy@syma.sussex.ac.uk   BITNET: andy%syma.sussex.ac.uk@uk.ac

randy@csseq.tamu.edu (Randy Hutson) (05/04/90)

|: On a Sun 3 (SunOS 4.0.3), how do I find out what my
|: Ethernet address is?  One answer is rebooting, but how
|: do you find out without rebooting?  
|: Is there a command executable from sh(1)?
|
|You could try           grep `hostname` /etc/hosts
|
|(assuming you have such a file, or similar)

No, that will give the Internet address.

	grep `hostname` /etc/ethers

should give the Ethernet address.  Or if yellowpages is running,

	ypcat ethers | grep `hostname`
 

jik@athena.mit.edu (Jonathan I. Kamens) (05/04/90)

In article <2561@syma.sussex.ac.uk>, andy@syma.sussex.ac.uk (Andy Clews)
writes:
|> You could try           grep `hostname` /etc/hosts
|> 
|> (assuming you have such a file, or similar)

  The original poster asked about his *Ethernet* address, not his
*Internet* address.  That means that either he's confused and meant to
ask about his Internet address, or you're confused and answered the
wrong question.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

emcguire@cadfx.ccad.uiowa.edu (Ed McGuire) (05/04/90)

From article <2561@syma.sussex.ac.uk>, by andy@syma.sussex.ac.uk (Andy Clews):
> From article <1606@dinl.mmc.UUCP>, by noren@dinl.uucp (Charles Noren):
> : On a Sun 3 (SunOS 4.0.3), how do I find out what my
> : Ethernet address is?  One answer is rebooting, but how
> : do you find out without rebooting?  
> : Is there a command executable from sh(1)?
> 
> You could try           grep `hostname` /etc/hosts

That will give you the Internet address, not the Ethernet address.
What I do know is that `arp -a' will give you the Ethernet addresses of
remote nodes.  That is, you can get the Ethernet address of system `foo'
by signing in on system `bar' and typing `ping foo;arp -a'.
---
peace.  -- Ed
"So, when `thirtysomething' was over, she turned off the TV, collected
her thoughts and called 350,000 of her closest friends."

emcguire@cadfx.ccad.uiowa.edu (Ed McGuire) (05/04/90)

From article <5197@helios.TAMU.EDU>, by randy@csseq.tamu.edu (Randy Hutson):
> 	grep `hostname` /etc/ethers
> should give the Ethernet address.

This is only somewhat reliable as /etc/ethers is maintained by the
sysadmin, and is only used for reverse ARP as far as I know.  It's
liable to be empty if you're not supporting diskless nodes.  I suspect
the same would be true if the file was YP served.
---
peace.  -- Ed
"So, when `thirtysomething' was over, she turned off the TV, collected
her thoughts and called 350,000 of her closest friends."

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (05/04/90)

In article <5197@helios.TAMU.EDU> randy@csseq.tamu.edu (Randy Hutson) writes:
: 
: |: On a Sun 3 (SunOS 4.0.3), how do I find out what my
: |: Ethernet address is?  One answer is rebooting, but how
: |: do you find out without rebooting?  
: |: Is there a command executable from sh(1)?
: |
: 
: 	grep `hostname` /etc/ethers
: 
: should give the Ethernet address.  Or if yellowpages is running,
: 
: 	ypcat ethers | grep `hostname`

If your ethers database is out-of-date (which ours often is), then another
way to find it is to say

	rsh someotherhost /usr/etc/arp `hostname`

Larry Wall
lwall@jpl-devvax.jpl.nasa.gov

noren@dinl.uucp (Charles Noren) (05/04/90)

Thanks to the dozens of replies.  There are many ways to "skin the cat"
on this question.  I haven't tried all of them, but here's a list of
some of the many ways:

  arp(8):  arp -a, or pipe it to grep with hostname just to get
  the hostname address, for example: arp -a | grep dinl

  ifconfig(8)
  
  grep `hostname` /etc/hosts   (for IP address only).

  /etc/dmesg|grep Ethernet, or dmesg | grep Ethernet   if path is set right.

  grep Ethernet /var/adm/messages* | tail -1    (for your hardware address)

  grep `hostname` /etc/hosts | tail -1  (for the IP address)

  rsh machine2 ping machine1 \; arp machine1

  Look in /var/adm/messages. It has copies of all messages output to
  the console during logins.

  Go to another machine on the same local net, ping it to make sure its
  alive, then enter:  arp hostname, where hostname is the name of your
  machine.

  If your network administrator maintains the "ethers" yellow pages
  database, it's as simple as typing "ypmatch `hostname` ethers".

  If above not true, you can write a trivial utility in C which uses the
  library function ether_hostton().  See the ethers(3N) man page.

Thanks again for all the replies!

-- 
Chuck Noren
NET:     ncar!dinl!noren
US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260,
         Denver, CO 80201-1260
Phone:   (303) 971-7930

bob@omni.com (Bob Weissman) (05/05/90)

Hmm, SunOS 4.0.3 provides the helpful functions

     ether_hostton(hostname, e)
	   char *hostname;
	   struct ether_addr *e;

     ether_ntohost(hostname, e)
          char *hostname;
          struct ether_addr *e;

where netinet/if_ether.h defines

	struct ether_addr {
		u_char  ether_addr_octet[6];
	};

This is described on the ethers(3N) man page.

Is SunOS the only flavor of Unix which has this?

-- 
Bob Weissman
Internet:	bob@omni.com
UUCP:		...!{apple,pyramid,sgi,tekbspa,uunet}!omni!bob

chris@mimsy.umd.edu (Chris Torek) (05/05/90)

In article <1606@dinl.mmc.UUCP> noren@dinl.uucp (Charles Noren) writes:
>... how do I find out what my Ethernet address is?

Others have followed up with various answers, but no one has pointed
out one basic problem with the idea: there is nothing that says that
a machine *has* `an' Ethernet address.  In particular, the Sun 3/50
I am typing on at the moment has an (1) Internet address and no (0)
Ethernet addresses.  There are other Suns at the University of Maryland
that have two Ethernet addresses.  In the general case, you cannot talk
about `the' Ethernet address of any particular machine without first
deciding that the machine has exactly one Ethernet address (this does
not imply `one Ethernet interface': all Xerox D-machines have a single
Ethernet address, regardless of the number of Ethernet interfaces).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris