Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: how to get the short hostname

  1. #1

    Default how to get the short hostname

    on my opensuse 42.2 with kde, fresh install, I set my hostname in >Yast>network settings>hostname/DNS in the hostname field I have "pla3-TW" and in the domain name field I leaved "suse", I have a plasmoid that shows me the hostname as result of commandline, but I would like to have the short hostname, reading hostname --help I found that hostname -s do this, but it doesn't works:
    Code:
    pla@pla3-TW:~> hostname --short
    hostname: Name or service not known
    pla@pla3-TW:~> hostname --alias
    hostname: Name or service not known
    pla@pla3-TW:~> hostname -d
    hostname: Name or service not known
    pla@pla3-TW:~> whoami
    pla
    pla@pla3-TW:~>
    how can I get the short hostname with commandline?
    manythanks, ciao, pier :-)

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,329
    Blog Entries
    15

    Default Re: how to get the short hostname

    Hi
    Works fine here, maybe a PATH issue to bin?
    Code:
    malcolml@mizz-piggy:~> echo $PATH
    /home/malcolml/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    malcolml@mizz-piggy:~> hostname --short
    mizz-piggy
    malcolml@mizz-piggy:~> hostname --alias
    mizz-piggy
    malcolml@mizz-piggy:~> hostname -d
    homelinux.org
    malcolml@mizz-piggy:~> whoami
    malcolml
    malcolml@mizz-piggy:~> cat /etc/os-release 
    NAME="openSUSE Leap"
    VERSION="42.2"
    ID=opensuse
    ID_LIKE="suse"
    VERSION_ID="42.2"
    PRETTY_NAME="openSUSE Leap 42.2"
    ANSI_COLOR="0;32"
    CPE_NAME="cpe:/o:opensuse:leap:42.2"
    BUG_REPORT_URL="https://bugs.opensuse.org"
    HOME_URL="https://www.opensuse.org/"
    malcolml@mizz-piggy:~> which hostname
    /bin/hostname
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,189
    Blog Entries
    3

    Default Re: how to get the short hostname

    Here, "hostname" only gives the short name (unless I use "--long" as an option).

    But I seem to recall that this depends on how networking is done. When I use "wicked", it gives the short name. If I use "NetworkManager", it gives the long name.
    openSUSE Leap 15.1; KDE Plasma 5;

  4. #4
    Join Date
    Oct 2008
    Location
    Glasgow, Scotland
    Posts
    1,130

    Default Re: how to get the short hostname

    Do you get output something like this? --:
    Code:
    pla@pla3-TW:~> echo $HOSTNAME
    pla3-TW.suse
    
    pla@pla3-TW:~> cat /etc/hostname
    pla3-TW.suse
    
    pla@pla3-TW:~> grep pla3 /etc/hostname
    127.0.0.2       pla3-TW.suse   pla3-TW
    This is about name resolution. I suspect that using both upper and lower case in the hostname may be the source of the problem.
    ~Thank you for sharing an interesting problem.
    --
    slàinte mhath,
    rayH

  5. #5

    Default Re: how to get the short hostname

    Quote Originally Posted by eng-int View Post
    Do you get output something like this? --:
    Code:
    pla@pla3-TW:~> echo $HOSTNAME
    pla3-TW.suse
    
    pla@pla3-TW:~> cat /etc/hostname
    pla3-TW.suse
    
    pla@pla3-TW:~> grep pla3 /etc/hostname
    127.0.0.2       pla3-TW.suse   pla3-TW
    This is about name resolution. I suspect that using both upper and lower case in the hostname may be the source of the problem.
    the simple hostname works, is the short hostname that doesn't
    Code:
    pla@pla3-TW:~> cat /etc/hostname
    pla3-TW.suse
    pla@pla3-TW:~> echo $HOSTNAME
    pla3-TW.suse
    pla@pla3-TW:~> grep pla3 /etc/hostname
    pla3-TW.suse
    pla@pla3-TW:~> 
    pla@pla3-TW:~> hostname
    pla3-TW.suse
    pla@pla3-TW:~>

  6. #6
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    10,827
    Blog Entries
    1

    Default Re: how to get the short hostname

    Seems the long/short hostname bug I submitted this last year(952517) is no longer listed, it might have been cleared by someone although AFAIK it was never fixed.

    The hostname command doesn't always return what it's supposed to do,

    Recommend you submit a bug describing what isn't working correctly.

    My own tests in 42.2 suggest that the problem isn't fixed.
    In fact, except for the --help option, on my machine hostname isn't parsing the option correctly.... hostname is interpreting the option as a new command or service(according to the error).

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  7. #7
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,329
    Blog Entries
    15

    Default Re: how to get the short hostname

    Hi
    So with either wicked or Network Manager, hostname works fine even --help short/long options as well. Now I use real (fqdn) domain names, not suse, wonder if that may be the issue.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  8. #8
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    10,827
    Blog Entries
    1

    Default Re: how to get the short hostname

    Quote Originally Posted by malcolmlewis View Post
    Hi
    So with either wicked or Network Manager, hostname works fine even --help short/long options as well. Now I use real (fqdn) domain names, not suse, wonder if that may be the issue.
    Maybe, because I am configured with local names and not those issued by a nameserver.

    But, that shouldn't matter.
    When you execute the hostname command, it should be reading the local name, which may or may not be consistent with what the machine's network name(s) might be.
    If you want your macine's network name as seen by remote machines, then you do an nslookup(ie querying the nameserver which tells every machine how to identify your machine).

    Another variable is that this machine was upgraded from 42.1 and not installed new (42.2).

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  9. #9

    Default Re: how to get the short hostname

    Quote Originally Posted by malcolmlewis View Post
    Hi
    So with either wicked or Network Manager, hostname works fine even --help short/long options as well. Now I use real (fqdn) domain names, not suse, wonder if that may be the issue.

    as real (fqdn) domain names do you intend something like opensuse.org?
    yes, if I set hostname as opensuse.org it works in another way:
    evrything I set the domain it set to homenet.telecomitalia.it
    but it gives the hostname like the short hostname
    Code:
    pla@pla3-TW:~> hostname
    pla3-TW
    pla@pla3-TW:~> hostname -s
    pla3-TW
    pla@pla3-TW:~> hostname -d
    homenet.telecomitalia.it
    pla@pla3-TW:~>

  10. #10
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,329
    Blog Entries
    15

    Default Re: how to get the short hostname

    Quote Originally Posted by pier_andreit View Post
    as real (fqdn) domain names do you intend something like opensuse.org?
    Hi
    My hosts are tied to homelinux.org, if use use nslookup or host commands in my example mizz-piggy and the domain it will resolve...
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •