{"id":1002,"date":"2010-07-16T08:13:33","date_gmt":"2010-07-16T15:13:33","guid":{"rendered":"https:\/\/simpleprogrammer.com\/?p=1002"},"modified":"2013-08-04T22:17:19","modified_gmt":"2013-08-05T02:17:19","slug":"if-you-like-living-dangerously-modify-your-hosts-file","status":"publish","type":"post","link":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/","title":{"rendered":"If You Like Living Dangerously Modify Your Hosts File"},"content":{"rendered":"<p>I\u2019ve been seeing it and hearing about it more and more, and every time I do, I cringe.<\/p>\n<blockquote><p>\u201cHey, how do I test out our web app?\u201d<\/p>\n<p>\u201cOh modify your hosts file so that when you go to <a href=\"http:\/\/wonkywares.com\">wonkywares.com<\/a> it goes to <a href=\"http:\/\/test.wonkwares.com\">test.wonkwares.com<\/a>.\u201d<\/p>\n<p>\u201cUmm\u2026 ok, that sounds great.\u201d<\/p><\/blockquote>\n<h2>What this is doing<\/h2>\n<p>What I am talking about is going to C:\\windows\\system32\\drivers\\etc\\hosts and adding entries to that file that map ip addresses to host names.<\/p>\n<p>The hosts file is basically a mapping for ip addresses to host names.<\/p>\n<p>So if you put an entry,<\/p>\n<p>207.46.0.87 google.com<\/p>\n<p>in the file, when you type google.com into your browser you will go to bing.com instead. (That is the ip address for bing.com.)<\/p>\n<p>Why would someone do this?<\/p>\n<p>Well, if you have some code, automated scripts, or process that uses your real production domain name, you can modify your hosts file so that the production host name gets resolved to the test ip address.<\/p>\n<p>Magically when you go to <a href=\"http:\/\/wonkywares.com\">wonkywares.com<\/a> you will instead go to <a href=\"http:\/\/test.wonkywares.com\">test.wonkywares.com<\/a>.<\/p>\n<p>Yes, I do realize this may seem cool and clever.<\/p>\n<p>Heck, you might have stopped reading this blog and called an emergency meeting so you can tell everyone on your team how they can modify their hosts file to magically make your production scripts work on test without passing in the url.<\/p>\n<h2>What could possibly go wrong?<\/h2>\n<p>Let me give you a scenario:<\/p>\n<blockquote><p>\u201cOkay Jeff, I\u2019m gonna run the tests scripts on my new workstation to make sure everything is still working right.<\/p>\n<p>\u201cJoebob, how do those fancy dandy test scripts of yours work again?\u201d<\/p>\n<p>\u201cWell Jeff, they drop all the data in the test database and then create new test data, run the tests, and clean up the data after them again.\u201d<\/p>\n<p>\u2026 Joebob runs the test scripts and watches as they all pass, thinking about how awesome and clever he is.<\/p>\n<p>RING\u2026 RING\u2026 RING\u2026<\/p>\n<p>\u201cHello, this is Joebob.\u201d<\/p>\n<p>\u201cHi Joebob, this is the CEO, Mr. Wonky, I am getting reports that there are no products at all being displayed on our production website.\u201d<\/p>\n<p>\u201cOh shnikies!\u00a0 I must have forgotten to modify my hosts file to point wonkywares.com to test.wonkywares.com.\u00a0 I ran my test scripts against production.\u201d<\/p>\n<p>\u2026 Joebob pulls a wonkywares revolver out of his bottom drawer, right next to the single malt scotch he keeps for \u201cplanning day.\u201d<\/p><\/blockquote>\n<p><a href=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0;\" title=\"Don't let this happen to you\" alt=\"Don't let this happen to you\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted_thumb-1.jpg\" width=\"497\" height=\"188\" border=\"0\" \/><\/a><\/p>\n<p>I am sure you can guess what happens next.<\/p>\n<p>Let me list for you some of the bad things that can happen if you modify your host file to be clever, instead of parameterizing your scripts or code to be able to take a configurable url.<\/p>\n<ul>\n<li>You run your test scripts against production because you forgot to configure your hosts file on your new machine.<\/li>\n<li>You think you modified some production data for a data-fix, but you actually only modified test data.<\/li>\n<li>Someone else uses your machine and doesn\u2019t know that you have a modified host file.<\/li>\n<li>You use someone else&#8217;s machine and forget they don\u2019t have a modified hosts file, so you think you are going to the test website, but you are really modifying live production data.<\/li>\n<li>Your IT guys switch the IP addresses of the staging and production server as part of a rotation so they can do maintenance work on what was the production hardware.\u00a0 You now are pointing to production instead of staging and have no clue.<\/li>\n<li>Someone else tries to run your script or code and is not aware that they have to modify their hosts file first.\u00a0 They run your scripts against production.<\/li>\n<li>You change your hosts file and expect the change to immediately take effect, but your browser is smart and has cached the ip address of the page you just visited.<\/li>\n<\/ul>\n<p>I am sure you can think of plenty more reasons.<\/p>\n<p>So instead of being \u201cclever\u201d and modifying your hosts file, try making whatever code you are writing take in a parameter for the url to use, or read it from a configuration file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been seeing it and hearing about it more and more, and every time I do, I cringe. \u201cHey, how do I test out our web app?\u201d \u201cOh modify your hosts file so that when you go to wonkywares.com it goes to test.wonkwares.com.\u201d \u201cUmm\u2026 ok, that sounds great.\u201d What this is doing What I am&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1000,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[2185,32],"tags":[],"class_list":["post-1002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices","category-infrastructure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>If You Like Living Dangerously Modify Your Hosts File<\/title>\n<meta name=\"description\" content=\"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"If You Like Living Dangerously Modify Your Hosts File\" \/>\n<meta property=\"og:description\" content=\"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file\" \/>\n<meta property=\"og:url\" content=\"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Simple Programmer\" \/>\n<meta property=\"article:published_time\" content=\"2010-07-16T15:13:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-05T02:17:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"241\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"John Sonmez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"John Sonmez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/\"},\"author\":{\"name\":\"John Sonmez\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#\\\/schema\\\/person\\\/1abc70edfb189184827740310672de67\"},\"headline\":\"If You Like Living Dangerously Modify Your Hosts File\",\"datePublished\":\"2010-07-16T15:13:33+00:00\",\"dateModified\":\"2013-08-05T02:17:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/\"},\"wordCount\":694,\"commentCount\":3,\"image\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2010\\\/07\\\/percussion_revolver_wanted.jpg\",\"articleSection\":[\"Best Practices\",\"Infrastructure\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/\",\"name\":\"If You Like Living Dangerously Modify Your Hosts File\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2010\\\/07\\\/percussion_revolver_wanted.jpg\",\"datePublished\":\"2010-07-16T15:13:33+00:00\",\"dateModified\":\"2013-08-05T02:17:19+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#\\\/schema\\\/person\\\/1abc70edfb189184827740310672de67\"},\"description\":\"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#primaryimage\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2010\\\/07\\\/percussion_revolver_wanted.jpg\",\"contentUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2010\\\/07\\\/percussion_revolver_wanted.jpg\",\"width\":640,\"height\":241},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/if-you-like-living-dangerously-modify-your-hosts-file\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/simpleprogrammer.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"If You Like Living Dangerously Modify Your Hosts File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#website\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/\",\"name\":\"Simple Programmer\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/simpleprogrammer.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#\\\/schema\\\/person\\\/1abc70edfb189184827740310672de67\",\"name\":\"John Sonmez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g\",\"caption\":\"John Sonmez\"},\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/author\\\/jsonmez\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"If You Like Living Dangerously Modify Your Hosts File","description":"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/","og_locale":"en_US","og_type":"article","og_title":"If You Like Living Dangerously Modify Your Hosts File","og_description":"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file","og_url":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/","og_site_name":"Simple Programmer","article_published_time":"2010-07-16T15:13:33+00:00","article_modified_time":"2013-08-05T02:17:19+00:00","og_image":[{"width":640,"height":241,"url":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg","type":"image\/jpeg"}],"author":"John Sonmez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"John Sonmez","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#article","isPartOf":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/"},"author":{"name":"John Sonmez","@id":"https:\/\/simpleprogrammer.com\/#\/schema\/person\/1abc70edfb189184827740310672de67"},"headline":"If You Like Living Dangerously Modify Your Hosts File","datePublished":"2010-07-16T15:13:33+00:00","dateModified":"2013-08-05T02:17:19+00:00","mainEntityOfPage":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/"},"wordCount":694,"commentCount":3,"image":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#primaryimage"},"thumbnailUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg","articleSection":["Best Practices","Infrastructure"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/","url":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/","name":"If You Like Living Dangerously Modify Your Hosts File","isPartOf":{"@id":"https:\/\/simpleprogrammer.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#primaryimage"},"image":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#primaryimage"},"thumbnailUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg","datePublished":"2010-07-16T15:13:33+00:00","dateModified":"2013-08-05T02:17:19+00:00","author":{"@id":"https:\/\/simpleprogrammer.com\/#\/schema\/person\/1abc70edfb189184827740310672de67"},"description":"7 examples of why you should read urls from either a configuration file or have code take it in as a parameter rather than modify your hosts file","breadcrumb":{"@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#primaryimage","url":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg","contentUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2010\/07\/percussion_revolver_wanted.jpg","width":640,"height":241},{"@type":"BreadcrumbList","@id":"https:\/\/simpleprogrammer.com\/if-you-like-living-dangerously-modify-your-hosts-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/simpleprogrammer.com\/"},{"@type":"ListItem","position":2,"name":"If You Like Living Dangerously Modify Your Hosts File"}]},{"@type":"WebSite","@id":"https:\/\/simpleprogrammer.com\/#website","url":"https:\/\/simpleprogrammer.com\/","name":"Simple Programmer","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simpleprogrammer.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/simpleprogrammer.com\/#\/schema\/person\/1abc70edfb189184827740310672de67","name":"John Sonmez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc2f18dfa76e017566ce607de002d7abe4acfd5ec19a6db82c180b00867b8d94?s=96&d=mm&r=g","caption":"John Sonmez"},"url":"https:\/\/simpleprogrammer.com\/author\/jsonmez\/"}]}},"_links":{"self":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/comments?post=1002"}],"version-history":[{"count":0,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts\/1002\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/media\/1000"}],"wp:attachment":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/media?parent=1002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/categories?post=1002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/tags?post=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}