3

Is it possible to change the /etc/hosts file so that the routing is used when a peer to peer network is created, for example, in my /etc/hosts file, I have thisismylaptop.com mapped to 127.0.0.1:

127.0.0.1         localhost
255.255.255.255   broadcasthost
::1               localhost
127.0.0.1         thisismylaptop.com

On that computer, if I traceroute thisismylaptop.com, I get the following result:

$ traceroute thisismylaptop.com
traceroute to thisismylaptop.com (127.0.0.1) 64 hops max, 52 byte packets
 1. localhost (127.0.0.1)  0.252 ms  0.031ms  0.025ms

I can then open a computer to computer network (in the wifi menu, by clicking "Create Network"), however, when I traceroute thisismylaptop.com on a seperate computer connected to the network, I get the following result:

$ traceroute thisismylaptop.com
traceroute: unknown host thisismylaptop.com

Do you know if it is possible to have thisismylaptop.com point to 127.0.0.1 or the computer hosting the network?

This is my first time asking a question here, so if you need any clarification or anything, please let me know. Thank you so much!

3

As stated, it's pretty difficult to do this. However, if you're willing to change the goal a little, and use a name ending in ".local" instead of ".com", it's trivial (in fact, it's already being done for you).

Let me start with a little networking theory. I think you're mixing up two different levels: name resolution and routing.

Name resolution is how network names (like "thisismylaptop.com") into numeric IP addresses (like 127.0.0.1 or ::1). To simplify a bit, when you put in a name, your computer looks for it in /etc/hosts, and if it finds it it uses that number; if it doesn't find it, it asks a DNS (Domain Name Service) server to look it up for you.

This is a problem in your scenario, because your computer's /etc/hosts file applies only to that one computer; the other computer has its own /etc/hosts file, and it doesn't have your custom entries in it. You could run a DNS server, but then you'd need to find a way to configure all of the computers to use that DNS service, which is a whole other can of worms.

Routing takes place after name resolution; it's the "ok, I have a numeric address, now where do I actually send the packets (data) to get it there?" phase. And there's another problem here, because 127.0.0.1 always refers to "this computer right here". That is, on your first computer, it sends packets to that first computer. On the second computer, it sends packets to the second computer. If you did manage to get all the computers to resolve "thisismylaptop.com" to 127.0.0.1, every computer would think that it was "thisismylaptop.com". Instead, you need to figure out what the IP address(es) attached to your computer's Wi-Fi interface is/are, and use that.

The good news is that wanting to do things like this is common, and so Apple worked out a solution long ago. Apple calls it Bonjour (the rest of the world calls it zeroconf), and it's been built into Mac OS X since 2002. The main limitation is that it requires names ending in ".local" as a hint to the computers involved that they shouldn't use a regular DNS lookup, but instead use multicast DNS, which basically consists of yelling over the local network: "Hey, is thisismylaptop.local out there? If so, send me your IP address(es), so we can talk."

To use it, go open System Preferences on your Mac, select the Sharing preference pane, and look near the top, just below the computer name. It'll probably say something like "Computers on your local network can access your computer at: nywillbs-MacBook.local". If you don't like that name, click Edit to change it (or change the computer name; by default it's based on that). If your other computer is running macOS, you can just use that name directly. If it's running Windows, install iTunes on it, and that'll install Bonjour as well. (There's supposed to be a way to install just Bonjour without iTunes, but I'm not sure it's up to date.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .