December 22, 2024
Tutorials

How to View Hosts File in Linux

View hosts file in Linux


In Linux, the host file is a text file that contains important details such as website names and IP addresses. It allows your machine to find websites without relying on a DNS server. Viewing and inspecting the host file is essential for troubleshooting and addressing network problems.

Furthermore, It also helps you allow or block specific websites on your system. Thus, you can efficiently manage and configure your network through the Hosts file.

This post aims to explore how to view the Hosts file in a Linux-based system.

How to View Hosts File in Linux (Ubuntu 24.04)?

Use these methods to view Hosts files in Linux-based systems:

Method 1: View Hosts File via “cat” in Ubuntu 24.04

Method 2: View Hosts File with “Nano” in Ubuntu 24.04

Method 3: View Hosts File using “vim” in Ubuntu 24.04

Method 4: View Hosts File through “File Manager” in Ubuntu 24.04

Method 1: View Hosts File via “cat” in Ubuntu 24.04

The “cat” command is the simplest method to inspect the Hosts file using the Linux terminal:

cat /etc/hosts

The “cat” command will display all the content in the host file on your terminal screen.

Alternatively, run the below command to print the content in the host file with the line number:

nl /etc/hosts

You can easily find the specific details in the host file by their line numbers.

Method 2: View Hosts File with “Nano” in Ubuntu 24.04

In Linux-based operating systems like Ubuntu 24.04, Nano is a simple and commonly used text editor that allows you to view and edit files. To open the Hosts file using Nano, run the command:

sudo nano /etc/hosts

When you open the Hosts file using the Nano editor, it will display all the existing content. The example is attached below:

It is a user-friendly text editor that can be used to view and manipulate your host files in Linux systems.

Method 3: View Hosts File using “vim” in Ubuntu 24.04

The “vim” text editor is powerful and advanced in a Linux-based system. If you want to view your system Hosts file using “vim”, ensure that it is installed on your system:

sudo apt install vim -y

Once you have confirmed the “vim” installation on your system. You can view the Hosts file by executing the below command:

sudo vim /etc/hosts

Like other text editors, “vim” can be utilized for viewing and editing Hosts files in your Ubuntu 24.04 or other Linux systems.

Method 4: View Hosts File through “File Manager” in Ubuntu 24.04

If you prefer to use a graphical tool, such as “File Manager” to view your Ubuntu 24.04 Hosts file, here are a few steps:

  • Open your system “Files”.
  • Navigate the “other locations”.
  • Select your system “Drive”.

In your system drive (i.e. ubuntu), navigate to the “/etc/” directory:

Locate the Hosts file in the “/etc/” directory, as shown below:

Double-click on the “Hosts” file or right-click to choose “Open with text editor” to view the Hosts file:

The above are the most commonly used methods to view and edit Hosts file in Linux-based systems, including Ubuntu 24.04.

Conclusion

In Linux systems like Ubuntu 24.04, you can view your system Hosts file using various methods. You can use a Linux terminal or File Manager to view the existing content of Hosts file. The “cat”, “nano”, and “vim” are the terminal-based commands. If you do not want to use the terminal, you can use the “File Manager”.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video