Oct
Oct

How to edit your Mac hosts file (Mac OS X)

codesm - editing mac hosts fileHow to edit your Mac hosts file (Mac OS X)

Sometimes you need to view a site on a development server. It’s something that I use regularly to connect to a development server using the regular site domain but mapped to a development server’s IP address. This way you can maintain your DNS as it is, and work with the development site’s future domain in a real and meaningful way. Some CMS and applications work best this way when you’re doing active development, and you’re not ready to adjust your domain’s zone file quite yet.

It’s a pretty straight forward and easy process, but a word of caution: if you’re not familiar working with the command line, proceed with caution. You can screw stuff up in a quick hurry if you’re not careful!

Start Terminal on Your Mac

In order to change your hosts file on Mac OS X, you need to use the Terminal app. You can find it by going in to your LaunchPad and starting to type “terminal” and hit enter to launch it, or going to your applications folder, and then to your utilities folder, and it will be in there too.

Open Your Hosts File

Once you get terminal started you will want to run the following command:

sudo nano /private/etc/hosts

This will open up your hosts file in Terminal allowing you to make edits. Make sure you include the first slash before private to get you to the right directory.

Enter Your Password

Next, Terminal is going to ask you for your Mac password, so go ahead and enter that next. As you’re typing your password the cursor will not move, so hopefully you know your way around your keyboard. You can also copy and paste your password in.

Once you enter your password, you’ll now be in the edit screen for your hosts file.

Make Your Entry in Your Hosts File

The lines that start with # are “commented out” so that they’re not read by the system, but allow you to read any important info that the creator of the file wants you to know about. Learning how to comment things is a big help when you’re working with code, and if you need to toggle back and forth between a live site, and one that’s on a remote server, you can simply comment out the line that routes that domain to the development server, in order to get back to the original site.

It should look a little like this:

##
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1     localhost
123.4.5.67    yournewdomainentry.com

Use your arrows to scroll down to an empty line below the ones that are already there by default. Once you’re on a new line, add your new entry by adding the IP address of the server you want to point your domain to, then followed by your domain name. You may want to include both yournewdomainentry.com and www.yournewdomainentry.com. That way it won’t matter whether you include the www or not when trying to get to your new destination that you’re mapping – both the regular domain and the www domain will both resolve to the same place.

Save The Hosts File

Once you’ve made your adjustments by adding a new line to the hosts file you’ll need to save it so hit control+o to save the file. The system will prompt you if you want to write to the same file. Since you’re writing to the same place, just hit enter to save it as the existing file. Next to complete the edit and get out of the hosts file, hit control+x to exit and that will bring you back to your main command prompt.

Make note: it’s control not command.

Flush Your DNS Cache

You should now be good to go. If for some reason your new site mapping isn’t working correctly you may want to flush DNS cache and you can do that while you’re still in Terminal.

dscacheutil -flushcache

Once you’ve got everything done, go ahead and check your hosts file edits. Your new mapping should be in place! Once you’re done and you’ve pushed your site live, make sure to remove your domain mapping, either by commenting it out, or just completely removing it, so that it resolves naturally. You don’t want to be stuck looking at your development server while the rest of the world is looking at the live version.

See Also:

How To Generate Leads Online: Clever & Unique Concepts To Sky Rocket Your Business

Feb

"Generating leads online is an exciting way to build your business, whether your business is online or not. And as we all know generating leads is absolutely crucial because it’s how you get new clients in order to grow your business. So let’s dive right into it! How To Generate Leads Online: The Basics The […]"

Keep Reading...

How To Set Up Your Theme In WordPress?

Feb

"Looking for some help on how to set up your theme in WordPress? One of the biggest things I obsessed over when I was getting started was how my new site was going to look. I’ve always been obsessed with design and aesthetics, so I immediately gravitated to figuring out how to make my new […]"

Keep Reading...

What Do You Need To Get Done Today? Five Things To Get Done Everyday

Aug

"Each morning as I get started on my day I come and sit at this computer with a nice hot cup of coffee and one of the very first things that comes up is an appointment reminder in my Google Calendar asking me what I need to accomplish for the day. I’ve been working on […]"

Keep Reading...

Website Copywriting Template: The Pages You Need & How to Write Them

Apr

"Website Copywriting Template What does success look like for your website and its content? If you don’t know what you’re creating, how can you see if it’s successful or not? When it comes to building out a website I’ve found that creating the content for the new site is among the biggest challenges customers and […]"

Keep Reading...

9 Factors To Consider When Choosing Your Domain Name

Sep

"There are a lot of factors take into consideration when you’re looking at domain name ideas. You’ll be living with this choice for a while, so make sure you think through each factor carefully and make a good decision based on what you’re long term goals are. 1. Think About Finding Something Unique And Catchy […]"

Keep Reading...

Three Factors Affecting The Cost of Every Website Project

Sep

"Every new website has its own challenges but there are three factors that are part of every web development project and how much it costs. Complexity – The deeper the functionality, the higher the cost When I talk about complexity what I mean is it’s really a matter of the different things you need to be […]"

Keep Reading...

WordPress Alternatives – 21 Popular Options Other Than WordPress In 2021

Aug

"Today there are more choices than ever when it comes to choosing a content management system for your website project. WordPress is a great platform, but it really isn’t the right solution for every project. There may be all kinds of reasons you’d look for an alternative to WordPress: ease-of-use, functionality, technical level, features, and […]"

Keep Reading...

What kinds of websites can I build with ClickFunnels?

Jan

"Here’s the deal: ClickFunnels is the best online sales funnel builder on the market today. There isn’t another that comes close. It’s exceedingly good at what it does. But it’s not right for all kinds of websites. It’s great for building some of the kinds of websites we’ve already talked about – websites for contractors, […]"

Keep Reading...

Want free help getting started with your ClickFunnels account?

Jan

"One of the things that’s overwhelming for a lot of people who are new to ClickFunnels and starting an online business is all the stuff you need to do get set up in your account to begin with. I’ve seen it too many times. People get excited about all the possibilities of what can be […]"

Keep Reading...

What is the best ClickFunnels Bonus?

Jan

"The best ClickFunnels bonus is that you get full access to FunnelFlix when you sign up to the pro level account at $297 per month. Everything you’ll ever need to learn about online business and sales funnels is taught by Russell and the ClickFunnels team – in addition to many other industry leaders in FunnelFlix. […]"

Keep Reading...