Hot answers tagged

301

If you use: sudo scutil --set HostName name-you-want it will work a bit better. From the scutil(8) man page: --get pref Retrieves the specified preference. The current value will be reported on standard output. Supported preferences include: ComputerName The user-friendly name for the system. LocalHostName The local (...


128

After following Jeffrey J. Hoover's tip, sudo scutil --set ComputerName "newname" sudo scutil --set LocalHostName "newname" sudo scutil --set HostName "newname" I would add these last two steps. Flush the DNS cache by typing: dscacheutil -flushcache Restart your Mac. EDIT: It didn't work for me until I restarted my mac.


43

For those who are not looking for a command line solution, you can change it under System Preferences -> Sharing -> Computer Name:


37

Had the same problem. I deleted one of my project's folder and it became broken. In this case the site's configs should be removed from httpd-vhosts.conf and httpd.conf. Try ping 127.0.0.1 apachectl configtest can help you to detect the problem.


21

You can define what you want to see before the $ in your terminal by modifying the file ~/.profile. For example if you add to the file ~/.profile the following line: # h is the host name, w the complete path export PS1="\h:\w$ " you will see the host name and the complete path of the current directory: host_name:current_directory_path$ You can also ...


16

Assuming the Firewall is turned off, then in order to ping $HOSTNAME, there has to be some form of sharing or service enabled in System Preferences > Sharing, or add an entry to the /etc/hosts file, depending on how/what you're trying to access by $HOSTNAME. Example, 127.0.0.1 computer_name where computer_name is what's reported by echo $HOSTNAME or in lieu ...


14

Check your hosts file, because probably it's malformed. It should look similar to this one: ## # 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 127.0.0.1 youtube.com 127.0.0.1 www.youtube.com 255.255.255.255 broadcasthost ::1 ...


11

In one line, from Terminal: sudo -b "/Applications/Textedit.app/Contents/MacOS/TextEdit" /etc/hosts Make your changes, save and close.


9

Use Weblock - AdBlock for iOS app to create a redirect rule from http://app to the IP and port you like. (Only works when on a WIFI network)


9

The solution was to move the domain in the /etc/hosts file to the same entry as localhost. 127.0.0.1 localhost domain.com See this StackOverflow thread.


9

Open TextEdit as sudo sudo -b /Applications/TextEdit.app/Contents/MacOS/TextEdit Open /etc/hosts in this new TextEdit instance using any of the following methods: Append the path to the end of the previous command Use File → Open Drag the file to the sudo'd TextEdit on the Dock Alternatively, you can edit in Terminal using nano: SUDO_EDITOR=nano sudo -e ...


8

You can run sudo hostname Name-Of-My-Computer in Terminal to change the name.


7

In my case, I found that it was a problem with our DNS server, as the reverse DNS lookup didn't scavenge because there was duplicate DNS entries for the IP address and hostname.


6

Create a new Inbound Rule that allows traffic over UDP port 5353 in the needed security zones. Step-by-step: Open Windows Firewall Advanced Settings Create a new rule in Inbound Rules Under Protocols and Rules, choose Protocol Type > UDP and Specific Ports > 5353 Choose the appropriate security zones for your network. For more information on security ...


6

Everything seems to be working now. I can access localhost again, and my app is running Sinatra on Thin as it was before. Thanks to bmike, I did a bit of searching on why my loopback was unreachable and came across this article. I moved my old hosts file (/etc/hosts) to hosts.old and made a new one in its place that simply contained: ## # Host Database # # ...


6

Protecting with ‘schg’, the system immutable flag, is a potential solution, depending on how much protection you need. You can set the schg flag using sudo chflags schg /etc/hosts Removal of the protection depends on your kernel security level. Run sysctl kern.securelevel: 1 means you need to boot to single-user mode to run chflags noschg /etc/hosts, 0 ...


5

All additional entries to the HOSTS file must be above the: fe80::1%lo0 Make sure there is at least one line break after the last entry. Like so: 127.0.0.1 LLL.localhost 127.0.0.1 LLL.localhost # Although you probably can't tell, there is another line following the # symbol. One more thing to mention, using Space instead of Tab between 127.0.0.1 and ...


5

The hosts(5) manual page provides some insight into how /etc/hosts is used. The file is used by mDNSResponder and, given your question, I suspect you want to see edits to /etc/hosts reflected in your DNS look-ups. After each edit of /etc/hosts reset the mDNSResponder cache using this Apple technical note, OS X: How to reset the DNS cache: sudo ...


5

sudo nano /private/etc/hosts to edit the hosts file within Terminal, Control-O to save, then hit enter


4

The Cisco AnyConnect VPN Client is known to show this behavior. It will reset your /etc/hosts file on reboot to the contents of /etc/hosts.ac. If you use this VPN client, you should make your modifications to both files. See this hint for more info. http://hints.macworld.com/article.php?story=20111011050950471


4

This answer on the question Lion “hosts” File Bug is relevant here as well. All additional entries to the HOSTS file must be above the: fe80::1%lo0 Make sure there is at least one line break after the last entry. Like so: 127.0.0.1 LLL.localhost 127.0.0.1 LLL.localhost # Although you probably can't tell, there is another line following the # symbol. One ...


4

unfortunately the answer is no. Here's another answer to a very similar question. It's not the same question, but the answer is the same: https://stackoverflow.com/a/5007150/62653 As a side note, you might be interested in this blog post. It won't solve your problem, but is quite interesting nonetheless (the domain name for this address, and the blog title ...


4

I have no such problems connecting to a web server when it's actually listening on port 80. If you have no web server running, here is what you should get from terminal to show that name resolution is working on all network interfaces before the telnet gives up connecting to port 80: mac:~ me$ telnet localhost 80 Trying ::1... telnet: connect to address ::...


4

No, having duplicates is not a problem. Since the file is read in order, the first matching result is read, and the rest of the file is ignored. Having exact duplicates has no effect.


4

You could try TextWrangler for this sort of thing; much more capable than TextEdit, and if you use the direct install from BareBones Software instead of the App Store version, it will happily open locked files. When you try, it asks permission, reminding you that you are not a member of the required group, but password entry will allow you to open and edit ...


4

The problem could be that the hosts file might have been corrupted from the original ASCII encoding. I cleared all spaces and put tabs in it, ran sudo killall -HUP mDNSResponder (you can do that instead of rebooting) and after, it worked.


4

Usually only the root user is allowed to modify the file hosts. To do that and fix your hosts file or your /etc folder (depending where you applied your read/write permissions) follow these steps: Throw away your newly created hosts file (but not the old one!) Repair your permissions with Disk Utility. Open Terminal and enter sudo nano /etc/hosts and hit ↵...


4

sudo killall -HUP mDNSResponder No reboot required. "It works!" for me, OS X 10.11.6


4

You're not actually mapping ::1 to 127.0.0.1 in this case. You're providing an invalid name for ::1 that is essentially disabling the entry. You can't map an ipv6 address to an ipv4 address - they're not compatible. If you need localhost resolution for ipv6 to not be enabled, simply comment the ::1 line out, or don't include it at all.


4

No. You need a web proxy or other filter product that snoops on and processes the URL instead of just the main host.


Only top voted, non community-wiki answers of a minimum length are eligible