frank

Modifying the Hosts file in Mac OS X

Frequently asked, here is my mini tutorial on it.

How do I change the 'hosts' file under macOS (from 10.5 Leopard to 15.3.1 Sequoia) to link an internal IP address with a DNS name?

There is a file called 'hosts' in the '/etc/' directory. This file has to be accessed with administrator rights. This is done in the 'Terminal' application using the 'sudo' command.

sudo nano /etc/hosts

The "nano" text editor is used here. You can also use the "vi" or "vim" editor (sudo vi /etc/hosts).
After the password prompt, the contents of the "hosts" file will appear:

##
# 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

You can now add your own entries. Example:

##
# 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

192.168.0.1 www.mydomain.com
192.168.0.2 mymac

Save the file (in nano: Ctrl->X and then enter Y to save) and then execute the command:

dscacheutil -flushcache
This command will update the existing DNS cache.

You can now 'ping' to test the internal name resolution.

# ping mymac
PING mymac (192.168.0.2): 56 data bytes
64 bytes from 192.168.0.2: icmp_seq=0 ttl=64 time=0.155 ms
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.166 ms

That's it face-smile

Greetings Frank
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 673085

Url: https://administrator.de/tutorial/modifying-the-hosts-file-in-mac-os-x-673085.html

Ausgedruckt am: 30.05.2025 um 01:05 Uhr