How-to Flush DNS on Mac OS X

About the DNS cache

OS X keeps a local cache of resolved DNS queries for a time defined by the DNS server. Sometimes it might be necessary to reset the cache immediately and re-query a DNS server. For example, you might need to do this if you are a network or server administrator and an entry on your DNS server has recently changed.

If your Mac isn’t using the latest DNS entries from your server, you can restart your Mac to update its cached information. If you need to update DNS entries on a server using OS X and you can’t restart the server, use the terminal commands below for the version of OS X you’re using.

OS X Yosemite, El Capitan and later

Use the following Terminal command to reset the DNS cache in OS X v10.10.4 or later:

sudo killall -HUP mDNSResponder

Use the following Terminal command to reset the DNS cache in OS X v10.10 through v10.10.3:

sudo discoveryutil mdnsflushcache

OS X Mavericks, Mountain Lion, and Lion

Use the following Terminal command to reset the DNS cache in OS X v10.9.5 and earlier:

sudo killall -HUP mDNSResponder

Mac OS X Snow Leopard

Use the following Terminal command to reset the DNS cache in OS X v10.6 through v10.6.8:

sudo dscacheutil -flushcache

Apple Mac Mavericks / Yosemite – Refresh Shared Computers in Finder

Sometimes the list of shared computers on the network will not refresh within Finder.

To fix this issue, re-launch the Finder, from the dock. You can do this by:
– Hold down the Alt key and right-click on the Finder icon in the dock. The pop-up menu should include Relaunch as the last item. Click on that and it will re-launch Finder, which takes just a second or so.

Hope it helps!

How to Make a Bootable Mavericks Install Drive

I needed to make a bootable Mavericks install drive using a USB flash drive. I followed option 1 from the below site and it worked perfectly!

Copied here for future reference:

Option 1: Use createinstallmedia

Hidden inside the Mavericks installer is a Unix program calledcreateinstallmedia, provided by Apple for creating a bootable Mavericks installer. If you’re comfortable using Terminal, it’s a relatively simple tool to use. The program assumes your account has administrator privileges.

Note: This method does not work in Snow Leopard. It works only in Lion, Mountain Lion, or Mavericks. (The resulting installer drive will let you install Mavericks over Snow Leopard, but you can’t create the installer drive while booted into Snow Leopard.) If you need to create a Mavericks install drive while booted into Snow Leopard, you should use the Disk Utility instructions, below.

  1. Download the Mavericks installer from the Mac App Store and make sure it’s in your main Applications folder. (This means that if you followed my advice to move the installer out of your Applications folder, you’ll have to move it back, at least temporarily. The Terminal command I’m using here assumes the installer is in its default location.)
  2. Connect to your Mac a properly formatted 8GB (or larger) drive. Rename the drive to Untitled. (The Terminal command used here assumes the drive is named Untitled.)
  3. Select the text of this Terminal command and copy it:
    sudo /Applications/Install\ OS\ X\ --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ --nointeraction
  4. Launch Terminal (in /Applications/Utilities).
  5. Paste the copied command into Terminal and press Return. Warning: This step will erase the destination drive or partition, so make sure it doesn’t contain any valuable data.
  6. Enter your admin-level account password when prompted.
  7. The Terminal window displays the progress of the process, in a very Terminal sort of way, by displaying a textual representation of a progress bar: Erasing Disk: 0%… 10%…20%… and so on. The program then tells you it’s copying the installer files, making the disk bootable, and copying boot files. Wait until you see the text Copy Complete. Done. (see the screenshot below), which could take as long as 20 or 30 minutes, depending on how fast your Mac can copy data to your destination drive.

You now have a bootable Mavericks-install drive. If you’re curious about createinstallmedia, type or paste the following command in Terminal and press Return:

/Applications/Install\ OS\ X\

The resulting text output shows you the (brief) instructions for using createinstallmedia more generically. (Thanks to a developer on Apple’s Developer Forums for pointing out createinstallmedia a few months ago.)

The createinstallmedia command in Terminal
Using the createinstallmedia command in Terminal

How-To Flush DNS on Mac OS X Lion

Flushing the DNS on Mac OS X Lion is quite simple. Just follow the below steps:

OS X Mavericks, Mountain Lion, and Lion

Use the following Terminal command to reset the DNS cache in OS X v10.9.5 and earlier:

sudo killall -HUP mDNSResponder

Making a Bootable USB Stick on an Apple Mac OS X from an ISO

This quick how-to will show you how to make a bootable USB stick from a downloaded ISO file using an Apple Mac OS X.

Note: this procedure requires an .img file that you will be required to create from the .iso file you download.

TIP: Drag and Drop a file from Finder to Terminal to ‘paste’ the full path without typing and risking type errors.

  1. Download the desired file
  2. Open the Terminal (in /Applications/Utilities/ or query Terminal in Spotlight)
  3. Convert the .iso file to .img using the convert option of hdiutil:
    hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso)
  4. Note: OS X tends to put the .dmg ending on the output file automatically.
    Rename the file by typing:
    mv /path/to/target.img.dmg /path/to/target.img
  5. Run diskutil list to get the current list of devices
  6. Insert your flash media
  7. Run diskutil list again and determine the device node assigned to your flash media (e.g. /dev/disk2)
  8. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command; in the previous example, N would be 2)
  9. Execute sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m (replace /path/to/downloaded.img with the path where the image file is located; for example, ./ubuntu.img or ./ubuntu.dmg).
    • Using /dev/rdisk instead of /dev/disk may be faster.
    • If you see the error dd: Invalid number '1m', you are using GNU dd. Use the same command but replace bs=1m with bs=1M.
    • If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the ‘Disk’ and unmount (don’t eject) the drive.
  10. Run diskutil eject /dev/diskN and remove your flash media when the command completes
  11. Now the USB stick is ready. Boot the device that you want from the USB stick.

Using Private Keys with SSH login Without Password on Mac OS X

Here’s an excellent write-up for setting up SSH access using private keys to connect to other Linux/Unix servers without having to enter a password.

Copied here for reference.

Tired of typing passwords to SSH servers you often access? Well get used to it! Passwords provide a high level of security, but but it have a tendency be tedious, and also prevent you from running local scripts that automatic logon to your server to perform tasks or you you simply will backup/copy files from your server to your local Mac. The good news is that’s a simple solution to all this.

SSH and keys, WTF

To enable automatic login to a SSH server, the server must have a copy of your public key. The key is signed by what we call a passphrase, meaning that, when you now access a server that got a copy of your public key it prompt your for your password (passphrase) instead of the system user account password. So we really did not fix the problem, we just shifted the problem, but we shifted it in the right direction, and now we can do something about it.
ssh public key
Passphrase exchange

Empty passphrase

The most daring users, simply create a public key with a empty passphrase. This introduce a security problem. If you somehow gained access to a copy of your privat key, they will gain access to all the servers that trust your key.

Use a agent to propagate the passphrase

Keychain Access
A more secure way of solving this is using a program (ssh-agent) to propagate the passphrase. This solution is quite good, but like everything else it comes with a few drawbacks. You need to have your shell environment set up correctly, and only application with the correct environment setting is able to benefit from it. In OS X you are able avoid this problem simply by using the system utility “Keychain Access”. It will store and propagate your passphrase, and in Leopard (10.5) Apple finally introduced native support for using Keychain Access also in terminal.

Setting it all up

OS X has native support for creating and storing pass phrases (Keychain access) so setting this up on your Mac is not that hard. Linux users that are reading this can also follow along then the only difference is what application you use to store the passphrase. Like an example will Gnome users normally use the Gnome Keyring application.

  1. Create your set of keys:
    Start up the Terminal application and run:
    ssh-keygen -t rsassh-keygen will the ask where to store the public key it is about to create. Normally the default suggestion works just fine (~/.ssh/ ssh-keygen then ask you to enter a pass phrase. Please use something secure here and please also remember it.
  2. Copy the public key to your SSH server
    Copy the newly created public key to the SSH server(s) you need to auto login into by using your favourite transport method. Please be careful not to overwrite ~/.ssh/authorized_keys if it already exist! This is how I personally copy the key, might not be your preferred method:

    • If authorized_keys exist: 
      cat ~/.ssh/ | ssh "cat - >> ~/.ssh/authorized_keys"
    • If authorized_keys does not exist: 
      scp ~/.ssh/
  3. Optional step: You might consider restricting file access to the file authorized_keys on the SSH server. chmod 0600 ~/.ssh/authorized_keys to even further improve your system security.

Keychain store passphrase
Now you should be all set. The very first time you access the server by ssh, Keychain will prompt you for your keyphrase and then store it and you will never have to type it again.

Why Are More People Becoming Mac Fans?

I’m known at my job and with friends of being a Mac fan, which is true. It wasn’t always like that however. I’ve spent the majority of my IT career behind a keyboard of a PC (well, and a Linux machine when I was a Redhat Server Administrator) 😉 Customers and friends often ask why I use a Mac, and I thought that this experience of a blogger who works for a site called Tuaw summed it up nicely. Just like he mentions- Macs are not perfect- but even when things go wrong, the overall experience has been way less frustrating than experiences that I’ve had with a PC.

And people wonder why Mac’s are gaining marketshare, not only for the consumer, but in the enterprise as well.. 😉

Interesting graphic on Mac’s market share: