Introduction
Obtaining basic host information is essential for system administration tasks. This article covers commands to display the hostname, host details, IP addresses and system uptime.
Table of contents
Open Table of contents
Host Name
Understanding the host’s identity is crucial. Here are various ways to retrieve the hostname:
Using hostname
Command:
hostname
Display the Fully Qualified Domain Name (FQDN):
hostname -f
Reading /etc/hostname
file:
cat /etc/hostname
Reading hostname
file in /proc
pseudo-Filesystem:
cat /proc/sys/kernel/hostname
Using HOSTNAME
environment variable in Bash:
echo $HOSTNAME
Note: The
HOSTNAME
variable is set in Bash. It does not exist in other shells likesh
,zsh
,csh
,tcsh
.
More Details
For comprehensive host information, the hostnamectl
command is handy:
hostnamectl
Example Output:
Static hostname: my-machine
Icon name: computer-desktop
Chassis: desktop
Machine ID: 1234567890abcdef
Boot ID: 1234567890abcdef
Operating System: Linux
Kernel: 5.10.0-123-generic
Architecture: x86-64
Alternatively, you can use uname -a
to retrieve details like hostname, kernel version, and architecture:
uname -a
Example Output:
Linux my-machine 5.10.0-123-generic #46-Ubuntu SMP Tue Aug 3 09:17:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
IP Address
Knowing the IP address of a Linux system is vital. Here are some methods to obtain it:
- Primary IP Address:
hostname -I
Output:
192.168.0.100
- Secondary IP Address:
hostname -i
Output:
127.0.1.1
More Network Interface Details
For a deeper dive into network interfaces, the ip
command is invaluable:
ip addr show
Here’s an example output snippet:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:1e:6a:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
Additional ip
command usage examples:
ip addr
: Display detailed information about all network interfaces.ip addr show
: Display the IP address of the currently active network interface.ip addr show eth0
: Display the IP address of the specific network interface named eth0.ip a
: A shorthand forip addr show
.
Another command for displaying and configuring IP addresses is ifconfig
.
ifconfig
Show only the loopback interface:
ifconfig lo
Show only the eth0 interface:
ifconfig eth0
Show all interfaces:
ifconfig -a
Show only the IPv4 addresses:
ifconfig | grep 'inet addr'
Show only the IPv6 addresses:
ifconfig | grep 'inet6 addr'
System Uptime
Knowing how long a system has been running can provide valuable insights:
uptime
Example Output:
12:05:43 up 1 day, 8:46, 19 users, load average: 0.76, 0.43, 0.26
This output indicates that the system has been running for 1 day and 8 hours, with 19 users logged in. The load average provides insight into CPU usage.
Conclusion
Understanding the basics of Linux system information retrieval is fundamental for effective system administration. With commands like hostname
, hostnamectl
, ip
, ifconfig
, and uptime
, administrators can gather crucial details about the system’s identity, network configuration, and uptime, facilitating efficient management and troubleshooting.