How to find the IP address of the local Linux workstation
I am creating a shell script that should do some local settings and echo the IP of the machine in a text file. The reason I need to do this is to get the IP in a PHP script and use it from there as root for a site.
I can get the IP using ifconfig but I need to strip the useless information. I’d like to do this in the shell script not in the PHP file.
The OS is CentOS 5.5, I need the IP of eth0.
Well ip -4 -o addr show dev eth0 will get you a reasonably nice one line output showing the address but it will need some parsing to extract the address. Something like this should work:
ip -4 -o addr show dev eth0 | awk '{ gsub(//[0-9]+$/, "", $4); print $4 }'
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





