• Strip domain name from hostnames in output

    From Steve Keller@21:1/5 to All on Mon Sep 16 11:40:01 2024
    Is there a config option in libc, the host name resolver or somewhere
    else to show hostnames in my own domain without the full domain name?
    E.g. when I have the domain "my.domain" I want that string to stripped
    off from all hostnames shown. Usually, tools always show the FQDN:

    foo:~ $ cat /etc/resolv.conf
    # Generated by resolvconf
    domain my.domain
    nameserver 10.0.0.1
    foo:~ $ hostname -f
    foo.my.domain
    foo:~ $ ping -c1 bar
    PING bar(bar.my.domain (2001:db8::42)) 56 data bytes
    64 bytes from bar.my.domain (2001:db8::42): icmp_seq=1 ttl=64 time=0.685 ms

    --- bar ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.685/0.685/0.685/0.000 ms
    foo:~ $ sudo tcpdump icmp6
    tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
    listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
    19:15:48.159799 IP6 foo.my.domain > bar.my.domain: ICMP6, echo request, id 151, seq 4, length 64
    19:15:48.160032 IP6 bar.my.domain > foo.my.domain: ICMP6, echo reply, id 151, seq 4, length 64
    foo:~ $ sudo lsof | grep IPv.*EST
    ssh 85351 <user> 3u IPv6 474715 0t0 TCP foo.my.domain:41088->bar.my.domain:ssh (ESTABLISHED)

    I'd like the output to be shortened also in other tools that translate
    IP addresses into host names.

    Steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Stone@21:1/5 to Steve Keller on Mon Sep 16 14:10:01 2024
    On Mon, Sep 16, 2024 at 11:18:19AM +0200, Steve Keller wrote:
    Is there a config option in libc, the host name resolver or somewhere
    else to show hostnames in my own domain without the full domain name?

    no

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Urs Thuermann@21:1/5 to Michael Stone on Tue Sep 17 07:40:01 2024
    Michael Stone <mstone@debian.org> writes:

    On Mon, Sep 16, 2024 at 11:18:19AM +0200, Steve Keller wrote:
    Is there a config option in libc, the host name resolver or somewhere
    else to show hostnames in my own domain without the full domain name?

    no

    You could at least achieve that desired behavior by putting all your
    local hosts to /etc/hosts without domain name. You would have to do
    this on all your hosts (or NIS aka YP, if you have that). Ugly, if
    you already have DNS running.

    The getnameinfo(3) function has a flag NI_NOFQDN which would do what
    you want for local hosts, but that doesn't help here.

    So, missing is only a global config flag for getnameinfo() that let's
    it behave as if NI_NOFQDN had been specified if the domain name
    matches the one in /etc/resolv.conf. Useful would also be another
    flag to strip domain names that are listed in /etc/resolv.conf in the
    "search" entry. I also would like such a functionality.

    urs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)