linux centos 6.3 hostname (dhcppc4) assigned automatically - linux

Linux terminal showing hostname dhcppc4 that i never configured. As per configuration files hostname must be localhost :
[root#dhcppc4 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
[root#dhcppc4 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Note : I attached a new monitor to my laptop.
Don't know how but sometimes terminal shows localhost as hostname.
what is dhcppc4? How to resolve the issue?

This question is not suitable for stackoverflow (this should be on serverfault i guess)
Anyway, DHCP server could even assign an hostname to your machine
Look here: RFC 1553 - DHCP
Maybe this is your case?

You are most assuredly allowed to edit the HOSTNAME line of that config' file you refer to in your question just fine.
It will not show up until you logout & back in again. You will also want to run /etc/init.d/rsyslogd restart (or whatever syslog daemon you are using) to make that name take effect in the log files.
You may or may not need to run a vi /etc/hosts to adjust the lines in there as you need for your specific applications. Most will be fine, but some are very very picky, like the otherwise very awesome software, Zimbra, for one example, wont work if those lines are not perfect. Asterisk could be another one that might require that file to be perfect match with your configuration.
You can or can not work with your DHCP server to set this, but most people dont, most edit the HOSTNAME and move on.
It is actually important, though, and do in fact resolve this, dont just leave it, as we sysadmins do not want to be typing mission critical commands at the BASH prompt on the wrong machine when all 6 of your servers all say "localhost".

Related

How does the host name resolution of anyname.localhost resolves to IPv6 ::1 address?

In an Ubuntu 20 or 22 LTS, if I attempt to use a hostname like anyname.localhost it always seems to resolve to IPv6 ::1 address.
In an old RHEL 6, if I attempt to use a hostname like anyname.localhost it always seems to resolve to IPv4 127.0.0.1 address.
In a MS-Windows or MacOS 12.6 machine, this does not seem to happen. (It only happens if I manually edit /etc/hosts and manually add an host alias to 127.0.0.1
127.0.0.1 localhost localhost.localdomain somename.localhost
)
Is this any.sequence.of.names.localhost resolution to ::1 (localhost) always garanteed to happen ? By what reason ? In what Linux distros ?
I have a few projects where it seems useful to have many localhost aliases without having to edit /etc/hosts, but I searched about TCP and DNS quirks, and found nothing about this behaviour. (Not very sure what I should search for). Not sure if I can depend on this behaviour.
Well, thanks to the link posted in the comments above by Patrick Mevzek, I could reach a documented explanation.
For the Ubuntu 20/22 LTS, it seems to use systemd-resolved for DNS resolution.
And, as it says on
https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html
Synthetic Records
...
The hostnames "localhost" and "localhost.localdomain" as well as any hostname ending in ".localhost" or ".localhost.localdomain" are resolved to the IP addresses 127.0.0.1 and ::1.
So, this seems to explain that Linux OSes that have DNS resolution based on systemd will have this behaviour, and others (like Windows and MacOS) do not.
(So, this seemed a systemd question after all :-)
(This question is in fact a duplicate of https://serverfault.com/questions/1065513/how-does-linux-resolve-wildcard-locahost-subdomains-e-g-ping-test-localhost/1065514#1065514 - just using systemd-resolved instead of nss-myhostname , and if anyone knows how to link them both ways, could help others searching by other words).

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.

Rename localhost 127.0.0.1, in LAMP stack

I am using a LAMP stack. Will there be problems if I update the /etc/host file to reflect 127.0.0.1 as somename from localhost?
Thanks!
Edit:
I sometimes work in remote sites with no network. I have the same setup on different machines and I need the server name to know dynamically where to do changes, etc.
I edited /etc/hosts to show
127.0.0.1 localhost somename
Now, with my Wifi off I am trying http://somename and it is not connecting. If I turn my wifi on, it works. But I need it to work with no connection. How can I resolve this?
No. Just add somename after localhost separated by space in /etc/hosts. You can add as many aliases as you like, as long as you don't delete localhost.

Host name showing (none) at login

I am a newbie to Linux environment and building a Linux system from scratch using busy box. I created /etc/hosts and /etc/hostname file. But every time I start the system it shows (none)login:
But I can change the hostname using hostname command after logging in. I don't want any FQDN hostname or dynamic hostname configuration from DNS server. The content of the host name files are:-
$cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 tiny
$cat /etc/hostname
tiny
Is there wrong with the procedure or file. Please any help is appreciated.
You're likely going about this the right way and just need to either restart the system sudo reboot (or just reboot as the root user) or reload networking.
On Ubuntu and other Debian-variants, you're correct - you need to update /etc/hostname and /etc/hosts. To reload networking: service networking reload or invoke-rc.d networking force-reload.
On Fedora/CentOS and other Red Hat variants, you can set the hostname using the hostnamectl program. To reload networking: /etc/init.d/network reload
On Android, I believe the command you want is: setprop net.hostname <your name here>.
Also, you can combine your entry in /etc/hostname to:
127.0.0.1 localhost tiny
Perhaps your IP-address is not really 127.0.1.1 (it seems unlikely).
On most Linux systems, you have the ifconfig tool, which can show your IP-address. I would check if the IPv4 address displayed by ifconfig matches the IP-address given for "tiny" in your /etc/hosts file - and modify it to match. Once you have done that, you should be able to ping "tiny" to verify that the hosts file is updated. Verifying that the hostname is going to be used takes a reboot, of course.
Setting /etc/hostname and /etc/hosts doesn't work for my embedded arm Linux box. Instead, I put this line in the start script:
echo tiny > /proc/sys/kernel/hostname

ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am trying to set up a VPN with a Raspberry Pi, and the first step is gaining the ability to ssh into the device from outside my local network. For whatever reason, this is proving to be impossible and I haven't the slightest clue why. When I try to ssh into my server with user#hostname, I get the error:
ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
However, I can log into the server with,
ssh user#[local IP]
The server is a Raspberry Pi Model B running the latest distribution of Raspbian and the machine I am trying to connect to it with is a Macbook Pro running Mavericks. ssh was enabled on the Raspberry Pi when I set up Raspbian.
I have perused Stack Overflow for hours trying to see if anyone else had this problem and I have not found anything. Every ssh tutorial I find says that I should just be able to set it up on the remote machine and log in from anywhere using a hostname, and I have never had success with that.
If you're on Mac, restarting the DNS responder fixed the issue for me.
sudo killall -HUP mDNSResponder
I had the same issue connecting to a remote machine. but I managed to login as below:
ssh -p 22 myName#hostname
or:
ssh -l myName -p 22 hostname
Recently I came across the same issue. I was able to ssh to my pi on my network, but not from outside my home network.
I had already:
installed and tested ssh on my home network.
Set a static IP for my pi.
Set up a Dynamic DNS service and installed the software on my pi.
I referenced these instructions for setting up the static ip, and there are many more instructional resources out there.
Also, I set up port forward on my router for hosting a web site and I had even port forward port 22 to my pi's static IP for ssh, but I left the field blank where you specify the application you are performing the port forwarding for on the router. Anyway, I added 'ssh' into this field and, VOILA! A working ssh connection from anywhere to my pi.
I'll write out my router's port forwarding settings.
(ApplicationTextField)_ssh (external port)_22 (Internal Port)_22 (Protocal)_Both (To IP Address)_192.168.1.### (Enabled)_checkBox
Port forwarding settings can be different for different routers though, so look up directions for your router.
Now, when I am outside of my home network I connect to my pi by typing:
ssh pi#[hostname]
Then I am able to input my password and connect.
In my case I was trying ssh like this
ssh pedro#192.168.2.179:22
when the correct format is:
ssh pedro#192.168.2.179 -p 22
If you need access to your VPN from anywhere in the world you need to register a domain name and have it point to the public ip address of your VPN/network gateway. You could also use a Dynamic DNS service to connect a hostname to your public ip.
If you only need to ssh from your Mac to your Raspberry inside your local network, do this: On your Mac, edit /etc/hosts. Assuming the Raspberry has hostname "berry" and ip "172.16.0.100", add one line:
# ip hostname
172.16.0.100 berry
Now: ssh user#berry should work.
I had the same issue, which I was able to resolve by adding a .local to the host name, ala ssh user#hostname.local
For me, the problem was a typo on my ~/.ssh/config file. I had:
Host host1:
HostName 10.10.1.1
User jlyonsmith
The problem was the : after the host1 - it should not be there. ssh gives no warnings for typos in the ~/.ssh/config file. When it can't find host1 it looks for the machine locally, can't find it and prints the cryptic error message.
I had the same problem: The address shown in Preferences -> Sharing -> Remote Login didn't work and I got a '... nodename nor servname provided, or not known'. However, when I manually edited the settings (in Preferences -> Sharing -> Remote Login -> edit) and enabled "Use dynamic global hostname", it suddenly worked.
If your command is:
$ ssh -p 1122 path/to/pemfile user#[hostip/hostname]
You will also face the same error
ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
when you miss the option -i /path/to/pemfile of ssh
So Command should be:
$ ssh -p 1122 -i path/to/pemfile user#[hostip/hostname]
I needed to connect to remote Amazon server
ssh -i ~/.ssh/test.pem -fN -L 5555:localhost:5678 ubuntu#hostname.com
I was getting the following error.
ssh: Could not resolve hostname <hostname.com>: nodename nor servname provided, or not known
Solution For Mac OSX
Pinging the host resolved the issue. I am using Mac OSX Seirra.
ping hostname.com
Now problem resolved. Able to connect to the server.
Note: I tried this solution also. But it didn't work out. Then ping resolved the issue.
It seems that some apps won't read symlinked /etc/hosts (on macOS at least), you need to hardlink it.
ln /path/to/hosts_file /etc/hosts
This was happening to me when trying to access Github. The problem is that I was in the habit of doing:
git remote add <xyz> ssh:\\git#github.com......
But, if you are having this error from the question, removing ssh:\\ may resolve the issue. It solved it for me!
Note that you will have to do a git remote remove <xyz> and re-add the remote url without ssh:\\.
I have the exact same configuration. This answer pertains specifically to connecting to a raspberry pi from inside the local network (not outside). I have A raspberry pi ssh server, and a macbook pro, both connected to a a router. On a test router, my mac connects perfectly when I use ssh danran#mypiserver, however, when I use ssh danran#mypiserver on my main router, i get the error
ssh: Could not resolve hostname [hostname]: nodename nor servname
provided, or not known
Just as you have gotten. It seems, the solution for me at least, was to add a .local extension to the hostname when connecting from my mac via ssh.
So, to solve this, i used the command ssh danran#mypiserver.local (remember to replace the "danran" with your username and the "mypiserver" with your hostname) instead of using ssh danran#mypiserver.
To anyone reading this, try adding a .local as the suffix to your hostname you are trying to connect to. That should solve the issue on a local network.
Try this, considering your allowed ports. Store your .pem file in your Documents folder for instance.
To gain access to it now all you have to do is cd [directory], which moves you to the directory of the allotted file. You can first type ls, to list the directory contents you are currently in:
ls
cd /Documents
chmod 400 mycertificate.pem
ssh -i "mycertificate.pem" ec2-user#ec2-1-2-3-4.us-compass-0.compute.amazonaws.com -p 80
I got this error by using a .yml inventory file in ansible that was not properly formatted. For multiple hosts in a group, each hostname needs to end in a hard colon ":". Otherwise ansible runs the host names together and produces this ssh error.
I had the same problem after testing Visual Studio Code with remote-ssh plugin. During the setup of the remote host the software did ask me where to store the config-file. I thought a good place is the '.ssh-folder' (Linux-system) as it was a ssh-remote configuration.
It turned out to be a bad idea. The next day, after a new start of the computer I couldn't logon via ssh on the remote server. The error message was 'Could not resolve hostname:....... Name or service not known'.
What happen was that the uninstall from VSC did not delete this config-file and of course it was than disturbing the usual process. An 'rm' later the problem was solved (I did delete this config-file).

Resources