Download Article
Learn how to prevent your browser from accessing specific sites
Download Article
- On Windows |
- On Mac |
- On iPhone |
- On Android |
- Q&A |
- Tips |
- Warnings
Do you not want your browser going to a site that might be malicious? The website cannot only have bad coding, but it can also negatively affect productivity, offer inappropriate content, or steal data. You'll definitely want to block anything like that from your browsers. This wikiHow teaches you how to prevent a specific website from being accessed on any browser on a Windows or Mac computer by editing the "hosts" file. Additionally, you can block sites on an iPhone or iPad using the Restrictions menu in Settings, and Android users can use the free BlockSite app to restrict website and app access.
Things You Should Know
- You can block websites using a Windows or Mac computer as well as an Android or iPhone phone or tablet.
- Editing the "Hosts" file takes a little work, but this wikiHow article guides you through the process so it's easier to block websites in all your web browsers.
- Use Settings on an iPhone or the BlockSite app to block sites on Android.
Steps
-
Type Notepad into Start. Doing so will display the Notepad app at the top of the Start menu window.Advertisement
-
Right-click on Notepad and select Run as administrator . This option will open Notepad using your administrator privileges. If you don't open Notepad in administrator mode, you won't be able to edit the "hosts" file.
- On a laptop with a trackpad instead of a traditional mouse, use two fingers to tap the trackpad instead of right-clicking.
-
Click Yes when prompted. Doing so will confirm your decision and open Notepad.
-
Click File , then click Open… . You'll find Open in the File drop-down menu.
-
Go to the Hosts file's folder. In the window that opens after clicking Open... , do the following:
- Click the This PC tab on the left side of the window.
- Double-click your computer's hard drive (e.g., OS (C:) ).
- Double-click the Windows folder.
- Scroll down and double-click the System32 folder.
- Scroll down and double-click the drivers folder.
- Double-click the etc folder.
-
Show all file types. Click the "Text Documents" drop-down box near the bottom of the window, then click All Files in the drop-down menu. You should see several files appear in the window.
-
Allow editing for the "hosts" file. Right-click the "hosts" file, then do the following:
- Click Properties
- Click Security
- Click Edit
- Check the "Full Control" box.
- Click OK , then click Yes when prompted.
- Click OK to exit the Properties window.
-
Double-click the "hosts" file. This will open the "hosts" file in Notepad, allowing you to view and edit its contents.
-
Scroll down to the bottom of the "hosts" file. You'll see two "localhost" lines of text here.
-
Click below the last line of text. It will say either "::1 localhost" or "127.0.0.1 localhost" at the bottom of the page. Your cursor must be directly below the last line of text on this page.
- Be careful not to delete anything that is already in the hosts file.
-
Type in 127.0.0.1 and press Tab ↹ . This is the loopback address to your own computer, which is what will return an error page in your web browser when someone tries to visit the blocked site.
-
Type the address of the site you want to block. For example, if you wanted to block Google, you would type www.google.com .
- If you're blocking sites on Google Chrome, you'll need to place a space and then the "www.[site].com" version of the website's address after the "[site].com" version. To block Facebook, for example, you would type in 127.0.0.1 facebook.com www.facebook.com .
-
Press ↵ Enter . This moves your cursor to a new line. The code you entered will tell your computer to redirect the website to your loopback address instead.
- You can add as many sites as you want to block, one per line, using the same number (127.0.0.1) as before.
- If you want to be as thorough as possible, enter different variations of the address (e.g., "google.com" and "https://www.google.com/") as well.
-
Save the Hosts file. Your changes won't be saved if you simply save using File > Save , so do the following to confirm your changes:
- Click File
- Click Save As...
- Click Text Documents , then click All Files in the drop-down menu.
- Click the "hosts" file.
- Click Save
- Click Yes when prompted.
Advertisement
-
Type terminal into Spotlight. This will prompt Terminal to appear at the top of the search results.
-
Open the Hosts file. Type the following code into Terminal and press ⏎ Return :
sudo nano /etc/hosts
-
Enter your Mac's password when prompted. Type in the password that you use to log into your Mac, then press ⏎ Return .
- Terminal won't display the password characters as you type them.
-
Move the blinking cursor down to the bottom of the page. To do so, press the ↓ key until the cursor is below the last line of text on the page.
-
Enter the local host address. Type 127.0.0.1 into the blank line. This is the loopback address to your own computer. [1] X Research source
-
Press Tab ↹ . The cursor will move to the right.
- Don't press ⏎ Return yet.
-
Type the address of the site you want to block. For example, if you wanted to block Google, you would type www.google.com .
- This line would then read 127.0.0.1 www.google.com .
- If you want to be as thorough as possible, enter different variations of the address (e.g., "google.com" and "https://www.google.com/") as well.
- If you're blocking sites on Google Chrome, you'll need to place a space and then the "www.[site].com" version of the website's address after the "[site].com" version. To block Facebook, for example, you would type in 127.0.0.1 facebook.com www.facebook.com .
-
Press ⏎ Return . This will tell your computer to redirect the website to your loopback address instead.
- You can add as many sites as you want to block, one per line, using the same number (127.0.0.1) as before.
-
Press Control + X . This is the command to exit the hosts file in the text editor. It will prompt you if you'd like to save your changes.
-
Press Y to save your changes. It will then ask you what filename you'd like to save it as. You want to overwrite the original hosts file, so don't change the filename.
-
Press ⏎ Return . This will save your changes to the original hosts file. Doing so exits the text editor and returns you to the main Terminal window. The website you added will now be unreachable in any web browser on the computer.
Advertisement
-
Tap Screen Time . This option is usually in the second grouping of menu items next to an icon of an hourglass.
- Select Turn on Screen Time if you're prompted and select if the phone is yours or a child's. If your phone belongs to a child, you'll be prompted to enter the passcode.
-
Tap Content & Privacy Restrictions . This is near the bottom of the screen next to a red icon with a circle that has a line through it.
- If you haven't yet enabled restrictions, first tap Enable Restrictions , then enter your desired passcode twice when prompted.
-
Tap Content Restrictions . This is usually the third listing in the menu.
-
Tap Web Content . It's the last entry beneath the "Web Content" heading.
-
Tap Limit Adult Websites . You'll see a blue checkmark appear to the right of this option.
-
Block a specific website. If you want to block a specific site, like Facebook, tap Add a Website below the "NEVER ALLOW" heading and type in the web address of the website you wish to block. The address must start with "www" and end with a domain tag (e.g., ".com" or ".net"), but you can leave the "https://" section out if applicable.
- For example, if you wanted to block Facebook on your iPhone or iPad, you would type in
www.facebook.com
. - This setting also applies to other popular iPhone browsers such as Chrome and Firefox. [2] X Research source
- For example, if you wanted to block Facebook on your iPhone or iPad, you would type in
Advertisement
-
Download the BlockSite app. BlockSite is an app which allows you to block websites and apps from being used on your Android. Open the Google Play Store and do the following: [3] X Research source
- Tap the search bar.
- Type in blocksite and tap the "Search" button.
- Tap INSTALL below the "BlockSite - Block Distracting Apps and Sites" heading.
- Tap ACCEPT when prompted.
-
Open Block Site. Tap OPEN in the Google Play Store, or tap the shield-shaped Block Site app icon in your Android's App Drawer.
-
Tap ENABLE . It's a green button at the bottom of the screen.
-
Tap GOT IT when prompted. Doing so should open your Android's Accessibility menu in the Settings app, but if it doesn't, do the following before proceeding:
- Open Settings
- Scroll down and tap Accessibility
-
Re-open Block Site. If Block Site closed or minimized, bring it back up before proceeding.
-
Tap + . It's in the bottom-right corner of the screen. Doing so will take you to the page from which you can block websites.
-
Enter a website's address. Tap the text field at the top of the screen, then type in the address of a website (e.g., facebook.com ).
-
Block an entire app on your Android. If you have to temporarily block an app, you can do so by tapping + in the bottom-right corner of the Block Site screen, tapping APPS , and tapping an app's name.
- Like websites, you can unblock the app at any time by tapping the trash icon to the right of its name.
-
Block adult content on your Android if needed. If you're looking to prevent a child or similar from visiting adult sites or viewing restricted content, check out this article for more adult content-specific instruction.
Advertisement
Community Q&A
Search
-
QuestionHow can I block a website on the iPad?Community AnswerParental controls in the Settings app allows you to block websites with a passcode.
-
QuestionHow do I force the host file to open in a text editor?Community AnswerIt can't be forced to open in a text editor, because it doesn't have the extension. To open, double-click the file and select the proper program to open it.
-
QuestionCan this be reversible?Community AnswerYes, it is a reversible process. Just remove the extra lines you added. Alternatively, you can restore the hosts file from a backup.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
- You should flush your computer's DNS cache after editing the "hosts" file in order to prevent conflicts between the "hosts" file and your browser.Thanks
- To unblock a site from the "hosts" file, simply open the file again and delete the lines that you added. Make sure you save your changes after removing the lines you added or the sites will still be blocked.Thanks
- Your iPhone's Restrictions settings will apply to both Safari and other browsers as well.Thanks
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement
Warnings
- The Hosts file won't always work to block websites. You might want to try blocking a website in different browsers instead of using the Hosts file if the Hosts file isn't working.Thanks
Advertisement
References
About This Article
Thanks to all authors for creating a page that has been read 1,998,032 times.
Advertisement