0

I've tried to run my first objective-c code in Xcode... Compilation process was successfully, however an error returns " invalid host string: 'localhost' ".

After some Googling, I found out and connected the points that it might had something to do with the hosts file I recently deleted.

Now I cannot recreate the /etc/hosts through terminal using:

sudo cat >/etc/hosts <

#

Host Database

#

localhost is used to configure the loopback interface

when the system is booting. Do not change this entry.

#

127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%1o0 localhost EOD sudo: /private/etc/sudoers is mode 0666, should be 0440

Thanks in advance for any workaround.

GuilhermeMesquitaX
  • 177
  • 1
  • 1
  • 8

1 Answers1

0

You have broken your system by making inappropriate changes.

First, you need to fix the permissions on /etc/sudoers. You might try opening Disk Utility, selecting the system volume, and clicking Repair Disk Permissions. I am not sure that will change the sudoers permissions. If it does not, reboot your system and immediately press and hold the Command and S keys. This boots to single-user mode. When the command prompt appears, enter these commands:

mount -uw /
chmod 0666 /etc/sudoers
reboot

When the system boots, your sudo command might be working again, if you have not otherwise broken it. At this point, you may be able to recreate /etc/hosts. In addition to restoring its contents, you may need to set its ownership and permissions:

sudo chown root:wheel /etc/hosts
sudo chmod u=rw,go=r /etc/hosts

You could also restore /etc/hosts while in single-user mode, rather than booting normally and using the sudo command. Before the reboot command, use cat (or cp to copy from a file you prepared previously) to recreate /etc/hosts, then execute the chown and chmod commands (without sudo), then reboot.

I cannot guarantee these commands will suffice or that there are no errors; diagnosing problems such as this remotely is troublesome.

Stop tinkering with your system without making backups that you know work or taking other steps to be able to revert your changes.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • Thanks for the help Eric. I could solved it by terminal using sudo nano and writing down host file standard information... I had a lot of permission errors at this point, but finally could execute the application. – GuilhermeMesquitaX May 16 '13 at 14:09