LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 02-12-2017, 06:42 PM   #1
drillsar
Member
 
Registered: Jan 2017
Posts: 144

Rep: Reputation: Disabled
Hostname and DNS?


First question how do you change hostname on centos?

Also is it needed?

Now lets say my website is www.example.com
External IP is 66.19.240.12
Internal IP is 192.168.1.4

hostname servix

I am guessing in /etc/hosts

127.0.0.1 localhost
66.19.240.12 or is it 192.168.1.4 servix.example.com servix

and in FreeDns A Record should point to 66.19.240.12 both example.com and www?

Or this isn't needed?
 
Old 02-12-2017, 08:29 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,358
Blog Entries: 28

Rep: Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148Reputation: 6148
To change the hostname:

Code:
vim [or the editor of your choice] /etc/hostname
See man hostname for more.

If you want the public to have access to your site, the A Record must point to the public-facing ip address. Beyond that, as for your DNS questions, I must confess I'm not exactly sure what you are asking.

Last edited by frankbell; 02-12-2017 at 08:33 PM.
 
Old 02-12-2017, 08:36 PM   #3
resuni
Member
 
Registered: Oct 2009
Location: Colorado, USA
Distribution: I use Arch btw
Posts: 142

Rep: Reputation: 12
If on CentOS 7:

Code:
hostnamcectl set-hostname servix.example.com --static
If on CentOS 6, use the `hostname` command like you just demonstrated. The `hostname` command will still work on CentOS 7, but with the introduction of systemd, the recommendation is to use hostnamectl going forward.

Quote:
I am guessing in /etc/hosts

127.0.0.1 localhost
66.19.240.12 or is it 192.168.1.4 servix.example.com servix
I'm assuming you're using a NAT or PAT (IP address or port translation through a router or firewall), since you provided both a public and a private IP address. If you are using a NAT or PAT, it's usually better to use the private IP address:

Code:
127.0.0.1 localhost
192.168.1.4 servix.example.com servix
Keep in mind this is situational. You may find that with your application, it's better to use the public IP address. The only difference this makes is how the server resolves its own host name.

EDIT: Forgot to answer your final question...

Quote:
and in FreeDns A Record should point to 66.19.240.12 both example.com and www?
I'm a bit confused about what you're trying to make resolve. In the example you provided, servix was your host name.

In the simplest cases, you have '@' (no subdomain) and 'www' resolve to the same IP address. So yes, you probably want example.com and www.example.com to resolve to 66.19.240.12.

If you also want servix.example.com to load something from your server, it will also need to resolve to 66.19.240.12.

Last edited by resuni; 02-12-2017 at 08:40 PM. Reason: Forgot to answer your final question...
 
Old 02-12-2017, 08:54 PM   #4
drillsar
Member
 
Registered: Jan 2017
Posts: 144

Original Poster
Rep: Reputation: Disabled
Ok you can name hostname anything you like am I correct? I am just confused on how DNS works.

In FREEDNS A record I have the external Ip of my machine pointing. I got a warning that my A record don't point to servers ip address which I am assuming because I didn't put 192.168.1.4 in /etc/hosts

So if my hostname is Servix I just add that to my domain name in the hosts file?
 
Old 02-12-2017, 10:28 PM   #5
resuni
Member
 
Registered: Oct 2009
Location: Colorado, USA
Distribution: I use Arch btw
Posts: 142

Rep: Reputation: 12
Yeah, you can name the hostname anything you want. It doesn't have to be the same as a public DNS record, but it often is.

Where did you see the warning that your A record doesn't point to the server's IP address? I don't think that would have anything to do with your hosts file, but I would have to know where it came from to be sure.
 
Old 02-12-2017, 10:36 PM   #6
drillsar
Member
 
Registered: Jan 2017
Posts: 144

Original Poster
Rep: Reputation: Disabled
I was using a script to configure Magento Server automatically and gave this warning that Servers address is 192.168.1.4 but points to different IP which was my external.

Now I also have a problem with SELinux. I put it in permissive mode and ran the following:

grep "SELinux is preventing" /var/log/messages" and got nothing, but can't access site if I enable SELinux to enforcing.
 
Old 02-12-2017, 11:19 PM   #7
resuni
Member
 
Registered: Oct 2009
Location: Colorado, USA
Distribution: I use Arch btw
Posts: 142

Rep: Reputation: 12
That should be a warning you can ignore. You may have to add a line that forces (www.)example.com to resolve to localhost or your private IP address, but it's best to leave your /etc/hosts file in its default state if you can.

As for SELinux, I personally have it disabled on many of my servers. I know it's bad practice, but it's just one of those things I haven't looked at doing properly yet. I recommend starting a new thread asking for help with SELinux, since people browsing the topics are seeing this thread as a host name issue. That way you'll catch the attention of the SELinux experts. In fact, you probably want to get everything set up and working with SELinux disabled, then come back and configure it last.

Good luck!
 
Old 02-12-2017, 11:38 PM   #8
drillsar
Member
 
Registered: Jan 2017
Posts: 144

Original Poster
Rep: Reputation: Disabled
I was told if your not running DNS on your own server /etc/hosts you don't have to do anything. It's only when you run own DNS. Everything is working when I disable SELinux. Thanks for your time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP Valid Hostname > Reverse DNS is not a valid Hostname ..... Anandhc Linux - Newbie 5 03-30-2016 01:19 PM
Hostname no valid via DNS server Linuxupdate Linux - Server 3 05-20-2013 12:43 AM
Registering Hostname in DNS crokett Linux - Networking 1 07-16-2010 12:39 PM
Query DNS if I only know a partial hostname jantman Linux - General 3 02-27-2008 04:57 AM
hostname and dns settings blanker Linux - Networking 3 09-15-2007 01:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration