Select Your Language
Infrastructure and management.
- Red Hat Enterprise Linux
- Red Hat Satellite
- Red Hat Subscription Management
- Red Hat Insights
- Red Hat Ansible Automation Platform
- Red Hat OpenShift
- Red Hat OpenStack Platform
- Red Hat OpenShift Container Platform
- Red Hat OpenShift Data Science
- Red Hat OpenShift Dedicated
- Red Hat Advanced Cluster Security for Kubernetes
- Red Hat Advanced Cluster Management for Kubernetes
- Red Hat Quay
- OpenShift Dev Spaces
- Red Hat OpenShift Service on AWS
- Red Hat Gluster Storage
- Red Hat Hyperconverged Infrastructure
- Red Hat Ceph Storage
- Red Hat OpenShift Data Foundation
- Red Hat Runtimes
- Red Hat JBoss Enterprise Application Platform
- Red Hat Data Grid
- Red Hat JBoss Web Server
- Red Hat Single Sign On
- Red Hat support for Spring Boot
- Red Hat build of Node.js
- Red Hat build of Quarkus
Integration and Automation
- Red Hat Application Foundations
- Red Hat Fuse
- Red Hat AMQ
- Red Hat 3scale API Management
How do I change the IP address/netmask and hostname on the command line WITHOUT rebooting the machine?
Here are some example configuration files:
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.
Current Customers and Partners
Log in for full access
New to Red Hat?
Learn more about Red Hat subscriptions
Using a Red Hat product through a public cloud?
How to access this content
Here are the common uses of Markdown.
Request a English Translation
Generating machine translation.
How to Set or Change System Hostname in Linux
Device or system hostnames are used to easily recognize a machine within a network in a human readable format. It is not much of a surprise, but on Linux system, the hostname can be easily changed by using simple command as “ hostname “.
Read Also: How to Set Static IP Address and Configure Network in Linux
Running hostname on its own, without any parameters, will return the current hostname of your Linux system like this:
If you want to change or set hostname of your Linux system, simply run:
Of course, you will need to replace “NEW_HOSTNAME” with the actual hostname that you wish to set. This will change the hostname of your system immediately, but there is one problem – the original hostname will be restored upon next reboot.
There is another way to change the hostname of your system – permanently. You might have already figured it out that this will require change in some configuration files and you will be correct.
Set System Hostname Permanently in Linux
Newer version of different Linux distributions such as latest Ubuntu , Debian , CentOS , Fedora , RedHat , etc. comes with systemd , a system and service manager that provides a hostnamectl command to manage hostnames in Linux.
To set system hostname on SystemD based distributions, we will use hostnamectl command as shown:
For Older Linux distributions, which uses SysVinit in short init , can have their hostnames changed by simply editing the hostname file located in:
You then have to add another record for the hostname in:
You then need to run:
On RHEL/CentOS based systems that use init , the hostname is changed by modifying:
Here is a sample of that file:
To keep a permanent hostname change the value next to "HOSTNAME" to the one of your hostname.
This simple article meant to show you a simple Linux trick and I hope that you learned something new.
Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.
How to Extract Tar Files to Specific or Different Directory in Linux
8 Useful ‘Debian Goodies Utilities’ for Package Management
How to Delete User Accounts and Their Home Directories in Linux
How to Find and Kill Running Processes in Linux
How to Set Time, Timezone and Synchronize System Clock in Linux
15 Must-Know FFmpeg Commands for Video, Audio & Image Conversion
5 thoughts on “How to Set or Change System Hostname in Linux”
I am using capital letters as hostname using the hostnamectl set-hostname command. But hostname is applying small cases.
Any solution for this?
Great help. Very clear. Thanks.
Thanks for the hostnamectl command
I want to delete the hostname.
Nice work, thanks
Got something to say? Join the discussion. Cancel reply
Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.
Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.
Save my name, email, and website in this browser for the next time I comment.
- Articles Automation Career Cloud Containers Kubernetes Linux Programming Security
7 ways to set your hostname in Fedora, CentOS, or Red Hat Enterprise Linux
%t min read | by Seth Kenlon (Editorial Team, Red Hat)
A hostname is a human-readable string that helps people refer to a computer by a familiar name, rather than by a number or unwieldy descriptors like, "the third one from the bottom of the second-to-last rack." Often, a hostname is set during the installation process, but there are times when it needs to be changed. On Linux, there are many ways to set a hostname, and this article aims to cover them all.
Before exploring the tools related to hostnames, though, you must understand the different contexts in which the term is used. There are potentially two designators of a system’s hostname: the computer’s administrator (a laptop’s owner, or a server’s root user) and the network (depending on protocols and settings). This factor can lead to confusion, because you might look at your computer’s hostname and see one value, only to find that the same computer is referred to as something different over the network.
There’s a historical reason for this situation. Long ago, before DNS, hosts on a network had to be defined locally in the file /etc/hosts . If there were 31 hosts on a network and a new one was added, then 32 hosts had to update their /etc/hosts file to reflect the correct IP address and corresponding hostname for each of their neighbors. This process didn’t scale well for bigger networked systems such as the World Wide Web (the Internet), and so DNS was invented, and the concept of hostnames largely was abstracted away from local computers to instead be managed by the network.
Today, the important hostname is the one the network uses. The hostname value in /etc/hosts is often set to localhost by default.
With this context in mind, here are all the different ways to manipulate a hostname on Linux.
[ Free download: Advanced Linux commands cheat sheet . ]
Change all three names with hostnamectl
The hostnamectl command from systemd can manipulate three varieties of hostnames:
- Transient : Received from network configuration.
- Static : Provided by the kernel.
- Pretty : Provided by the user.
A transient hostname can change as needed to avoid name collisions. For instance, if you name your computer penguin but there’s already another host with that name on the network, your network hostname becomes penguin-1 .
Static and pretty hostnames are a little like local variables: They’re used for activities occurring on the local machine, mostly as a convenience for the user, along with applications that need to know whether they’re running locally or remotely (for example, over a forwarded X session ).
When invoked without any arguments, hostnamectl returns the static and pretty names, plus some system information:
Change the static and pretty names in the GUI with GNOME Settings
If you want to set the static and pretty names in a desktop application, use GNOME Settings. To launch GNOME Settings, go to the Activities menu in the upper left corner of your GNOME desktop. Type Settings into the search field, or click the Show Applications icon on the left dock and find Settings in the application icons as shown below:
Change the static name with cockpit
Fedora, CentOS, and RHEL systems feature a web console application called Cockpit for monitoring and configuring local and remote machines. Using Cockpit, you can change the static hostname for your own machine, or any machine you administer (as long as it has Cockpit enabled).
First, install and enable Cockpit:
In the web console, click the System tab in the left column. Click the entry for Host name and edit the Pretty Host Name and (static) Real Host Name :
Change the static name in the hostname file
You can also set the static hostname manually by editing /etc/hostname . This file contains exactly one line by default. If you have not changed the hostname yet, then that line probably reads localhost.localdomain . If you have used hostnamectl to change the hostname already, then this file reflects that change.
Editing this file manually is not necessarily recommended, because it doesn’t update all the other hostname values the way hostnamectl does. For example:
Change the static name with nmcli
Another way to change a static hostname is through the command line interface for Network Manager, nmcli :
Change the transient name with sysctl
The sysctl command allows you to configure kernel parameters while Linux is running (that is, instead of at boot time). Your computer’s transient hostname is a kernel parameter, so you can modify it with this command:
Change the transient name with hostname
The hostname command from the util-linux package is a simple tool to query and set the transient hostname.
To query your current hostname:
Be careful with /etc/hosts
The /etc/hosts file is mostly historic, although it is used by some applications and protocols, and can be a useful method for creating shortcuts to hosts you use often. You can use it to set a hostname, but usually, you’re just creating an alias to localhost at IP address 127.0.0.1 (your computer’s network loopback address).
For example, if you change /etc/hosts from the default entries like this:
Follow the conformity convention
As you can tell from the iterations within this article, a computer’s hostname can get confusing should you use too many methods to set it, or if you change it frequently. While nothing enforces uniformity across hostname types, it’s a convention to keep everything the same on each computer.
Choose a memorable name and use it for your pretty name. Let the static and transient names be derived from that. Just as importantly, in a large network, choose meaningful names. For instance, all upper management computers may be named after a D&D monster, while all computers in the IT department may be named after a famous starship, and so on. Using a naming schema helps avoid name collisions and provides context to an otherwise dizzying list of network hosts.
Seth Kenlon is a UNIX geek and free software enthusiast. More about me
Try Red Hat Enterprise Linux
Download it at no charge from the red hat developer program., related content.
How to Change the Hostname in Linux
Want to change your Linux machine's hostname but can't figure out how? Here's a step-by-step guide to walk you through the process.
There are plenty of reasons why you may want to change the hostname of your Linux system. Unfortunately, changing your hostname is not exactly an intuitive process. Don’t worry, though, we’re going to show you how you can change your machine's hostname in less than a minute with just a few clicks and commands.
Although this guide uses Ubuntu to demonstrate the steps required to change the hostname, the commands should work on other Linux distributions as well.
What Is a Hostname?
All computers connected to a network have an IP address and a hostname. The hostname is the name used to identify a computer on a network in “human-readable” form. Without the hostname, when you try to locate a computer on a network, all you would see are numbers, or IP addresses, like 127.0.0.1.
While IP addresses are a great way for computers to identify each other, they don’t really do much to help people identify specific computers. For example, let’s say you want to set up a network shared folder on your Ubuntu system . If someone else wants to access that folder, they will be able to find it much easier if they see your computer on the network as “larry-laptop” rather than “192.168.0.24”.
One common reason for switching hostnames is to avoid duplicate names on the same network. Ubuntu, for example, sets the hostname of all new installations to “ubuntu” by default. If you have more than one computer on your home network and want them all running Ubuntu Linux, you’re going to have to change the default hostnames to avoid problems.
How to Change the Hostname Through System Settings
The easiest way for most people to change the hostname on a Linux machine is to simply go into the system settings and click on About . Your computer’s current hostname will appear as the first item on the list, under Device Name , or similar labels on other distros.
It is not immediately obvious, but you can click on the Device Name item and a dialog box will appear, allowing you to rename your device. Simply type whatever name you would like to use into the dialog and then click on Rename .
The new hostname will be permanently set and your computer will identify itself on your network with the new name.
Change the Hostname Using the Linux Terminal
The options that appear in your system settings depend on the desktop environment you are using. The process described above will work with Ubuntu’s default GNOME desktop. If you have switched your desktop environment or window manager, however, you may not have the option to change the hostname in system settings.
If that's the case, you can change your hostname by opening a terminal window and entering one simple command.
The hostnamectl command will allow you to view and change the hostname on most other Linux distributions. Simply open a terminal window and enter the following command to view your current hostname along with a few related details:
To change the hostname, enter the following command, replacing new-hostname with the name you’d like to use:
To verify that the new name has been set, type hostnamectl again and you’ll see the updated information.
Again, the command-line method for changing the Linux hostname should work on nearly all modern Linux distributions, not just Ubuntu.
Learn More About How Linux Networks Work
Now that you’ve successfully set your computer’s hostname, it's time to dip your toes into networking with Linux. If you’re having other network problems with your system (or even if you’re just curious), the ss command in Linux will help you troubleshoot the errors.
How to Change HostName and IP-Address in CentOS / RedHat Linux
You can use any one of the following methods to change the hostname and/or ip-address on RedHat related distributions.
If you want to change only the hostname you can either do it from command line, or from GUI as explained below.
To change the ip-address along with the hostname, follow the steps shown below.
I. Change HostName From Command Line
1. use hostname command to change hostname.
In this example, we’ll change the hostname from dev-server to prod-server.
hostname command by default will display the current hostname as shown below:
The following will change the hostname to prod-server.
Once the hostname is changed, verify that it has changed the hostname successfully. As you see below, it has changed the hostname to prod-server
2. Modify the /etc/hosts file
If you have entries in the /etc/hosts file with the old hostname, you should modify it.
For example, the entry for 127.0.0.1 line in the /etc/hosts file will still show the old hostname. In this example, it shows as dev-server.
Modify this file, and set the new hostname here. For example, change dev-server to prod-server as shown below.
3. Modify the /etc/sysconfig/network file
The /etc/sysconfig/network file also has an entry for HOSTNAME. Change the value here as shown below.
4. Restart the Network
Restart the network service, if you want any other services that are using the hostname to pickup the changes.
If this is not a production system, you can also reboot the system to make sure the hostname is changed properly, and the system is picking it up properly during startup.
II. Change Hostname from UI
If you have desktop related utilities installed on your system, you can change the hostname from the GUI.
Execute system-config-network from the command line.
This will display the “Network Configuration” GUI. Go to the “DNS” tab and change the hostname from here as shown below.
III. Change the IP-Address
1. change ip-address temporarily using ifconfig.
You can change the ip-address of the server using ifconfig command as we discussed earlier. For example, the following changes the ip-address of the server on eth0 interface to 192.168.1.2
2. Change ip-address Permanently
Under the /etc/sysconfig/network-scripts directory, you’ll see file for every network interface on your system. For example, if your interface is “eth0”, you’ll see ifcfg-eth0 file under this directory.
Modify the ifcfg-eth0 file and change the IPADDR field accordingly as shown below to change the ip-address.
3. Modify /etc/hosts file
If you’ve defined the ip-address in the /etc/hosts file, make sure to change those also. For example, if you have a FQDN that was pointing to the old ip-address in the /etc/hosts file, change it to the new ip-address. Depending on how you’ve configured your system, you might not have to do this step.
Finally, restart the network service, for the system to pick-up the changes.
If this is not a production system, you can also reboot the system to make sure the hostname and ip-address is changed properly, and the system is picking it up properly during startup.
If you enjoyed this article, you might also like..
Comments on this entry are closed.
Will this work for VM also? I am looking to make my VM’s IP public. Is that possible using the above mechanism.
Simple but very useful material
Please note that just changing the host name as described in 1 will not survive a reboot. That would change the host name only on that session.
The other options are valid.
Nice Article ..
Good stuff. I noticed one spelling mistake…
II. Change Hostname from UI –> I think it should be GUI. Can you please correct it?
Don’t forget that to ensure that the hostname is persistent against reboots that you will also have to change the hostname in the /etc/sysconfig/network file on RHEL/CENTOS systems.
Thanks dear, it help lot for me.
system-config-network is the best way to setup the hostname permanently, this would be ideal if you are you RHEL also you do not need any script in startup to save the changes permanently.
#cat /etc/hosts (to change the hostname )
before ediitng any file we have to take the back up
here u have to modify the ipaddress,gateway,subnetmask
here we have to modify the
Next post: How Much Swap Space to Add for Oracle Database on Linux
Previous post: How to Monitor MongoDB using Nagios check_mongodb Python Plugin
- Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting
- Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
- Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor
- Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well
- 15 Essential Accessories for Your Nikon or Canon DSLR Camera
- 12 Amazing and Essential Linux Books To Enrich Your Brain and Library
- 50 UNIX / Linux Sysadmin Tutorials
- 50 Most Frequently Used UNIX / Linux Commands (With Examples)
- How To Be Productive and Get Things Done Using GTD
- 30 Things To Do When you are Bored and have a Computer
- Linux Directory Structure (File System Structure) Explained with Examples
- Linux Crontab: 15 Awesome Cron Job Examples
- Get a Grip on the Grep! – 15 Practical Grep Command Examples
- Unix LS Command: 15 Practical Examples
- 15 Examples To Master Linux Command Line History
- Top 10 Open Source Bug Tracking System
- Vi and Vim Macro Tutorial: How To Record and Play
- Mommy, I found it! -- 15 Practical Linux Find Command Examples
- 15 Awesome Gmail Tips and Tricks
- 15 Awesome Google Search Tips and Tricks
- RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams
- Can You Top This? 15 Practical Linux Top Command Examples
- Top 5 Best System Monitoring Tools
- Top 5 Best Linux OS Distributions
- How To Monitor Remote Linux Host using Nagios 3.0
- Awk Introduction Tutorial – 7 Awk Print Examples
- How to Backup Linux? 15 rsync Command Examples
- The Ultimate Wget Download Guide With 15 Awesome Examples
- Top 5 Best Linux Text Editors
- Packet Analyzer: 15 TCPDUMP Command Examples
- The Ultimate Bash Array Tutorial with 15 Examples
- 3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
- Unix Sed Tutorial: Advanced Sed Substitution Examples
- UNIX / Linux: 10 Netstat Command Examples
- The Ultimate Guide for Creating Strong Passwords
- 6 Steps to Secure Your Home Wireless Network
- Turbocharge PuTTY with 12 Powerful Add-Ons
- Linux Tutorials
- Sed Scripting
- Awk Scripting
- Bash Shell Scripting
- Nagios Monitoring
- IPTables Firewall
- Apache Web Server
- MySQL Database
- Perl Programming
- Google Tutorials
- Ubuntu Tutorials
- PostgreSQL DB
- Hello World Examples
- C Programming
- C++ Programming
- DELL Server Tutorials
- Oracle Database
- VMware Tutorials
About The Geek Stuff
Copyright © 2008–2023 Ramesh Natarajan. All rights reserved | Terms of Service
Change Linux Hostname and IP Address
Sometimes you might want to change the Linux hostname and IP address assigned to a Linux machine. In this article, we will be looking at Linux hostname and IP address change.
Change Linux Hostname
Change linux ip address.
Check the current hostname on the server
To change the hostname, give new hostname in the single quotes
Verify new hostname change
On a Linux minimal install, you can assign new IP address by editing /etc/sysconfig/network-scripts/ifcfg-eth3 file
Restart the network
Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How to point a hostname to an ip address
I have a running webserver, that can be called via http://localhost:9000/ . What I am trying to archive is, instead of calling http://localhost:9000/ , I would like to call http://repo.sweetsoft/ . I've tried to modify the hosts file as follow:
As you can see, I've added the last line but it does not work. What am I doing wrong?
- 1 You cannot add port number in /etc/hosts file; only IP address. – FedKad Oct 13, 2019 at 10:13
- Aha ok. Thanks a lot – zero_coding Oct 13, 2019 at 10:16
2 Answers 2
There is a misunderstanding about hosts file here.
First of all, hosts file have precedence over DNS on most operating systems, you can define them on Linux/Unix operating systems and macOS in /etc/hosts and c:\windows\system32\drivers\etc\hosts on Windows .
So when you add a record in your hosts file like:
and try to open http://repo.sweetsoft/ in your browser, it doesn't send any DNS query to the outside world and uses this entry from your hosts file.
Keep in mind this only works for A record (resolving a name or domain address to an IPv4 address) and AAAA record (resolving a name or domain address to an IPv6 address) and you can not define TXT or MX records for example.
But port numbers are in a different network layer, hosts file only understands names (like repo.sweetsoft) and IP addresses, it's layer 3 and 4 in ISO model (Network/Transport) but port numbers are in layer 7 (application layer).
Check OSI model
OSI vs TCP/IP model
Since hosts file or DNS protocol are not aware of application layers, they have no idea about port numbers too.
Your configuration by adding 127.0.0.1:9000 to your hosts file is like adding port numbers to DNS A records.
After this clarification, you can fix this issue in multiple ways:
- Running your application on port 80. Fixes your issue and removes any ambiguity.
- Forward port 80 to port 9000 on your machine via iptables
- Forward port 80 to port 9000 on your machine via socat:
If you can't change your application port, socat will be the easiest way.
For day to day usage, you can write a systemd service file to run it in the background.
- 1 Isn't TCP port number in transport layer instead of application layer? – Billy T Jan 12, 2023 at 19:50
You can go with a different approach:
- 127.0.1.1 sweetsoft repo.sweetsoft in /etc/hosts
- Direct repo.sweetsoft:80 and 127.0.0.1:9000 in your HTTP server (AFAIK, Apache can make it using VirtualHost Reference ).
However, it seem to me you are using an app development server. Using Apache to proxy may be an overkill.
You must log in to answer this question.
Not the answer you're looking for browse other questions tagged networking server ..
- The Overflow Blog
- Exploring the inclusive tech revolution sponsored post
- Would you trust an AI bot to find the fix for vulnerabilities in your code?
- Featured on Meta
- Site maintenance - Saturday, February 24th, 2024, 14:00 - 22:00 UTC (9 AM - 5...
- Upcoming privacy updates: removal of the Activity data section and Google...
- Notifying users about the policy on AU concerning AI-generated content
- AI-generated content is not permitted on Ask Ubuntu
Hot Network Questions
- Was Alexei Navalny in 2020 poisoned with Novitschok nerve agents by Russia's Federal Security Service?
- Shimano clipless pedals and cleats
- What is a system?
- What exactly is transmission time?
- Determining why my proof depends on the axiom of choice
- Why are my new switches operating in reverse?
- Were Mr. Darcy and Mr. Bennet formally equal in rank?
- Is it possible for an animal to have a plant stage in its life cycle?
- Can I walk to the Netherlands from Weeze?
- What is the technical definition of "clone" that makes the K1810VM88 (К1810ВМ88) not a clone of the 8088?
- Can a subshell create a subprocess?
- Novel - Disguised alien Tock Von visits Earth, meets a girl, gets committed to a psychiatric hospital
- The problem of philosophy?
- Is this diesel gun concept feasible?
- What does "rob it of a few petrified spars" mean in "Pride and Prejudice"?
- How does this code work?
- Lots of electrical noise at boost converter output
- Odd use(s) of "bauen"
- Markets in Germany with a large selection of seafood
- Enumerate the Phat-fingered-lights-out numbers
- Why is there a phasor in the transfer function of an ideal LPF?
- ogr2ogr: Unable to import shapefile with '-lco RFC7946=YES' parameter to the PostGIS db
- Compute the phat-fingered double-bit-flip distance
- Partial derivative of the Gibbs free energy with respect to temperature at constant enthalpy
5 ways to resolve hostname to ip address in linux
Nov 2, 2021
We all know we can use ping command to get the ip address of a hostname , but sometimes we need to do it for multiple hosts.
This post shows you how to resolve hostname to ip address in several ways , like use command ping or getent or host ,etc, so that we can do it via bash script.
Method 1: use ping command
ping command is always our friend , it’s very reliable and intuitive .
Let me explain above command a little bit:
- -q Quiet output. Nothing is displayed except the summary lines at startup time and when finished
- -c1 only send one ping packet
- -t1 set TTL to 1 , if not pingable return immediately
- tr -d '()' removed Parentheses around ip address
- awk ... print ip address
Method 2: use getent command
The getent command displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf.
For IP v6 , you can use
For both IP v4 and v6:
Let see one example:
Here the domain has 2 IP addresses and a CNAME(kind of alias) new-fp-shed.wg1.b.yahoo.com points to one of these 2 IP addresses randomly.
So to get one of the IP address directly, below command can be used.
Method 3: use host command
host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options.
Similarly we can use below command to get one of the IP v4 address
Method 4: use dig command
Dig is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig.
Method 5: use resolveip command
The resolveip utility resolves host names to IP addresses and vice versa. This command is easy to use but seems not available by default.
Method 6 : use command nslookup
Nslookup is a program to query Internet domain name servers.
To get one of the IP v4 addresses only , you can try below command:
Bash script example
Where 2>/dev/null suppressed errors.
How to find the IP address in CMD using hostname?
In networking, each system has its own identity denoted by a few numerical digits known as IP address, however, remembering them can be a difficult task, especially when there are a large number of systems. For example, each website running on the Internet has an IP address, so that other systems can call them whenever needed but do you think it is feasible to remember the long series of numbers for each website we visit?
The answer is “No”, hence corresponding to each IP address we can set a human-readable label. That’s the reason why when we need to visit Google we use its domain name Google.com instead of its IP address. Similarly, in our local networks, we have hostnames for each PC alongside IP addresses. This hostname allows us to connect PC if we don’t know the IP address.
However, if you don’t know the IP address corresponding to some hostname and want to find that, here in this tutorial we learn how to use the Command prompt or PowerShell to translate a hostname or Domain name to its corresponding IP address.
Step 1: Open Command Prompt
Well, as the title of this tutorial suggests we are going to use the command line on Windows to find the IP address associated with a hostname. Therefore, open the command prompt or PowerShell, click on the Windows Start button search for “ CMD ” as it appears click to run the same.
Alternatively , we can use the Windows key + R to open the Run dialog, typing “ cmd ,” and pressing Enter to access the Command prompt.
Also, learn – how to find a Wi-Fi password using the command prompt in Windows 11.
Step 2: Ping and NSLookUp
There are two common commands that we can use to find the IP address associated with a hostname, one is PING , and the other is NsLookUP , let’s see how to use them.
Ping Command to find the hostname IP
On your command prompt, and those are use PowerShell, run the “ ping ” command along with the hostname of the PC or device that IP address you want to identify. For example, our local hostname is “h2smedia” then the command to find its IP address:
ping hostname or domain
If you want to get IPv4 then add the ‘ -4 ‘ parameter in the above command, it will be like this:
Similarly, we can use any domain name to find its corresponding IP:
Like ping, we can use the NSLookUp which is a specialized command line tool for querying Domain Name System to obtain the mapping between domain name and IP address:
nslookup hostname or domain
Step 3: View the IP Address
Well, the ping command as you run it, the system will start pinging the remote system or device to send packets to the mentioned hostname and in return will display the IP address along with information on whether the remote or local system is in reach or not. To identify the IP address just look for the line that starts with “Reply from” followed by the IP address.
Similarly, in the NSlokup command, you will directly have the Ip-address value as output, instead of confirming whether the host is reachable or not.
Step 4: Note the IP Address
Once you have the IP address on the command prompt display, you can start using it to either connect the device available in your network or perform any troubleshooting task with the help of any third-party software such as Wireshark .
- Check if Virtualization is Enabled via Command Prompt (CMD)
- Install PHP on Windows 10 | 11 using the Command prompt
- How to start Firefox in safe mode with the command prompt?
- How to create multiple folders in the Windows command prompt?
Inside Kodak TV Factory: A Glimpse into the Manufacturing Process
How to Reset Windows 11: A Step-by-Step Guide to Restore Your PC to Factory Setting
What is the DPC watchdog violation on Windows 11? Why this is caused and the possible fixes
How to Check if Virtualization is Enabled via Command Prompt (CMD)
Single Command to Install Virt-viewer on Windows 11 or 10
How to enable Virtualbox nested VTX/Amd-V on Windows or Linux
Leave a comment cancel reply.
This site uses Akismet to reduce spam. Learn how your comment data is processed .
Reach out to us for sponsorship opportunities or suggestions
Problems are meant to be solved.
© 2024 H2S Media