Updating Hosts In and Out of Office

Posted by: Steven Smith, on 10 Nov 2008 | View original | Bookmarked: 0 time(s)

We have a machine in the office that we use for source control, and its set up in DNS with a fully qualified name that points to the offices external IP address.  Of course, if you try and use that fully qualified name while youre in the office, you cant connect you have to use the local 192.168.X.X address to get to it.  Thus, the machine has different addresses depending on whether youre trying to reach it from within or outside of the office LAN.

Short of requiring everyone VPN into the LAN when outside the office, the simplest solution (not having a domain controller or DNS server inside the LAN) weve found thus far is to update the HOSTS file (C:\Windows\System32\Drivers\Etc\Hosts) of computers when they are outside of the office.  To achieve this, we simply created two hosts files:

hosts.office.txt includes mapping of foo.bar.com > 192.168.x.x

hosts.home.txt includes mapping of foo.bar.com > xxx.xxx.xxx.xxx internet address

Home really means Anywhere but the office but usually thats home.  It also starts with a different letter (as opposed to out of office) which well see matters slightly.

The next step is to create an office.bat and home.bat which each consist of one line and say:

office.bat:
xcopy /Y hosts.office.txt hosts

home.bat:
xcopy /Y hosts.home.txt hosts

The /Y tells it to overwrite without asking.

Now all that remains is to make it easy to call these two batch files.  This is where Slickrun comes in handy.  By creating magic words for office and home that map to these two files, switching from one profile to another is just a matter of typing:

Win-Q, h o ENTER (for home)

or

Win-Q o f ENTER (for office)

 

Now, what Id really like is for Windows to automatically notice when its network status changes (basically, my machines IP address, or perhaps the name of the LAN/Wireless network), and determine from that which hosts file to use.  If someone has a script that does something like this, let me know.  In the meantime, this approach has worked for the last couple of years with minimal friction/annoyance, so Ill keep using it until something simpler presents itself (or until we move our source control to the cloud/internet).

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: Mobile | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1309 | Hits: 224

Similar Posts

  • My History of Visual Studio (Part 2) more
  • An alternative to Crystal more
  • Telerik Releases New Controls for Silverlight 3 and WPF more
  • Teleriks Q2 2009 Release Expands All-in-one .NET Offering more
  • Don’t use Response.End() with OutputCache more
  • Donut Hole Caching in ASP.NET MVC more
  • Outlook Send Mail Infinite Loop Message in Outbox more
  • Developing RESTful services with JSON and POX support in the ASP.NET MVC more
  • Script to Inventory Print Servers more
  • ASP.NET Podcast Show #129 - Caching with .NET 3.5 SP1 more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD