Results 1 to 2 of 2

Thread: Changing the hostname -- I can do it but it's ugly

  1. #1
    Join Date
    Dec 2007
    Location
    Deerfield, Massachusetts
    Beans
    293
    Distro
    Kubuntu

    Changing the hostname -- I can do it but it's ugly

    I want to change the hostname of my computer. I can do it by editing (as root) the files /etc/hostname and /etc/hosts (unless I missed some other important place). But that's ugly. Is there a straightforward way to do it? (The hostname command only modifies your home directory.)

    This would be a useful addition to System Settings.

  2. #2
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,299
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: Changing the hostname -- I can do it but it's ugly

    let me make you something for that
    this script is called new-host-name
    Code:
    #!/bin/sh
    if [ -z "$1" ];then
       echo"usage $(basename $0) newHostName"
       exit
    fi
    if [ ! "$(whoami)" = "root" ];then
       echo "$(whoami) is not root"
       exit
    fi
    old="$(cat /etc/hostname)"
    new="$1"
    sed -i "s/$old/$new/" /etc/hosts
    echo "$new" > /etc/hostname
    exit
    * this script is untested
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •