Redirect IP address back to localhost on Mac OSX

Just a little trick so I can work on some pre-configured work projects at home without having to have a seperate configuration for home. Basically what I wanted to do was, for a web application that connects to a remote MySQL database (where the host is an IP address instead of localhost), I wanted it to simply redirect and connect to my local database (which had the same username and password set up as the remote database).

We can’t do this with the hosts file, because that can only redirect a server name to an IP address (the opposite way round to what we want here).

Fire up your Terminal and type the following:

sudo ifconfig lo0 alias

After entering your password, that will redirect requests for to the localhost/loopback adapter.

And if you need to remove this redirect, try

sudo ifconfig lo0 -alias