hoangtranwork
11/28/2017 - 9:22 AM

Change Ubuntu hostname without restart

Without restart. Retain across ssh sessions (pernament). This also help avoiding sudo: unable to resolve host warning

Steps:

  1. edit /etc/hostname: only 1 line with the new-hostname
new-hostname
  1. edit /etc/hosts: 2 lines
127.0.0.1 localhost new-hostname
127.0.1.1 new-hostname
  1. run sudo service hostname start

NOTE:

  • Need to edit both files with the same value for new-hostname, then restart the hostname service.
  • Work on Ubuntu 14:
    lsb_release -a                                                                                                                                                               0 < 09:25:15
    No LSB modules are available.
    Distributor ID:   Ubuntu
    Description:  Ubuntu 14.04.5 LTS
    Release:  14.04
    Codename: trusty