My Linux System doesn't recognize hostname. How could I fix it? - linux

I am setting a Linux machine and I have a problem. When I try to run the command:
hostname -f
I get this error:
hostname: Name or service not known
I am ew on this and I would like to know how could I solve it. My /etc/hosts and /etc/hostname files show the next:
/etc/hostname:
namehost
/etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Thak you so much!

Try sudo apt-get -f install first and then retry.

I had to configure the file /etc/hosts and add there the next line:
127.0.0.1 namehost
Doing this, it works!

Related

Linux process/component sending frequent DNS queries to resolve the local hostname (but shouldn't)

I'm not a networking guru so could use some help. I am running a RHEL7 (Red Hat Enterprise Linux) VM (Virtual Machine) where some component on the OS is sending frequent DNS queries to resolve it's own local hostname to our main DNS server (which shouldn't be happening because the DNS server won't know anything about its address). Can anyone provide guidance as to how I can find out what component/service/process this is? It's filling our logs with 19k records over just hours and I need to find a way to fix this.
The hostname for the RHEL VM is spe1.2v29999999.dev.local , there is a static IP on this VM and it is 10.70.49.61. The /etc/hosts looks like:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost4 localhost4.localdomain4
I suspected it might be a java jar we have running on the VM, but I stopped it via systemctl stop MyJavaJar but after running a tcp dump via tcpdump -i any udp port 53, I could still see the queries happening.
Here are some examples from different days/times in the logs (both A and TXT records):
2020-05-05T13:53:50.189178+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[20886]: 739 10.70.49.61/65078 query[A] spe1.2v29999999.dev.local from 10.70.49.61
2020-05-07T00:01:39.934899+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[8615]: 27827 10.70.49.61/57348 reply spe1.2v29999999.dev.local is NXDOMAIN
2020-05-11T00:01:20.674688+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[8615]: 130345 10.70.49.61/53321 query[TXT] bootstrap.spe1.2v29999999.dev.local from 10.70.49.61
Would making any changes to /etc/hostname, /etc/sysconfig, /var/named .zone files, /var/named.conf or /etc/named help? Can I do more with tcpdump? Thanks
Put:
127.0.0.1 spe1.2v29999999.dev.local
in /etc/hosts. This is done by default on many distros.

Why do I have to change the linux host name for postfix?

I am trying to install postfix on my debian server. This is kind of a "general purpose" machine.
The server is running an apache web server and a couple of applications in docker containers. I would like to add a postfix mail server. Every tutorial tells me to change my hostname to mail.mydomain.com, but as I understand the hostname applies to the entire System. This is not primarily a mailserver so I would prefer not to commit to a hostname for the mailserver only.
What is the purpose of naming my host mail.mydomain.com?? Apache works fine without naming the system mydomain.com.
Am I meant to have a separate machine for my mail server? Or should I try to put it in a docker container?
Actually no need to change the hostname. You will add an FQDN so that services like postfix can use it.
let's say your /etc/hosts looks like this:
127.0.0.1 myhostname localhost localhost.localdomain
::1 myhostname localhost localhost.localdomain
set the FQDN to make the hostname be an alias for it:
127.0.0.1 myhost.domain.com myhostname localhost localhost.localdomain
::1 myhost.domain.com myhostname localhost localhost.localdomain
Then you can verify by hostname --fqdn
myhost.domain.com
While hostname is same as before myhostname

Root can resolve localhost, while normal user cannot

I think I encounter a weird problem:
With a normal user: when I ping localhost, I got ping: unknown host localhost, when I ping 0.0.0.0 or 127.0.0.1, I got response.
With root: everything is fine.
Here is the content in /etc/hosts:
127.0.0.1 localhost.localdomain localhost
... [opt out]
I am using CentOS (rocks cluster system)
I guess that /etc/hosts is not readable by ordinary users. What are the permissions of that file?

Getting complain message from radius server

I am very new to Radius server, please give some advice if you know.
currently the basic configuration of Radius have been finished, while i am testing the server i got the following error:
/usr/local/radius/bin/radtest user password localhost 0 testing123
radclient:: Failed to find IP address for radius
radclient: Nothing to send
if you want to know further information for configuration please let me know.
It appears it can't resolve localhost, try /usr/local/radius/bin/radtest user password 127.0.0.1 0 testing123
Edit your /etc/hosts file and add add the hostname of your server to the aliases list of 127.0.0.1, like this:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 my-radius
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 my-radius

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

I tried to restart my Apache server on CentOS 5.0 and got this message:
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Here is the /etc/hosts file:
127.0.0.1 server4-245 server4-245.com localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
Here is the /etc/sysconfig/network file:
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server4-245
I also have this in the Apache httpd.conf file:
ServerName localhost
However, I still get the first error message when I restart Apache.
If you don't have httpd.conf in folder /etc/apache2, you should have apache2.conf - simply add:
ServerName localhost
Then restart the apache2 service.
Your hosts file does not include a valid FQDN, nor is localhost an FQDN. An FQDN must include a hostname part, as well as a domain name part. For example, the following is a valid FQDN:
host.server4-245.com
Choose an FQDN and include it both in your /etc/hosts file on both the IPv4 and IPv6 addresses you are using (in your case, localhost or 127.0.0.1), and change your ServerName in your httpd configuration to match.
/etc/hosts:
127.0.0.1 localhost.localdomain localhost host.server4-245.com
::1 localhost.localdomain localhost host.server4-245.com
httpd.conf:
ServerName host.server4-245.com
After the initial install of Apache server, I got the following error while restarting the Apache service on Ubuntu 12.04 (Precise Pangolin)
The solution is really simple. Just add the ServerName directive to /etc/apache2/httpd.conf:
sudo nano /etc/apache2/httpd.conf
Add: ServerName localhost
Finally restart the Apache server:
sudo /etc/init.d/apache2 restart
Make sure you're editing the right httpd.conf file, then the error about unreliable server's domain name should be gone (this is the most common mistake).
To locate your httpd.conf Apache configuration file, run:
apachectl -t -D DUMP_INCLUDES
Then edit the file and uncomment or change ServerName line into:
ServerName localhost
Then restart your apache by: sudo apachectl restart
So while this is answered and accepted it still came up as a top search result and the answers though laid out (after lots of research) left me scratching my head and digging a lot further. So here's a quick layout of how I resolved the issue.
Assuming my server is myserver.myhome.com and my static IP address is 192.168.1.150:
Edit the hosts file
$ sudo nano -w /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 myserver.myhome.com myserver
192.168.1.150 myserver.myhome.com myserver
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
::1 myserver.myhome.com myserver
Edit httpd.conf
$ sudo nano -w /etc/apache2/httpd.conf
ServerName myserver.myhome.com
Edit network
$ sudo nano -w /etc/sysconfig/network HOSTNAME=myserver.myhome.com
Verify
$ hostname
(output) myserver.myhome.com
$ hostname -f
(output) myserver.myhome.com
Restart Apache
$ sudo /etc/init.d/apache2 restart
It appeared the difference was including myserver.myhome.com to both the 127.0.0.1 as well as the static IP address 192.168.1.150 in the hosts file. The same on Ubuntu Server and CentOS.
In httpd.conf, search for "ServerName". It's usually commented out by default on Mac. Just uncomment it and fill it in. Make sure you also have the name/ip combo set in /etc/hosts.
In the Apache httpd.conf file:
ServerName: 127.0.0.1
There are two ways to resolve this error:
Include /etc/apache2/httpd.conf
Add the above line in file /etc/apache2/apache2.conf
Add this line at the end of the file /etc/apache2/apache2.conf:
ServerName localhost
I've resolved the fully qualified domain name message on different occasions by adding my server hostname to the /etc/apache2/httpd.conf file and to the /etc/apache2/apache2.conf file.
Type hostname -f in your terminal. This query will return your hostname.
Then edit the /etc/apache2/httpd.conf file (or create it if it does not exist for some reason) and add ServerName <your_hostname>.
Alternatively, I have also been able to eliminate the message by adding ServerName <your_hostname> to the /etc/apache2/apache2.conf file.
If all goes well, when you restart Apache, the message will be gone.
Most answers suggest to just add ServerName localhost to /etc/apache2/apache2.conf.
But quoting Apache documentation :
The presence of this error message also indicates that Apache httpd was unable to obtain a fully-qualified hostname by doing a reverse lookup on your server's IP address. While the above instructions will get rid of the warning in any case, it is also a good idea to fix your name resolution so that this reverse mapping works.
Therefore adding such a line to /etc/hosts is probably a more robust solution :
192.0.2.0 foobar.example.com foobar
where 192.0.2.0 is the static IP address of the server named foobar within the example.com domain.
One can check the FQDN e.g. with
hostname -A
(shortcut for hostname --all-fqdn).
Turns out that I had this problem and it was because I used "tabs" to indent lines instead of spaces. Just posting, in case it helps anyone.
If you've edited /etc/apache2/httpd.conf with the ServerName localhost you may be editing the wrong file. All answers I found were pointing towards that standard httpd.conf. After some foraging, I found a good answer here.
To locate the right httpd.conf file use
apachectl -t -D DUMP_INCLUDES
I found mine was actually /usr/local/etc/httpd/httpd.conf.
Use your preferred editor to comment out the line (i.e. remove the # before) starting with ServerName, and replace the domain name for the appropriate one – local environments should work with
ServerName localhost
I hope this helps more people who may be stuck.

Resources