#! /bin/bash # swap_hosts.sh # This script changes /etc/hosts for when I'm in the same subnet as # my server, and port-forwarding won't work. I can run it at startup, # assuming it has the right permissions, and it will autodetect the # active wireless network # Note: the proper way to address this issue is through simulated loopback. # See https://secure.sccs.swarthmore.edu/pipermail/slug/2006-December/006612.html for more. # This script requires network.sh ssid=`./network.sh` myhomenet= #whatever its name is if [ "$ssid" == "$myhomenet" ] then # These calls to sed should be changed to reflect the nature of your # /etc/hosts. For me, all IPs starting with 192 should be commented # out when I'm away, and uncommented when I'm in the server's subnet. echo "Setting /etc/hosts for local..." sed -i -e 's/^\#192/192/g' /etc/hosts else echo "Setting /etc/hosts for away..." sed -i -e 's/^192/\#192/g' /etc/hosts fi