2

How can I change Ubuntu server IP Address to the web address? For example, the address that I need to access on the browser is 192.168.x.xxx. How can I change to dev.robi.local? Thanks!

The /etc/hosts file:

127.0.0.1 localhost localhost
192.168.0.105 dev.robi.local robi
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

The resolv.conf file:

nameserver 8.8.8.8
nameserver 8.8.4.4
domain dev.robi.local
search dev.robi.local
4
  • Only on your host or on the whole LAN?
    – kos
    Sep 18 '15 at 11:38
  • @kos to my whole network Sep 18 '15 at 11:49
  • 1
    Either you need setup local DNS server or add edit /etc/hosts to add this host on each system in you network.
    – jijinp
    Sep 18 '15 at 12:01
  • please note that .local domain is used by the avahi daemon in ubuntu. that is - unless there is something on your network blocking it - you can use <hostname>.local to instead of an ip to name an ubuntu machine from any other ubuntu machine on your local network.
    – user448115
    Sep 18 '15 at 15:28
0

Conventionally name resolution, that is the mapping of IP addresses to host names and vice versa, is done by a DNS (Domain Name System) server.

You probably have an internet router that provides DNS for your local network. There is an offside chance, that your router allows you to add entries to its DNS, but usually customer grade hardware does not offer this. Won't hurt to check, since this would be the easiest way.

As this will probably not be possible, there are multiple ways to go

Note: the domain .local refers to a system known as m(ulticast)DNS, aka zeroconf/bonjour/avahi - for technical details see the RFC. It provides name resolution and service announcement if there is no dedicated DNS server available, although on OS X(bonjour) and Ubuntu (avahi) it is enabled by default.

Update: I found the avahi method not immediately viable and setting up a local DNS only makes sense if it can run as the primary DNS for the network.

  • Most operating systems maintain a hosts file, which contains entries like IP hostname. You could manually add an entry (replace x's with the proper IP!)

      192.168.x.x dev.robi
    

to /etc/hosts on each client on the LAN. This method is straightforward, but a little impractical, if IPs or hostnames change frequently.

  • As noted above, the avahi-daemon is running by default on Ubuntu. You can configure the machine to announce itself under multiple names, but there needs to be a mDNS client running on each machine in the LAN, that should resolve the new hostname (on Windows machines, Apples bonjour service is installed with iTunes). Give it a try by adding

      192.168.x.x dev.robi.local
    

to /etc/avahi/hosts and restart the service with sudo service avahi-daemon restart. Now try if the new hostname is resolved e.g. by pinging it from another machine.

Update: The described method to use avahi to setup an alias does not work! Avahi will not allow to bind multiple hostnames to the same IP, as it will always try to register a corresponding PTR, which leads to a collision. This is expected and good behavior. However, there exists an extension avahi-alias which allows to register aliases (CNAME). Unfortunately, those aliases will not be recognized by (at least) Windows clients, but as long as you're only running clients with avahi, this provides a real option.

To install avahi on a Ubuntu system, do

    sudo apt-get install avahi-daemon libnss-mdns 
  • Setup a local DNS server. I would recommend dnsmasq. It can be installed with sudo apt-get install dnsmasq. It comes with a DHCP server which you will want to disable. Its config is stored in /etc/dnsmasq.conf. To disable DHCP set

      no-dhcp-interface=eth0
    

where eth0 is the interface connecting to the LAN. dnsmasq automatically reads /etc/hosts, so add your hostname to hosts like stated above. Finally add the machine running dnsmasq to the list of DNS servers on each client.

Update: You probably have a DNS server running already, e.g on your internet router. The clients will send DNS queries to that server. You cannot simply add a secondary DNS to your clients config, as it will only ever be queried if the primary DNS is unreachable. Unless you're running an always-on machine that can become the primary DNS for the network, there is no way to make this work.

In Summary: In a Linux-only environment, where you can run the avahi-daemon on each client, the avahi method actually provides a solution. I tried this myself.

Since you probably cannot turn a machine into an always-on DNS server, installing and configuring dnsmasq is not advised.

Still, the most straightforward if a little cumbersome method, is to add an entry to the hosts file on each client!

Your recent problem with DNS resolution probably comes from running dnsmasq. I now actually discourage using dnsmasq, since it will not solve your problem. Stop the service sudo service dnsmasq stop. Then try host -v ro.archive.ubuntu.com. It should resolve using Google's DNS 8.8.8.8 as configured in resolv.conf.

Furthermore, if you go with the hosts method, do not append the domain .local, as it is reserved for mDNS. Instead, just put

192.168.0.5 dev.robi

in /etc/hosts, not dev.robi.local.

15
  • It doesn't work @nephente :( Sep 21 '15 at 12:13
  • @user3749583 Which methods do not work?
    – Nephente
    Sep 21 '15 at 12:19
  • that with dnsmasq Sep 21 '15 at 12:22
  • @user3749583 I believe I know what the problem is. First make sure you can reach dev.robi from the machine itself, e.g ping dev.robi. Then go to another machine and try host dev.robi robi. This will query dnsmasq on robi instead of the primary DNS. It may be that host is not available. You could either install the package bind9-host, or if the package dnsutils is installed try dig @robi dev.robi, which is just another DNS utility. Does the hostname resolve now?
    – Nephente
    Sep 21 '15 at 14:37
  • the response is ,,unknow host dev.robi" Sep 21 '15 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.