A computer hostname represents a unique name that gets assigned to a computer in a network in order to uniquely identify that computer in that specific network. A computer hostname can be set to any name you like, but you should keep in mind the following rules:
How To Set A Static IP Centos 7 By default, most instillation of Centos will end up having the default protocol set to be dynamic (DHCP) for obtaining the IP address. For a web server this is not what we want as it will be no good having the IP change and then having to change DHCP records to correctly point to the new IP address. Two static IPs configured: the address 192.168.1.105 is configured on the first machine which is the Master and the adress 192.168.1.106 is configured on the second machine which is the Worker ( you can refer to this article on how to setup a static IP on a CentOs machine: Static IP address in CentOS 7 ) 2GB RAM per machine.
- hostnames can contain letters (from a to z).
- hostnames can contain digits (from 0 to 9).
- hostnames can contain only the hyphen character
( – )
as special character. - hostnames can contains the dot special character
( . )
. - hostnames can contain a combination of all three rules but must start and end with a letter or a number.
- hostnames letters are case-insensitive.
- hostnames must contains between 2 and 63 characters long.
- hostnames should be descriptive (to ease identifying the computer purpose, location, geographical area, etc on the network).
In order to display a computer name in CentOS 7 and RHEL 7 systems via console, issue the following command. The
-s
flag displayed the computer short name (hostname only) and the -f
flag displays the computer FQDN in the network (only if the computer is a part of a domain or realm and the FQDN is set).You can also display a Linux system hostname by inspecting the content of /etc/hostname file using the cat command.
Display CentOS 7 Hostname
In order to change or set a CentOS 7 machine hostname, use the hostnamectl command as shown in the below command excerpt.
In addition to hostname command you can also use hostnamectl command to display a Linux machine hostname.
In order to apply the new hostname, a system reboot is required, issue one of the below commands in order to reboot a CentOS 7 machine.
A second method to setup a CentOS 7 machine hostname is to manually edit the /etc/hostname file and type your new hostname. Also, a system reboot is necessary in order to apply the new machine name.
A third method that can be used to change a CentOS 7 machine hostname is by using Linux sysctl interface. However, using this method to change machine name results in setting-up the machine transient hostname.
The transient hostname is a special hostname initialized and maintained only by the Linux kernel as an auxiliary machine name in addition to he static hostname and doesn’t survive reboots.
To display machine transient hostname issue the below commands.
Change CentOS 7 Hostname
Finally, the hostnamectl command can be used to achieve the following hostname setups: –pretty, –static, and –transient.
Although, there are other more specific ways to change a Linux machine hostname, such as issuing nmtui command or manually editing some configuration files specific to each Linux distribution (/etc/sysconfig/network-scripts/ifcfg-ethX for CentOS), the above rules are general available regardless of the used Linux distribution.
Share
Active1 year, 6 months ago
I am using centos Server and have to send the mail to the user so i copied running code of mine from one server and used it in here, but it is not sending mails.
Code is :
It always print 1. Same code running fine on other project. Please guide me what i can do to enable it here too?Any help will be highly appreciated!
AsthaAstha1,29633 gold badges1414 silver badges3333 bronze badges
7 Answers
After installing sendmail* and running the following commands:
I still had the same issue. I checked my
/var/log/maillog
and saw an error:After more searching, I changed
/etc/hosts
from:to:
and now the mail function is now working fine.
Skip Jack2,61322 gold badges1414 silver badges2222 bronze badges
AsthaAstha1,29633 gold badges1414 silver badges3333 bronze badges
I know this has been answered but I had a similiar problem.In case anyone else....
/var/log/maillog showed me a Postfix permission issue.
Tracking down error I found solution to be SELinux policy on CentOS (I'm using version 6).
Quick answer:
setsebool httpd_can_sendmail 1
You can use -P to make the change permanent; I just needed for password reset e-mail so not needed for my case.
Credit: http://www.spidersoft.com.au/2011/posftix-permission-denied-problem/?ModPagespeed=noscript
EDIT: I would have commented but I don't have enough reputation yet.
preOteppreOtep
![Change Change](/uploads/1/2/5/3/125324799/710622429.png)
I had the same problem. I have a development server at home and prod server at external server house and incoming mails go to other server. PHP:s
mail()
works nicely in server house, but not at home.I tested a bit and got it to work at home in the same manner as in server house. The difference between methods in server house and home is the configuration of sendmail. Server house I had only to install sendmail and it was fine, but at home I had to install also sendmail-cf and use it to add outgoing mail server address.
Let's assume you have Centos, Apache and PHP at home server and you want to send emails using PHP:s mail() function.
1) Set hostname on home server into two places: /etc/sysconfig/network and /proc/sys/kernel/hostname this way:
2) Install sendmail and sendmail-cf:
3) Add the following row into /etc/mail/sendmail.mc, where you have your ISP:s outgoing mail server:
4) Update sendmail.cf:
5) Restart sendmail and apache:
6) Boot to update hostname:
That's it. Now the following works:
You can skip -f:
in which case the sender's name become automatically user@hostname, eg. [email protected].
Some notes of hostname
![Centos Centos](https://devops.profitbricks.com/static/img/tutorials/apache/apache_centos_awstats.png)
The selection of hostname is critical. The default in Centos6 is
localhost.localdomain
, but mail()
is not working with it if you skip your own sender address (eg. '[email protected]'
) when calling mail(). If you are sure, that you always call mail() using your real address as sender address, the hostname can be whatever, but if you have existing calls to mail() that lacks the sender address (I have hundreds of this like calls for testing purposes), then you must have a real domain as a hostname, because your server's hostname is used as a sender-address-domain in these cases. Real in the sense that domain must have at least DNS A-record (for some reason my ISP doesn't require NS-record for sender address, only A-record, but test and check with your ISP). The downside of using non-email-domain as a sender address is that replys and delivery notifications will go to bit's heaven, but if you drop sender address in your code, it usually means that you test and debug something and don't need reply functionality. The domain can be eg. the one you get from dynamic dns server eg. mydns157.dlinkddns.com
, which can point to your home router (but not have to). You can get DNS record in PHP using dns_get_record('mydns157.dlinkddns.com')
, which returns an array like this:If
type
in above DNS-record is NS
, then the domain acts as an email domain, which is OK for hostname of own server, but the effect is a little different. If you set as hostname an existing email domain eg. myexistingemaildomain.com
, and send a message to [email protected]
eg for debugging purposes, sendmail thinks that the message has to be delivered to mail-folder of user me
on this server. If me
user doesn't exist, the sending fails and if the user exists, then the message goes to /var/mail/me
. This can be what you want, but (like me) you may want that all messages are delivered outside instead of server folders.Your hostname (in DNS record) doesn't need to point to your server's actual external IP to make mail() work in lack-of-sender-address cases, but there is no harm of it. The main thing is that hostname has a valid A-record and that the domain belongs to you. If the domain doesn't belong to you, then there may born a security hole. If you set as hostname some existing email domain eg.
t qmicrosoft.com
(for whatever reason) and send a message to someone without adding your own sender address when calling mail() (eg. '[email protected]'
), the sender address will be automatically [email protected]
. If you are logged as root, the sender address will be [email protected]
. Replys and notifications of failed deliveries go then to [email protected]
and this may not be your intention.2,67944 gold badges4040 silver badges7878 bronze badges
Timo KähkönenTimo Kähkönen8,19566 gold badges5252 silver badges9696 bronze badges
I'd recommend using SwiftMailer to simply a lot of this.
EamorrEamorr5,3822929 gold badges103103 silver badges190190 bronze badges
Sonal KhuntSonal Khunt
I just had this issue, two things.
My emails were going to spam, definitely check that. Probably because my server didn't have proper PTR and SPF records.
But also, I found it a lot easier to test sendmail with this:
Phil LaNasaPhil LaNasa
Centos 7 Iso
Always check your maillog in /var/log/maillog to know the cause of the problem.I had a similar issue once after having properly configured postfix. I got an error saying
Ratul DoleyRatul Doleyfatal: setrlimit: Permission denied
. Workaround is check if the httpd can send mail is enabled or not by getsebool httpd_can_sendmail
command. If httpd can send mail is off then enable it by the command: setsebool -P httpd_can_sendmail 1
. Hope this helps.Install Qmail On Centos 7 Change Static Iphone
41011 gold badge44 silver badges1111 bronze badges