Hi! I've created a program just to fix this. The thread I originally posted it in is here .
To use it, first install libgtk2-perl by finding it in synaptic or typing the following in a terminal:
PHP Code:
sudo apt-get install libgtk2-perl
Following that, copy my program into a text file on your hard drive, preferably calling it something that ends in a .pl. Make sure you make it executable (This can be done by right-clicking and going to properties)
My program:
PHP Code:

#copy after this line... those numbers shouldn't be here. Glitch with ubuntuforums, I guess
#!/usr/bin/perl
# by Adam
use warnings;
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
my $main = Gtk2::Window->new('toplevel');
$main->set_position('center');
$main ->set_title('Change Hosts');
$main ->signal_connect(delete_event => \&delete_event);
$main ->set_border_width(15); #this is like CSS' padding, not border
my $box1 = Gtk2::VBox->new(FALSE, 0); #I don't know what these arguments do
$main->add($box1);
my $button1 = Gtk2::Button->new("I'm home");
$button1->signal_connect(clicked => \&host_local);
$box1 -> pack_start($button1, TRUE, TRUE, 0); #what are these arguments?
$button1->show; #this tells Gtk that our button preps are done. Cool.
$button1 = Gtk2::Button->new("I'm not home"); #NEW POINTER, SAME VARIABLE
$button1->signal_connect(clicked => \&host_remote);
$box1 -> pack_start($button1, TRUE, TRUE, 0);
$button1->show;
$box1->show; #Box is done being composed. Send to higher level to get rendered.
$main->show; #show the window! :D
Gtk2->main;
0; #frig I keep forgetting this
sub delete_event
{
Gtk2->main_quit;
return FALSE;
}
sub host_remote
{
exec ("gksudo cp /home/adam/Scripts/GTK2/hosts.remote /etc/hosts") || die "Cannot change hosts file: $!\n";
#THIS IS THE FIRST LINE YOU NEED TO CHANGE
}
sub host_local
{
exec ("gksudo cp /home/adam/Scripts/GTK2/hosts.local /etc/hosts") || die "Cannot change hosts file: $!\n";
# THIS IS THE SECOND LINE YOU NEED TO CHANGE
}
The brunt of the program happens in the last few lines. It executes a simple bash command copying a file onto the current hosts file using sudo privileges. To fix it for your uses, create the two seperate hosts files you wish to use, and replace /home/adam/Scripts/GTK2/hosts.remote with the path to the one you want to use when away from home, and /home/adam/Scripts/GTK2/hosts.local to the path to the hosts file you wish to use when you are at home.
Now, for security reasons, you shouldn't keep any of these files in your home folder or writable by anyone except root. If you need help with that... let me know.
Bookmarks