2

then I'm using an ubuntu server with gitlab installed, I need to configure hostname the name ubuntudev, to access it from within the network! I configure the ubuntudev name in /etc/hosts but it does not work with the hostname, how can I fix this error? I put under the contents of the /etc/hosts file

--> /etc/hosts

127.0.0.1       localhost
127.0.1.1       ubuntudev

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
riki
  • 133
  • 1
  • 5
  • if you try the command `ping ubuntudev` you'll be pinging 127.0.1.1 so you'll likely find what you did worked, it just didn't do what you intended. `/etc/hosts` preceeded the dhcp protocol (ie. arpanet days) and is only a list of ip-addresses and names to access those ip.addresses. I think what you wanted to change was `/etc/hostname` – guiverc Dec 29 '17 at 11:26
  • @guiverc I have already added what you also say that, but still do not go – riki Dec 29 '17 at 11:29
  • changing the file does nothing until you reboot, or restart the required..... (the file is only read during init type processes then is accessed from memory -- you have to force re-read) note: I don't use gitlab, so do not know it significance to your issues.. – guiverc Dec 29 '17 at 11:30
  • @guiverc does not respond to ping – riki Dec 29 '17 at 11:30
  • @guiverc I've already tried to rewind it, but the result is the same! – riki Dec 29 '17 at 11:31
  • Which server is your DNS nameserver in this network? Is it the same server which's hostname you are changing? – derHugo Dec 29 '17 at 11:41
  • yes it's same.. – riki Dec 29 '17 at 11:43
  • 1
    @guiverc reboot is not required, you can set a hostname with `hostname` but. IMHO, `hostnamectl` is preferred – Panther Dec 29 '17 at 18:21

1 Answers1

3

you set a new hostname with

sudo hostnamectl set-hostname new_hostname

You can also do so by editing BOTH /etc/hostname and /etc/hosts` . Direct editing is discouraged because if you do not edit both you can break sudo.

panther@Ubuntu:~$hostname Ubuntu panther@Ubuntu:~$sudo hostnamectl set-hostname it_works

panther@Ubuntu:~$hostname

it_works

panther@Ubuntu:~$ping -c1 it_works

PING it_works (10.0.0.8) 56(84) bytes of data. 64 bytes from it_works (10.0.0.8): icmp_seq=1 ttl=64 time=0.020 ms

--- it_works ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.020/0.020/0.020/0.000 ms

panther@Ubuntu:~$sudo hostnamectl set-hostname Ubuntu

panther@Ubuntu:~$hostname

Ubuntu

Panther
  • 100,877
  • 19
  • 193
  • 283