I am planning to create new droplets dynamically. They will register themselves by writing their IP address in a database. They are all going to be on a private network, so this will be the IP address of eth1 and not eth0. Is the best way for a droplet to learn its IP address to run ifconfig and parse its output, or is there a better way to do this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi @RalphEJohnson, I remember needing something like this for a project a while ago, I basically did the following. It gives you the private IP address of the droplet.
ip addr show eth1 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.