Re: IP address variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx http://www.ycc.com spamSTOMPER Protected email


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux