IP address variable

Bill Gradwohl bill at ycc.com
Wed Feb 16 19:04:45 UTC 2005


Modifying the hosts file isn't a good idea to implement a method for 
determining the machines IP address.

Use the ifconfig or ip methods as that will always work. The hosts file 
method only works IF you fix the file appropriately first, and that has 
other implications. Don't do it.

To get the current IP address/cidr for a particular interface like eth0:
    ip addr show dev eth0|sed '/inet/!d;s/^.*inet //;s/ .*$//'
To get just the IP address:
    ip addr show dev eth0|sed '/inet/!d;s/^.*inet //;s/\/.*$//'

To set an environment variable in a script, do
    IPADDRESS="$(ip addr show dev eth0|sed '/inet/!d;s/^.*inet 
//;s/\/.*$//')"


-- 
Bill Gradwohl
bill at ycc.com
http://www.ycc.com
spamSTOMPER Protected email




More information about the fedora-list mailing list