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 unsing 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.

Are you running the ssh client on the router or on your PC? Does ping hostname work? Are these local hosts or on the Internet?

If pinging by hostname also says bad name, you need to fix DNS.

2 Likes

Thanks a lot for your quick response! 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". Like you said, seems to be a problem with DNS. Any idea how I could fix this?

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

Edit 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?

In a default installation of OpenWrt, the hostname is openwrt.lan
If you have made any changes that might not work anymore.

2 Likes

I have nothing changed that I cant switch back again. Searched the entire day but did not found the thing that fixes that problem yet. But there must be solution for this problem.

Which hostname are you using?

Use ssh to connect to the device.

Please run the following commands (copy-paste the whole block) and paste the output here, using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have

ubus call system board; \
uci export network; uci export dhcp; uci export firewall; \
head -n -0 /etc/firewall.user; \
ip -4 addr ; ip -4 ro li tab all ; ip -4 ru; \
ls -l  /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/* ; head -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*
1 Like

Your PC DNS needs to be configured as the OpenWrt router, since only the OpenWrt router knows local hostnames.

With a default configuration of OpenWrt and the PC using DHCP, that should be the case.

4 Likes

Thanks a lot @mk24 and trendy :slight_smile: ! Here is the result:

{
        "kernel": "4.14.81",
        "hostname": "XXX.XXX.XXX.XX Omega-30B4",
        "system": "MediaTek MT7628AN ver:1 eco:2",
        "model": "Onion Omega2+",
        "board_name": "omega2p",
        "release": {
                "distribution": "OpenWrt",
                "version": "18.06-SNAPSHOT",
                "revision": "r0+XXXX-XXXXXXXXXX",
                "target": "ramips\/mt76x8",
                "description": "OpenWrt 18.06-SNAPSHOT r0+XXXX-XXXXXXXXXX"
        }
}
package network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdXX:XXXX:XXX::/48'

config interface 'wlan'
        option type 'bridge'
        option proto 'static'
        option ipaddr 'XXX.XXX.3.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wwan'
        option ifname 'apcli0'
        option proto 'dhcp'
        option hostname 'Omega-30B4'

config interface 'wan'
        option ifname 'eth0'
        option proto 'dhcp'

package dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option localservice '1'

config dhcp 'wlan'
        option interface 'wlan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'

config dhcp 'wwan'
        option interface 'wwan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'

package firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option disable_ipv6 '1'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option network 'wlan'

config zone
        option name 'wan'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option network 'wwan'
        option input 'ACCEPT'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config include
        option path '/etc/firewall.user'

# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

# Internal uci firewall chains are flushed and recreated on reload, so
# put custom rules into the root chains e.g. INPUT or FORWARD or into the
# special user chains, e.g. input_wan_rule or postrouting_lan_rule.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: br-wlan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet XXX.XXX.3.1/24 brd XXX.XXX.3.255 scope global br-wlan
       valid_lft forever preferred_lft forever
5: apcli0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN qlen 1000
    inet XXX.XXX.XXX.XX/24 brd XXX.XXX.XXX.255 scope global apcli0
       valid_lft forever preferred_lft forever
default via XXX.XXX.XXX.1 dev apcli0  src XXX.XXX.XXX.XX
XXX.XXX.3.0/24 dev br-wlan scope link  src XXX.XXX.3.1
XXX.XXX.XXX.0/24 dev apcli0 scope link  src XXX.XXX.XXX.XX
broadcast 127.0.0.0 dev lo table local scope link  src 127.0.0.1
local 127.0.0.0/8 dev lo table local scope host  src 127.0.0.1
local 127.0.0.1 dev lo table local scope host  src 127.0.0.1
broadcast 127.255.255.255 dev lo table local scope link  src 127.0.0.1
broadcast XXX.XXX.3.0 dev br-wlan table local scope link  src XXX.XXX.3.1
local XXX.XXX.3.1 dev br-wlan table local scope host  src XXX.XXX.3.1
broadcast XXX.XXX.3.255 dev br-wlan table local scope link  src XXX.XXX.3.1
broadcast XXX.XXX.XXX.0 dev apcli0 table local scope link  src XXX.XXX.XXX.XX
local XXX.XXX.XXX.XX dev apcli0 table local scope host  src XXX.XXX.XXX.XX
broadcast XXX.XXX.XXX.255 dev apcli0 table local scope link  src XXX.XXX.XXX.XX
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default
ls: /tmp/resolv.*/*: No such file or directory
lrwxrwxrwx    1 root     root            16 Feb 22  2021 /etc/resolv.conf -> /tmp/resolv.conf
-rw-r--r--    1 root     root            32 Jun 30 14:12 /tmp/resolv.conf
-rw-r--r--    1 root     root            59 Jun 30 14:12 /tmp/resolv.conf.auto
==> /etc/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf.auto <==
# Interface wwan
nameserver XXX.XXX.XXX.1
search fritz.box
head: /tmp/resolv.*/*: No such file or directory

change the hostname into a single word. It cannot work with spaces.

2 Likes

That is ancient. It should be upgraded. Going to the 21 or 22 versions though will require some changes in the configuration syntax.

2 Likes

Thanks a million. I have changed the hostname using this command:

uci set system.@system[0].hostname='insert-hostname'
uci commit system
/etc/init.d/system reload

and changed my entry in /etc/hosts, but unfortunately it does not work.

Don't enter anything in /etc/hosts either on the PC or on the router. hostname.lan is automatically entered into the router's DNS server.

2 Likes

Do an nslookup hostname.lan from your lan host and post here the output. The actual hostname.

2 Likes

Alright, thanks again. Here is the nslookup output:

Server:         127.0.0.1
Address:        127.0.0.1#53

Name:      omega.lan
Address 1: 127.0.1.1
Address 2: fdXX:XXXX:XXXX::1

That is not a private address range.

3 Likes

Running nslookup on the router should show your LAN IP(s) like this:

 OpenWrt 22.03.0-rc1, r19302-df622768da
 -----------------------------------------------------
root@er-lite:~# nslookup er-lite.lan
Server:		127.0.0.1
Address:	127.0.0.1:53

Name:	er-lite.lan
Address: 192.168.33.1
Name:	er-lite.lan
Address: 192.168.22.1

And on a PC connected to the 22 network, I get this:

mike@mike-HP-Z4:~$ nslookup er-lite.lan
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	er-lite.lan
Address: 192.168.22.1
2 Likes

Oh sorry, I had another entry in /etc/hosts. Now it looks like it should I think (X are privat IPs like 192....):

Server:         127.0.0.1
Address:        127.0.0.1#53

Name:      omega.lan
Address 1: XXX.XXX.3.1
Address 2: XXX.XXX.XXX.XX
Address 3: fXXX:XXXX:XXXX::1
1 Like

and since they are private, it is pointless to mask them.
I guess it is working fine now.

2 Likes

Thats true, sorry for masking them. No, unfortunately it does not work.

Why not? 3 posts ago it resolved the address correctly.

1 Like