Trying a lot but ssh root@hostname instead of ssh root@ip does not work



  • Hi @all,

    I`m absolutely new in using openWRT but I have a bit experience in using other Linux/Unix distributions. If I try to connect by using ip adress over ssh (ssh root@ip) everything works like it should. But if I try to connect using the hostname instead of the ip adress I get absolutely no connection (ssh: Could not resolve hostname ...: Temporary failure in name resolution).

    So, at first I have tried to insert a new line into the /etc/hosts (IP hostname). But this did not work.
    Second thing was to search for the hostname config, like I know from other distributions. This helped me in further times. So I insert the same line into the /etc/sys/kernel/hostname. But this didnt work too.
    And the third possible solution was to try the command "ssh root@hostname.local". But this was also not constructive. Then I tried a few other things I found on the web, but nothing worked for me.

    Btw the hostname of the openWRT distribution is the same as configured in my router.

    So I dont know what to do now and I`m really sad about this circumstance. Hope someone has another great idea to possibly fix this. Thanks in advance.

    Some more information:
    The ssh client is running on PC. These are local hosts in my network. Ping does only work with ip adress too and unfortunately not with the hostname. Ping message is "Name or service not known".

    Question 1:
    What about the /etc/resolv.conf? Could an entry there be a possible solution?

    Question 2:
    In further times using other distributions my solution was to edit the /etc/hosts and /etc/hostname and write a new line with "ip hostname" in it. But within openWRT I cant find /etc/hostname. Should I create one to fix the problem? Or is under openWRT /etc/sys/kernel/hostname the same as in other distributions /etc/hostname?

    Question 3:
    What else could I do? Meanwhile Im feeling totally hopeless, because I`m working on that since hours. Unfortunately I cant find any resolved.conf file to check out same configs like for example under Linux Mint. I read about configurations in /etc/init.d/network. Could this be a possible solution?



  • Hi,

    I am not sure I understand your use case, but I guess what you want is connecting to the Omega2 from another computer? Or from another Omega2?

    Question 1:
    What about the /etc/resolv.conf? Could an entry there be a possible solution?

    No. In OpenWrt, /etc/resolv.conf is a softlink to /tmp/resolv.conf, which in turn is autogenerated from information the Omega gets from your DHCP server, or when you manually configure IP and nameserver, from /etc/config/networkšŸ˜ž

    $ ls -la /etc/resolv.conf
    lrwxr-xr-x    1 root     root            16 Jul 29  2021 /etc/resolv.conf -> /tmp/resolv.conf
    
    $ cat /tmp/resolv.conf
    # Interface lan
    nameserver 192.168.11.1
    search mydomain.ch
    

    What this means is that the Omega2 itself will use the specified nameserver when it wants to connect other hosts. So it has nothing to do with other computers connecting to this Omega2.

    Question 2:
    In further times using other distributions my solution was to edit the /etc/hosts and /etc/hostname and write a new line with "ip hostname" in it.
    But within openWRT I cant find /etc/hostname.

    Again, the hostname is something that in OpenWrt is managed via uci (the universal configuration interface):

    $ uci get system.@system[0].hostname
    Omega2-xyz
    $ uci set system.@system[0].hostname="newhostname"
    $ uci commit system
    $ uci get system.@system[0].hostname
    newhostname
    

    Should I create one to fix the problem?

    No šŸ˜‰

    And, while /etc/hosts exists on openwrt, it is probably not what you are looking for. /etc/hosts is to assign names to IP addresses for connections made from the Omega2 to other computers. It is a fallback when there is no nameserver in your network.

    Question 3:
    What else could I do? Meanwhile Im feeling totally hopeless, because I`m working on that since hours. Unfortunately I cant find any resolved.conf file to check out same configs like for example under Linux Mint. I read about configurations in /etc/init.d/network. Could this be a possible solution?

    If you want to connect to your Omega2 by name rather than IP, you need a nameserver in your LAN that can provide that information. Usually that would be your internet router, running a local DNS server and including hostname information from DHCP.

    Or you can use the so called DNS-SD (service discovery), which is a sort of distributed name server. The Omega2 supports this out of the box using the avahi software. This allows you to use youomega.local. style hostnames, however only from computers/browsers/apps that support this (macOS Terminal.app does out of the box, but otherwise usually you need to install a DNS-SD browser on the system you are connecting from before you can use *.local. hostnames)


  • administrators

    @luz said in Trying a lot but ssh root@hostname instead of ssh root@ip does not work:

    Or you can use the so called DNS-SD (service discovery), which is a sort of distributed name server. The Omega2 supports this out of the box using the avahi software. This allows you to use youomega.local. style hostnames, however only from computers/browsers/apps that support this (macOS Terminal.app does out of the box, but otherwise usually you need to install a DNS-SD browser on the system you are connecting from before you can use *.local. hostnames)

    šŸ‘ šŸ‘ šŸ‘



  • Did you try ssh root@hostname.local ?

    See the difference it makes to ping on my setup:
    Screenshot 2022-07-26 at 12.23.08.png



Looks like your connection to Community was lost, please wait while we try to reconnect.