1

I've installed Raspbian (Raspbian GNU/Linux 8.0 (jessie)) on the Raspberry Pi 2 Model B. To be able to reach it by its hostname, I installed winbind and then modified the hosts section in the file /etc/nsswitch.conf to:

hosts: files dns wins

Unfortunately, pinging is only possible to raspberrypi.local, but not raspberrypi.

What do I have to do to make pinging without .local possible on Raspbian?

EDIT:

The /etc/hosts looked like this:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       raspberrypi

and I changed it to this:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       raspberrypi
127.0.0.1       raspberrypi

But it still fails when I ping raspberrypi from another computer within the same network.

  • Why not editing host file and pointing 127.0.0.1 to raspberrypi? – xdhe Jun 11 '16 at 16:09
  • @xdhe Tried this with no effect. (edit above) – Socrates Jun 11 '16 at 23:28
  • how about setting up local dns-server using bind? – xdhe Jun 11 '16 at 23:33
  • @xdhe How would I do that? I thought I did that with winbind and the wins entry in /etc/nsswitch.conf. – Socrates Jun 11 '16 at 23:44
  • see my answer below. – xdhe Jun 12 '16 at 0:02
1

Your problem is that all of the edits you've done are for name resolution on the RPi itself. Other computers need to be able to find your RPi using DNS. Specifically, the DNS server they are using for name resolution. The solution is going to depend on what you're currently using for name resolution.

If your router/current dns server supports it, you can simply create a static dns mapping or alias there. That way, the other computers will obtain a response when looking for the RPi's name.

If you want a more scalable and easier to manage solution, can strongly recommend dnsmasq as a very flexible dhcp and dns server for exactly your situation. You configure it as your dhcp server, and configure the dhcp leases so your other computers point to the server running dnsmasq as their dns server. By default, dnsmasq will create dynamic dns entries for any machine it assigns a dhcp lease to. For example, all of my machines are assigned dhcp leases by dnsmasq, and point to the dnsmasq server for DNS. When I boot a newly-burned raspbian image, the RPi gets the same settings via dhcp, and dnsmasq creates a dynamic dns entry for the RPi. By default, I can locate new raspbian machines with ping raspberrypi, as well as every other machine that is configured to use dhcp. I can also create static dns entries in dnsmasq for machines that do not use dhcp.

I found dnsmasq setup and usage to be far simpler than using ISC DHCP and BIND.

Be aware that anytime you make changes to your dns setup, computers will cache dns entries, so it may take some time for changes to be recognized on all of your other computers.

0

But it still fails when I ping raspberrypi from another computer within the same network.

Yeah it never worked because host file only translate address to ip only on raspberry. If you want to ping raspberrypi from another computer on the same network, you must setup dns-server using bind, and then point the dns-server address to the interface that your computer currently used. To configure bind, you must install bind before using

sudo apt-get install bind9 && cd /etc/bind

and then change named.conf.local by adding following line

zone "raspberrypi (or domain you like)" {
        type master;
        file "/etc/bind/db.raspbeerypi";
};

you must note that the the ip that the raspberry currently used by using sudo ifconfig and then create file db.raspberrypi using db.local by copying it using sudo cp db.local db.raspberrypi and then add the following line to the db.raspberrypi

;
; BIND data file for raspberrypi
;
$TTL    604800
@       IN      SOA     raspberrypi. root.raspberrypi. (
                        1206201601      ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;

@       IN      NS      raspberrypi.
@       IN      A       <raspberry pi ip that it currently used>

the dns-server should working after you do sudo service bind9 restart and don't forget to appoint raspberrypi ip to the dns-server section of your OS network configuration.

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.