Tech Tip: Getting Your MAC and IP Address In a Script
Ever wanted to get the MAC or IP address of your computer in a Linux shell script? The following two commands should work on most flavours of Linux/Unix.
To get your IP address:
/sbin/ifconfig \ | grep '\<inet\>' \ | sed -n '1p' \ | tr -s ' ' \ | cut -d ' ' -f3 \ | cut -d ':' -f2
To get your MAC address (Hardware address):
/sbin/ifconfig \ | grep 'eth0' \ | tr -s ' ' \ | cut -d ' ' -f5
Note that this retrieves the address of the eth0 interface by default.
- Readers' Choice Awards 2013
- Mars Needs Women
- RSS Feeds
- Sublime Text: One Editor to Rule Them All?
- Raspberry Pi: the Perfect Home Server
- December 2013 Issue of Linux Journal: Readers' Choice
- IBM Will Minimize Impact of Future Disasters
- Tech Tip: Really Simple HTTP Server with Python
- Linux Systems Administrator
- Senior Perl Developer
- This should be very helpful
1 hour 6 min ago
- As much as I share your point
3 hours 25 min ago
- So girls had it better ?
6 hours 57 min ago
- Reply to comment | Linux Journal
7 hours 17 min ago
- why is GNOME 3 in the fifth position at 14.1 %?
12 hours 49 min ago
- Sublime Is Brilliant!
17 hours 52 min ago
18 hours 12 min ago
- Rapid[Disk,Cache] better than native ram caching?
18 hours 37 min ago
- Nothing is perfect
18 hours 50 min ago
- Mixtapes Community
1 day 29 min ago