We have requirement to add custom hostname for gateway IP and access the gateway through hostname instead of IP address.

We tried below ways in  RDKB RPI

  • In case of Raspberry Pi /etc/hosts already contains hostname as "RaspberryPi", we try to rename to custom hostname , we are able to ping in Rpi environment but this hostname is not reachable from any other device in the same network.

Note : Able to ping from IP address.

  • we try to set hostname using syscfg command , and restart dhcp service but change is not reflecting and hostname is reset back to "RaspberryPi"
  • we tried to modify dnsmasq.conf  by adding domain=<custom_hostname> address=/<custom_hostname>/10.0.0.1, the result was same
  • we observed that after reboot the change is not persisting in /etc/hosts file.

How to set hostname to gateway ip and persist after reboot?


  • No labels

5 Comments

  1. Hi Z-Divya Khasnis,

    The steps to set the hostname and persist after reboot are as follows:

    • syscfg set hostname <new-name>

    • syscfg commit hostname
    • reboot

    Now the rpi comes up with the new hostname. The same will be reflected in /etc/hosts and in /etc/hostname . 

    The command to check the hostname on terminal is "hostname".

    Please try the above steps and let us know how it works.

    Regards,
    Priyankaa KVB

  2. Hi Priyankaa K V B


    Thanks for the quick reply . The above steps did not work for us below are screen shot for the output. Kindly let us know if we are missing something


    • To Provide more detail on  our requirement , we want gatewayIP hostname registered with local DNS server so that it is accessible from other machine in same network.


    Regards,

    Divya.

    1. Hi Z-Divya Khasnis,

      Could you please confirm the below details

      • By setting to different hostname other than agent.nagra.com (without .com , for example : my-device ), were you able to ping from another device of same network.
      • If you are able to ping with different name , then you need to check your firewall setting/proxy setting and DNS record in your machine. Also please ensure whether you are able to access the same via browser.

      Regards,
      Priyankaa KVB

      1. Hi Priyankaa K V B


        We tried hostname without .com it works we are able to ping hostname from another device in same network, so we try to add hostname "agent.nagra.com" and following parameters to /etc/dnsmasq.conf and reboot still we are not able to ping from other device. Let us know how  to resolve this domain.

        /etc/dnsmasq.conf contents

        --------------------------------

        domain-needed

        local =/agent.nagra.com/

        address=/agent.nagra.com/10.0.0.1

        expand-hosts

        domain=agent.nagra.com

        • how to restart the dnsmasq service, if above parameters are set right?
        • Do we need to do any other configuration?
        • Does RDKB RPI come with default local  DNS server? if not how to configure it?

        Note:

        we observed "agent.nagra" as hostname also does not work, only works without dot and .com (example: agent) 


        Regards,

        Divya.


        1. Hi Z-Divya Khasnis,

          Please find the below details for your queries

          • To restart the dnsmasq service
                                ps | grep dns
                                kill -9 <pid>
                                dnsmasq -u nobody --dhcp-authoritative -P 4096 -C /var/dnsmasq.conf
          • RPi with local DNS server
            It depends on the network you are working on. Check your network dns server and configure it. You can check with your ISP for the domain name in dns server. You can also use other DNS server like Google DNS or OpenDNS as an alternative.
          C:\Users\priyankaa.kvb>ping agent.nagra.com
          Pinging agent.nagra.com [10.0.0.1] with 32 bytes of data:
          Reply from 10.0.0.1: bytes=32 time=1ms TTL=64
          Reply from 10.0.0.1: bytes=32 time=3ms TTL=64
          Reply from 10.0.0.1: bytes=32 time=6ms TTL=64
          Reply from 10.0.0.1: bytes=32 time=3ms TTL=64
          Ping statistics for 10.0.0.1:
              Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
          Approximate round trip times in milli-seconds:
              Minimum = 1ms, Maximum = 6ms, Average = 3ms
          • Other configurations
            The configurations of setting hostname, rebooting and nameserver under /etc/resolv.conf should be fine . 

          Regards,
          Priyankaa KVB