I'm connected to a private network where the IP addresses are like 192.168.xxx.xxx. I know the IP address of the default gateway but how do I get the gateway mac address? I'm working on iMac and Linux machines. Any Unix command for that?
Asked
Active
Viewed 6,704 times
-1
-
1did you tried "arp -a"? – Sasi V Apr 14 '14 at 19:10
-
Please go to this link: [1]: http://stackoverflow.com/questions/6782658/how-to-get-default-gateway-in-mac-osx – Bun S. Apr 14 '14 at 19:24
2 Answers
1
This gives you list of everything:
netstat -rn
or this one to get default gateway:
netstat -rn | grep 'default'
WHAT YOU REALLY WANT:
netstat -rn | grep 'default' | awk '{print $2}'

Bun S.
- 111
- 1
- 10
1
Here the command line example for arping
assuming your gateway's IP address is 192.168.1.1
and you have connected over eth0
:
arping -f -I eth0 192.168.1.1
ARPING 192.168.1.1 from 192.168.1.24 eth0
Unicast reply from 192.168.1.1 [ab:cd:ef:01:02:03] 1.030ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
So in this case gateway's MAC address is ab:cd:ef:01:02:03

Oleg Neumyvakin
- 9,706
- 3
- 58
- 62
-
1I used this solution instead `netstat` because `netstat -rn` does not include MAC addresses in Centos 7. – Valerio Bozz Mar 31 '20 at 07:58