Local name server linux

Linux Find Out My Machine Name/Hostname

The procedure to find the computer name on Linux:

  1. Open a command-line terminal app (select Applications > Accessories > Terminal), and then type:
  2. hostname
    OR
    hostnamectl
    OR
    cat /proc/sys/kernel/hostname
  3. Press [Enter] key

Linux find hostname using hostnamectl

Type the following command if you are using systemd based Linux distro:
$ hostnamectl

It is possible to filter output using the grep command:
$ hostnamectl | grep ‘hostname’
OR simply use the cat command as follows too:
$ cat /proc/sys/kernel/hostname

Linux find computer name using hostname command

At the terminal type hostname command:
$ hostname
Sample outputs
vivek-laptop.nixcraft.in
Where,

  • vivek-laptop : You computer name.
  • nixcraft.in : Your dNS domain name.
  • vivek-laptop.nixcraft.in : Your computer name with Fully Qualified Domain Name (FQDN).

To see the domain part of the FQDN (Fully Qualified Domain Name), enter:
$ dnsdomainname
Sample outputs:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

How Do I Change My Hostname?

The hostname commands set the host name using the following syntax. Please note that only the super-user / root can change the names. To switch to the root user by typing su – and entering the root password, when prompted.
# hostname newhostname.nixcraft.in
# hostname laptop.nixcraft.net.in
# hostnamectl set-hostname laptop.nixcraft.in
You need to edit /etc/hostname or /etc/sysconfig/network file to set hostname permanently. See our previous FAQ about changing hostname using configuration files.

Conclusion

The hostnamectl command may be used to query and change the system hostname and related settings on modern Linux distros such as Debian, Ubuntu, CentOS/RHEL, Fedora, Arch Linux and more.

Getting help

I strongly suggest that your read the man pages by typing the man command:
$ man hostname
$ man hostnamectl
$ hostnamectl —help

Источник

Linux setting hostname and domain name of my server

How to use hostnamectl command

If you are using systemd based distro such as RHEL/CentOS 7.x, Fedora latest, Ubuntu Linux 16.04 LTS, Debian 9.x+, Arch Linux and more, use hostnamectl command. To see current hostname, run:
$ hostnamectl
To change hostname to foo, run:
$ hostnamectl set-hostname ‘foo’
$ hostnamectl

Читайте также:  Нет маленького значка windows

A note about GUI tools

If you are using Red Hat or Fedora Linux (older version) use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name:
# redhat-config-network
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Setup/replace HOSTNAME
HOSTNAME=web.nixcraft.com
Where, web is hostname and nixcraft.com is your DNS domain name.

If you are using Debian Linux

You need to edit /etc/hostname file and put hostname.domain.com in this file:
# vi /etc/hostname
Set or replace hostname:
web.nixcraft.com

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Debian, Suse and other Linux distro support GUI tool called network-admin. Type following command and click on DNS tab > Setup hostname and domain name:
$ network-admin

Please note that you must have properly configured DNS server to work FQDN based hostname. See how to configure Linux as a dns client.

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

thank you bro. it is really helpfull

I think we have to restart the network service after making the changes.

service network restart

Thank you so much for this information. It was very useful for me!

Do you also want to tell in your artice about restarting services so the new changes can come to effect? At the moment the article is half baked.

Thanks a lot from a CentOS newbie.

hi I want to learn linux .what step should i follow?

Step1: Change the New Values in the Host file
[root@erp

]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.0.1 erp.myappsdba.com erp
[root@erp

Step2: Change the New Values in the network file
[root@erp

]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=erp.myappsdba.com
GATEWAY=192.168.0.3

Step3: Change the New Values in the sysctl.conf and resolv.conf files
[root@erp

]## cat /etc/sysctl.conf
kernel.hostname=erp.myappsdba.com
kernel.domainname=myappsdba.com

[root@erp etc]# cat /etc/resolv.conf
search myappsdba.com
nameserver 192.168.0.7
nameserver 192.168.0.2
option attemts : 5
option timeout :15
[root@erp etc]#

Step4:Ping the Host Name or Changed IP Address.
[root@erp etc]# ping myappsdba.com
PING myappsdba.com (192.168.0.1) 56(84) bytes of data.
64 bytes from fortedc.myappsdba.com (192.168.0.1): icmp_seq=1 ttl=128 time=1.06 ms

Step5:Restart the Network or Reboot the system for effecting the changes
[root@erp

]# service network restart

Thanks for the good article. @Nilesh Thanks dude

Please help me connect to server with a Linux netbook. There is a box for the name of the server… but I don’t know it.

Источник

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

DNS (Domain Name System or Service) is a hierarchical decentralized naming system/service that translates domain names into IP addresses on the Internet or a private network and a server that provides such a service is called a DNS server.

This article explains, how to setup a local DNS using the hosts file (/etc/hosts) in Linux systems for local domain resolution or testing the website before taking live.

For example, you may want to test a website locally with a custom domain name before going live publicly by modifying the /etc/hosts file on your local system to point the domain name to the IP address of the local DNS server you configured.

The /etc/hosts is an operating system file that translate hostnames or domain names to IP addresses. This is useful for testing websites changes or the SSL setup before taking a website publicly live.

Attention: This method will only work if the hosts have a static IP address. Therefore ensure that you have set static IP addresses for your Linux hosts or nodes running other operating systems.

For the purpose of this article, we will be using the following domain, hostnames and IP addresses (use values that apply to your local setting).

Understanding Name Service Switch in Linux

Before moving any further, you should understand a few things about another important file that is /etc/nsswitch.conf. It provides Name Service Switch functionality which controls the order in which services are queried for name service lookups.

The configuration is based on order; if files is before dns it means the system will query the /etc/hosts file before checking DNS for name service requests. But if DNS is before files then the domain lookup process will consult DNS first before any other appropriate services or files.

In this scenario, we want to query the “files” service. To check the order, type.

Check Name Service Switch

Configure DNS Locally Using /etc/hosts File in Linux

Now open the /etc/hosts file using your editor of choice as follows

Then add the lines below to the end of the file as shown in the screen shot below.

Next, test if everything is working well as expected, using the ping command from Host 1, you can ping Host 2 using it domain name like so.

Ping Domain Locally

On the Host 2, we have setup Apache HTTP server. So we can also test if the name translation service is working as follows by going to URL http://centos.tecmint.lan.

Check Domain Locally

Important: To use the domain names on any host on the network, you must configure the above settings in its /etc/hosts file.

What does this mean, in the above example, we only configured the hosts file of Host 1 and we can only use the domain names on it. To use the same names on Host 2, we have to add the addresses and names to its hosts file as well.

Lastly, you should use host command or nslookup command to test if the name translation service is actually working, these commands only query DNS and overlook any configurations in /etc/hosts and /etc/nsswitch.conf files.

You may also like to read these following related articles.

That’s it! Do share any additional thoughts or questions about this topic with us, via the comment section below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Читайте также:  Как отключить обозреватель компьютеров windows 10
Оцените статью