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 192.168.66.66

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

And if you need to remove this redirect, try

sudo ifconfig lo0 -alias 192.168.66.66

Leave a Reply

Your email address will not be published. Required fields are marked *