How do I parse my Linux servers IP address using a Bash shell?
You need to use the ifconfig or ip command to get ip address under Linux.
Parse an IP Address with ifconfig Command
Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands:
# ifconfig eth0 | grep 'inet addr:'
Sample outputs:
inet addr:192.168.2.100 Bcast:192.168.2.255 Mask:255.255.255.0
To get only an IP address, Bcast and Mask, use the egrep command as follows:
# ifconfig eth0 | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}'
Sample outputs:
192.168.2.100 192.168.2.255 255.255.255.0
Parse an IP Address with ip Command
Use the ip command as follows:
# ip -f inet addr show eth0| grep 'inet'
Sample outputs:
inet 192.168.2.100/24 brd 192.168.2.255 scope global eth0
Just display an IP:
# ip -f inet addr show eth0 | awk -F'inet' '{ print $2}' | cut -d' ' -f21
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop










![Linux: Find Out My Group Name [ Group Memberships ]](http://s13.cyberciti.org/images/shared/rp/3/20.jpg)


{ 0 comments… add one now }