-
-
Save mpneuried/b7654165a91437b6d0a6 to your computer and use it in GitHub Desktop.
A small shell script that will add and remove lines from the hosts file. Originally created by Claus Witt, http://clauswitt.com/319.html.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# @author: Claus Witt | |
# http://clauswitt.com/319.html | |
# Adding or Removing Items to hosts file | |
# Use -h flag for help | |
DEFAULT_IP=127.0.0.1 | |
IP=${3:-$DEFAULT_IP} | |
case "$1" in | |
add) | |
sed -ie "\| $2\$|d" /etc/hosts | |
echo "$IP $2" >> /etc/hosts | |
;; | |
remove) | |
sed -ie "\|^$IP $2\$|d" /etc/hosts | |
;; | |
*) | |
echo "Usage: " | |
echo "hosts.sh [add|remove] [hostname] [ip]" | |
echo | |
echo "Ip defaults to 127.0.0.1" | |
echo "Examples:" | |
echo "hosts.sh add testing.com" | |
echo "hosts.sh remove testing.com 192.168.1.1" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i added line 14 to remove existing settings for the hostname