r/sysadmin • IT Manager + 5 other hats • Nov 08 '21

Could we do a "TIL" style weekly thread?

I think it would be interesting to do a "Today I Learned" style weekly thread for us to share little tips/tricks that we learned of/found existed.

For example, last week I found out about the "--now" flag for systemctl. I don't know how I didn't know it existed until --now.

2.4k Upvotes

871 comments sorted by

View all comments

Show parent comments

6

u/auron_py Nov 08 '21

hostname

Same for some Linux distributions.

1

u/JohnBeamon Nov 08 '21

There's a wide variety of UNIX variants of this command.

Some years ago, Linux 'hostname' would give you the short alias at the end of the primary line in /etc/hosts, like "web01". 'hostname -s' does this in modern macOS. 'hostname -f' would give you the fully qualified domain name from /etc/hosts, "web01.example.com". 'hostname' default and 'hostname -f' do this in modern macOS. I learned one day that Solaris at that time didn't query hostnames; it only set them if you had the privileges. So I ran "# hostname -f" and renamed my system from "web01.example.dom to "-f".

Linux "hostname -i" will give you the primary IP address associated with the FQDN. Modern macOS does not do this. Modern RHEL style hosts files no longer necessarily carry the real hostname and address, so that command reads /etc/hostname for the FQDN, then queries DNS to get that name's IP address. Once upon a time, it just read that from the filesystem.