Adding the IP-to-hostname mapping in /etc/hosts

Open the /etc/hosts file.

Add a line of text in the format ip - address localhost localhost.localdomain .

As shown in Figure 1 , enter 192.168.1.158 imctest imctest .IMC to map 192.168.1.158 to the host name imctest in the IMC domain.

Figure 1: Modifying the /etc/hosts file

how to add ip address to /etc/hosts linux

Save and close the file.

© Copyright 2016 Hewlett Packard Enterprise Development LP

  • Network Performance Monitoring
  • Challenges of Network Performance Monitoring
  • Network Device Monitoring
  • Agent Based Monitoring
  • Network Availability Monitoring
  • Network Uptime Monitoring
  • Packet Loss Monitoring
  • Network Activity Monitoring
  • Network Interface Monitoring
  • Network Testing Tools
  • Network Assessment Tools
  • LAN Management
  • Hardware Monitor
  • Disk Space Monitor
  • Hard Drive Monitor
  • CPU Monitor
  • Uptime Monitoring
  • CPU Usage Monitor
  • CPU Temperature Monitor
  • CPU Memory Disk Monitor
  • Memory Monitoring
  • Router Monitoring
  • Switch Monitoring
  • Switch Management Software
  • Ethernet Monitoring
  • URL Monitoring
  • LAN Monitoring
  • IP SLA Monitor
  • WAN Monitoring
  • WAN RTT Monitoring
  • VoIP Monitor
  • Network Latency Monitoring
  • System Performance Monitoring
  • Load balancer Monitoring
  • VPN Monitor
  • WMI monitoring
  • Windows Process Monitor
  • Wireless Network Monitor
  • Wireless Monitoring
  • WiFi Monitor
  • Wi-Fi Analyzer
  • WLC Monitoring
  • UPS monitoring
  • Printer Monitoring
  • Network Printer Management
  • HP Printer Monitoring Software
  • Canon Printer Monitoring Software
  • Network Device Discovery
  • Cisco Monitoring
  • Cisco Meraki Monitoring
  • Cisco ACI monitoring
  • Cisco UCS Monitoring
  • Cisco Port Monitor
  • Cisco Switch Monitoring
  • IBM monitoring
  • Syslog Monitoring
  • IPMI Monitoring
  • SNMP Monitoring Software
  • SNMP Trap Monitoring
  • 3Com Switch Port Monitoring
  • Fortigate Performance Monitoring
  • Juniper Network Monitoring
  • NOC Monitoring
  • Network Performance Test
  • Network Link Monitoring
  • Server Monitoring
  • Server Uptime Monitoring
  • Windows Server Monitoring
  • Server Health Monitor
  • Server Log Management
  • Systems Management
  • Hyper-V Management Tools
  • Linux Server Monitoring
  • VMware Monitoring
  • ESX Host Monitoring
  • Virtual Machine (VM) Monitoring
  • Virtual Network Management
  • VMware ESXi Monitoring Tool
  • vSphere performance monitoring
  • Hyper-V Monitoring
  • Hyper-V Performance Monitoring
  • Citrix XenServer Monitoring
  • Citrix Monitoring
  • Nutanix monitoring
  • Hyperconverged Infrastructure Monitoring
  • Virtualization Monitoring Dashboard
  • Operating System (OS) Monitoring
  • Windows Network Monitor
  • Microsoft Network Monitoring
  • Linux Network Monitor
  • Dell Server Monitoring
  • HP Server Monitoring
  • Event Log Monitoring
  • Exchange Monitoring
  • File/ Folder Monitoring
  • FTP Monitoring
  • Windows Service Monitoring
  • Service Monitoring
  • Process Monitoring
  • Network Mapping
  • Network Planning
  • Network Path Analysis (Beta)
  • Network Diagram Software
  • Grouping Network Elements
  • Custom Network Maps
  • Network Monitoring Dashboards
  • Network Discovery Tool
  • Network Topology
  • Network Topology Software
  • Network Visualization Definition
  • Network Visualization
  • Network Topology Mapper
  • Traceroute Tool
  • Network Fault Management
  • Network Fault Monitoring
  • Network Monitoring Alerts
  • Root Cause Analysis for Network Faults
  • Network Automation
  • Troubleshooting Network Issues
  • IT Workflow Automation
  • Network Troubleshooting Tools
  • Service Level Management Dashboards
  • Intent based Networking (IBN)
  • Data Center Monitoring
  • Data Center Management
  • Data Center Networking
  • 3D Datacenter Floor
  • SAN Monitoring
  • Storage Monitoring
  • Storage Raid Management
  • Tape Library Management
  • Storage Monitoring Dashboard
  • Storage Capacity Forecasting
  • Fabric Switch Management
  • NetApp Monitoring
  • Dell EMC Storage Monitoring
  • IBM Storage Monitoring
  • HPE Storage Monitoring
  • Scheduled Reports
  • Network Performance Reporting
  • Business Snapshot Based Reports
  • Custom Reports
  • Enterprise Monitoring Tools
  • Distributed Network Monitoring
  • Enterprise Network Monitoring
  • Smart Upgrade
  • Remote Network Monitoring
  • OpManager MSP
  • Network Traffic Analysis
  • Network Configuration Management
  • Firewall Log Management
  • IP Address Management
  • Switch Port Mapper
  • Applications Monitoring
  • Integrations
  • ServiceDesk Plus Integration
  • ServiceDesk Plus Cloud Integration
  • ServiceDesk Plus MSP Integration
  • ServiceNow Integration
  • Jira Service Management Integration
  • Slack Integration
  • Webhook Integration
  • Integration with Analytics Plus
  • Monitor IT on the move
  • Network Monitoring
  • Challenges of Network Monitoring
  • Network Software
  • Network Monitor
  • Network Management Software
  • Network Management Challenges
  • Network Management System
  • Network Performance Management
  • Network Incident Management
  • Network Administration
  • Cisco Management
  • Network Monitoring Tools
  • Real-time Network Monitoring
  • Server Management
  • Server Performance Management
  • Virtual Server Management
  • Agentless Network Monitoring
  • Disk Space Monitoring Challenges
  • Windows Service Monitoring Challenges
  • Network Map
  • Virtualization
  • Virtualization Best Practices
  • Virtualization Challenges
  • Hyper-V Performance Monitoring Challenges
  • Wi-Fi Management Best Practices
  • Network protocols
  • Network Routing
  • Layer 2 Protocols
  • Troubleshooting Network Latency
  • Virtualization Sprawl
  • Basics of Network Diagrams
  • Network Diagrams
  • Network Mapping Challenges
  • Network Optimization
  • Switching Loops
  • Route Flapping
  • Troubleshooting VLANs
  • Best Network Monitor
  • Best Free Network Monitoring Software
  • Solarwinds Alternative
  • PRTG Alternative
  • Zabbix Alternative
  • Whatsup Gold Alternative
  • Nagios XI Alternative
  • Spiceworks Alternative
  • Customizable Role-based Access Control
  • SAML Authentication

How to add a static entry in the hosts file?

  • Open your text editor in Administrator mode.
  • In the text editor, open C:\Windows\System32\drivers\etc\hosts.
  • Add the IP Address and hostname. Example: 171.10.10.5 opm.server.com
  • Save the changes.
  • Open terminal.
  • Use the nano command line text editor or a different one you have available to open the hosts file. The command with nano is as follows (the command will require your Linux user password)    sudo nano /etc/hosts
  • Add the appropriate changes in the hosts file. Example: 171.10.10.5 opm.server.com
  • Use the Control and 'X' key combination to save the changes.
  • » Network Monitoring
  • » Bandwidth Monitoring & Traffic Analysis
  • » Network Configuration Management
  • » Switch Port & IP Address Management
  • » Firewall Management
  • » Network Monitoring Software for MSPs
  • » IT Operations Management
  • » Application Performance Monitoring
  • Download  
  •   Live Demo
  •   Compare
  •   Get Quote
  •   Buy Now
  •   Download
  •   Request Demo

Adding private IP addresses to the /etc/hosts file manually

Edit the /etc/hosts file to add the private IP address and corresponding node name for each node in the cluster.

To edit the /etc/hosts file

Log in to each system as the root user.

Add the following entries to the /etc/hosts file:

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form .

How to set up Linux hosts file

jack-wallen

Linux is a very powerful operating system that is also one of the most flexible in the marketplace. That flexibility has always been a big selling point of the OS. Any user that doesn't like the way Linux works can always bend it to better fit their needs.

  • How to install Ubuntu Linux (It's easy!)
  • How to run a Windows app on Linux with Wine
  • How to get started with Git on Linux
  • How to kill a process in Linux

One very simple example of that is the Linux hosts file. Do understand that the hosts file isn't unique just to Linux. Windows and MacOS also make use of the hosts file. In fact, the MacOS hosts file is almost identical to that of Linux.

What is the hosts file?  

The hosts file makes it easy to map IP addresses to domain names. Sound familiar? It should, as that's exactly what DNS does today. But back in the day of ARPANET, there was no DNS, so there needed to be a means to map those addresses. That's where the hosts file comes into play. Given that DNS now takes care of that for us, why would you even need the hosts file?

The best example I can give of that is for a LAN-based network setup, where you might have servers or desktops you want to be able to reach without having to type a full IP address. You might have a server on your LAN that you regularly access with:

ssh [email protected]

You could map that IP address in the hosts file such that all you'd have to type is:

ssh jack@invoiceplane

It may not be less typing, but it certainly means you don't have to remember the IP address of that server. Instead, you use a nickname. This can be very helpful when you have a large number of servers to work with on your LAN. You can even work with those nicknames in your web browser. For instance, if you've installed Invoiceplan (which is an invoicing solution) on a server within your LAN and the document root of that service is /var/www/html/invoiceplane, you could map the IP address of the server to the nickname invoice and type invoice/invoiceplane in your browser's address bar to open the service.

Also:   The 5 best Linux distros for beginners: You can do this

How do you set this up? It's very easy. Let me show you how.

Requirements

The only things this will require are a running instance of Linux and some IP addresses to map. That's it, let's make some hosts magic.

1. Open the hosts file

Log in to your Linux machine and open a terminal window. To open the hosts file for editing, type the command  sudo nano /ets/hosts .

2. Add a new entry to hosts

Each line in the hosts file is a mapping for a unique IP address and is laid out in the form:

IP Address Nickname Domain Name

For instance (sticking with our Invoiceplane example), you could map the IP address 192.168.1.11 to the nickname invoice with a domain of invoiceplane.lan. That entry would look like this (and be added to the bottom of the file):

192.168.1.11 invoice invoiceplane.lan

With that entry saved to the hosts file, you could reach that server via three ways:

  • IP address (such as ssh 192.168.1.11)
  • Nickname (such as ssh invoice)
  • Domain name (such as ssh invoiceplane.lan) 

The one caveat to the domain name entry is that you won't be able to reach the server using that entry in a web browser (where you're limited to IP addresses and nicknames).

Also: These are the absolute best Linux distros for programming

3. Save and close

Once you've added the necessary entries to hosts, save and close it with the Ctrl+X key combination. With the file saved, you don't have to bother with restarting the OS, as the networking subsystem will pick up on the changes immediately.

Also: Cool things you can do with the Linux desktop that you can't do with MacOS or Windows  

For those new to Linux, you probably won't need to bother with the hosts file at first. Eventually, however, the deeper you dive into using Linux, you will most likely run into numerous situations where the hosts file is very much necessary.

 width=

How to turn on Private DNS Mode on Android (and why you should)

 width=

How to use Chromebook Quick Files (and why you should)

 width=

How to connect to a network share from your Chromebook

IMAGES

  1. How to Setup Local DNS Using /etc/hosts File in Linux

    how to add ip address to /etc/hosts linux

  2. Configure a static IP address in Ubuntu

    how to add ip address to /etc/hosts linux

  3. Linux'ta IP Adresi Nasıl Kontrol Edilir?: 12 Adım (Resimlerle)

    how to add ip address to /etc/hosts linux

  4. The Hosts File on Linux

    how to add ip address to /etc/hosts linux

  5. How to configure an IP range on Ubuntu 16/18

    how to add ip address to /etc/hosts linux

  6. /etc/hosts file

    how to add ip address to /etc/hosts linux

VIDEO

  1. How to add IP address in OPTILINK OLT || Bangla Tutorial

  2. How To Check & Change IP Address in CentOS 7

  3. How to Add a Secondary IP Address to an Existing VNIC of a Linux Instance in OCI

  4. How to Configure ip Address in Toshiba E- Studio2008A 2508A 3008A

  5. BLOCKING IP ADDRESSES in LINUX

  6. Assign Multiple Static IP Addresses To Single NIC In Linux

COMMENTS

  1. How Can I Find Out If a Host IP Address Is Valid or Invalid?

    A basic understanding of what IP addresses represent can help to determine their validity. There are also free utilities available on the web that allow users to enter a specific IP address to determine the network and broadcast addresses o...

  2. How Can Users Find the IP Address of an SMTP Server?

    In the Windows operating system, users can find the IP address of an SMTP server by using the “ping” command and the server’s hostname in the command prompt. The same process is used in the terminal of Unix-based systems such as Linux and M...

  3. How Do You Find the IP Address for Your Minecraft Server?

    The Internet Protocol address of a Minecraft multiplayer server depends on whether the server is being hosted on a internal or external network. With the former, the IP address is identical to the computer’s.

  4. Adding the IP-to-hostname mapping in /etc/hosts

    Add a line of text in the format ip-address localhost localhost.localdomain. As shown in Figure 1, enter 192.168.1.158 imctest imctest.IMC to map 192.168.1.158

  5. How to Add an IP to a Hostname File

    2. Adding an IP Address to a Hostname Through the /etc/hosts File.

  6. How to add a static entry in the hosts file?

    Open your text editor in Administrator mode. · In the text editor, open C:\Windows\System32\drivers\etc\hosts. · Add the IP Address and hostname. Example: 171.10.

  7. How to Edit Your Hosts File on Linux, Windows, and macOS

    Using the hosts file to map a domain to an IP address is particularly useful when you want to test your website without changing the domain DNS

  8. Adding private IP addresses to the /etc/hosts file manually

    Adding private IP addresses to the /etc/hosts file manually · Log in to each system as the root user. · Add the following entries to the /etc/hosts file: 192.168.

  9. How to Edit Hosts File in Windows, MacOS and Linux

    Add the targeted IP address followed by a space, then the domain name at the bottom of the hosts file, just like on the Windows 10 tutorial.

  10. Edit Etc/Hosts Linux

    IP_address canonical_hostname [aliases...] The IP address specified in the host file can be either an IPv4 or IPv6 address as long as it resolves to the

  11. How to set up Linux hosts file

    The hosts file makes it easy to map IP addresses to domain names. Sound familiar? It should, as that's exactly what DNS does today. But back in

  12. How to edit the Ubuntu hosts file and ping a domain name locally

    Since the loopback IP address of 127.0.0.1 points back to the local machine, mapping any domain name in the hosts file to this IP address will

  13. Adding a host name in the /etc/hosts file

    ... edit the /etc/hosts file. Add the following line to the /etc/hosts file: IP_address host_name aliases. IP_address is the IP address of the host. host_name is

  14. associate IP with hostname without editing /etc/hosts

    If the hosts: line of your nsswitch.conf includes only the classic files and dns keywords, or you need to assign names to IP addresses that are