Using an IP address in config/db.php
The short answer is yes — you need to use a domain names.

You might also want to have a look at this multi-environment configuration method defined on the craft cookbook website that creates a global php variable called CRAFT_ENVIRONMENT in your main index.php.

I generally use that in combination with Ben Parizek technique as described in this answer.