unable to lookup my hostname via gethostbyname() function
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
unable to lookup my hostname via gethostbyname() function
I tried changing my hostname in /etc/hosts before changing it in
/etc/hostname. Now what can I do? I am going to go into single user mode from
grub and boot from a live cd to restore the backup file
/etc/hosts_backup. Is there any way to fix this problem without rebooting? I shouldn't
have to reboot to fix a problem because I am not using windows.
Code:
chris@chris-desktop:~$ sudo vim /etc/hosts
sudo: unable to lookup chris-desktop via gethostbyname()
chris@chris-desktop:~$ sudo vim /etc/host
host.conf hosts hosts_backup
hostname hosts.allow hosts.deny
chris@chris-desktop:~$ sudo vim /etc/hostname
sudo: unable to lookup chris-desktop via gethostbyname()
chris@chris-desktop:~$ gksu gedit /etc/hostname
sudo: unable to lookup chris-desktop via gethostbyname()
chris@chris-desktop:~$ sudo cp /etc/hosts_backup hosts
sudo: unable to lookup chris-desktop via gethostbyname()
chris@chris-desktop:~$ cat /etc/hosts
127.0.0.1 localhost ubuntu
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# websites to be blocked
127.0.0.1 www.google.com
chris@chris-desktop:~$
I just tried changing my hostname with the hostname command. Hopefully I did it right.
Code:
ubuntu@ubuntu:~/Desktop$ sudo hostname -v chris
After that, I cannot open programs however I can open up another gnome terminal window by pushing control shift n when the terminal window that I had opened is focused.
The new terminal window shows my new hostname, but why can't I open up programs anymore? Now I am getting this error after using the hostname command.
Code:
ubuntu@chris:~/Desktop$ gedit
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
cannot open display: (null)
Run 'gedit --help' to see a full list of available command line options.
ubuntu@chris:~/Desktop$ xclock
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
Error: Can't open display: :0.0
ubuntu@chris:~/Desktop$
Well, your Xserver is tied to your hostname.
So if you change your hostname, you'll loose your connection.
Solution: Restart the Xserver, or reboot.
HTH
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.