I would like to get the IP address assigned to eth0. How do I display the IP address only?
Environment
- Red Hat Enterprise Linux (3/4/5)
Issue
- I would like to get the IP address assigned to eth0. How do I display the IP address only?
Resolution
ifconfig will list the IP address assigned on the system.
Sometimes it is required to just find the IP address of a single interface. Its usually requires a script. In order to achieve this requirement, use several other commands along with ifconfig. These commands are grep and cut to acquire and print selected parts of lines/output.
ifconfig | grep -i "eth0" -A 1 | grep "inet addr" | cut -d " " -f 12 | cut -d ":" -f 2
Example output would look like the following:
ifconfig | grep -i "eth0" -A 1 | grep "inet addr" | cut -d " " -f 12 | cut -d ":" -f 2
10.0.0.15
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
