Changing hostname

Post tutorials, HOWTO's and other useful resources here.
Post Reply
digitalmidge
White ninja
White ninja
Posts: 9
Joined: 23 Feb 2016, 02:30
Distribution: lubuntu
Location: Longwood

Changing hostname

Post#1 by digitalmidge » 01 Jul 2016, 16:01

Here is the information I have on changing the hostname.
Please note that it requires a valid name and does no validation
I have created a short script to change the name after the installer completes:

Code: Select all

#! /bin/sh
echo ""
echo "This command requires a hostname to be passed in"
echo " Updates:"
echo "		/etc/NetworkManager/NetworkManager.conf"
echo "          /etc/HOSTNAME"
echo "          /etc/hosts"
echo "          ../boot/porteus.cfg"
echo ""
echo "desired hostname =  $1"
sleep 3
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
sleep 1
sed -i -e "s/hostname=porteus/hostname=$1/g" /etc/NetworkManager/NetworkManager.conf 
sleep 1
echo "/etc/NetworkManager/NetworkManager.conf"
echo ""
cat /etc/NetworkManager/NetworkManager.conf
sleep 5
clear
sed -i -e "s/porteus.example.net/$1.workgroup.local/g" /etc/HOSTNAME
sleep 1
echo "/etc/HOSTNAME"
echo ""
cat /etc/HOSTNAME
sleep 5
clear
sed -i -e "s/porteus.example.net porteus/$1.workgroup.local $1/g" /etc/hosts 
sleep 1
echo "/etc/hosts"
echo ""
cat /etc/hosts
sleep 5
clear 


if [ -f /mnt/sda1/porteus/boot/syslinux/porteus.cfg ];
  then
    sed -i -e "s/APPEND initrd=/APPEND hostname=$1 initrd=/g" /mnt/sda1/porteus/boot/syslinux/porteus.cfg
    sleep 1
    echo "/mnt/sda1/porteus/boot/syslinux/porteus.cfg"
    echo ""
    cat /mnt/sda1/porteus/boot/syslinux/porteus.cfg
  else
    sed -i -e "s/APPEND initrd=/APPEND hostname=$1 initrd=/g" /mnt/sda1/boot/syslinux/porteus.cfg
    sleep 1
    echo "/mnt/sda1/boot/syslinux/porteus.cfg"
    echo ""
    cat /mnt/sda1/boot/syslinux/porteus.cfg
fi

Post Reply