Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Last active June 3, 2025 16:04
Show Gist options
  • Select an option

  • Save bzerangue/4393408 to your computer and use it in GitHub Desktop.

Select an option

Save bzerangue/4393408 to your computer and use it in GitHub Desktop.

Revisions

  1. bzerangue revised this gist Dec 28, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion update-hosts.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,9 @@
    # @author: Claus Witt
    # http://clauswitt.com/319.html

    # Adding Items to hosts file
    # Adding or Removing Items to hosts file
    # Use -h flag for help

    DEFAULT_IP=127.0.0.1
    IP=${3:-$DEFAULT_IP}

  2. bzerangue revised this gist Dec 28, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions update-hosts.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    #! /bin/sh
    # @author: Claus Witt
    # http://clauswitt.com/319.html

    # Adding Items to hosts file
    DEFAULT_IP=127.0.0.1
    IP=${3:-$DEFAULT_IP}

  3. bzerangue created this gist Dec 28, 2012.
    25 changes: 25 additions & 0 deletions update-hosts.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #! /bin/sh
    DEFAULT_IP=127.0.0.1
    IP=${3:-$DEFAULT_IP}

    case "$1" in
    add)
    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