Apple

How to use loopback addresses other than 127.0.0.1 with OSX

Strange little thing I encountered a while back. Basically, I use ssh tunnels to a number of remote hosts and to organize it a bit easier, I tend to use 127.0.0.X and assign each server a different number. However, under OSX you cannot use any others except for 127.0.0.1

The fix isn’t too bad though, you basically need to add the interfaces either manually or at startup.

To add just a few, you can do:

sudo ifconfig lo0 alias 127.0.0.2 up

and change 2 to whatever ip you need. However, if you want to add a large number or all of the possible ones, this will take a long time. So, a quick little script to do it would be something like:

for ((i=2;i<256;i++))
do
   sudo ifconfig lo0 alias 127.0.0.$i up
done

You could also change the 256 to something else like 50 if you don’t want the full list added.

How to clear DNS cache in various OS

There are a variety of reasons why (updated a DNS record, issues with resolver, etc) but sometimes a good diagnostic step is to clear out the dns cache.

Each operating system (and even versions / distributions in some cases) have a different method

OSX 10.10 > sudo discoveryutil udnsflushcaches

OSX 10.9 > dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OSX 10.7 – 10.8 > sudo killall -HUP mDNSResponder

OSX 10.5 – 10.6 > sudo dscacheutil -flushcache

Windows > ipconfig /flushdns

Linux - There are many different distros and versions here, but one of the following should work > /etc/init.d/named restart

/etc/init.d/nscd restart

service nscd reload

sudo /etc/init.d/dnsmasq restart

service dnsmasq restart