Basic networking: browsing to Rails site running o

2019-08-26 21:17发布

问题:

I'm running a Rails site on computer A. I start the site with rails server and browse to it at http://localhost:3000. Computer B is on the same WIFI network. From computer B I can visit my site at http://192.x.y.z:3000 where the IPv4 address of computer A is obtained from ifconfig in the OS X Terminal.

How can I browse to my site (running on computer A) from computer B without using the wireless router? I'll still have WIFI enabled on both computers. However I don't want the computers to communicate through the additional WIFI router.

My current understanding is the WIFI router assigns IP addresses to the various devices on the network. In trying to answer my question I wondered who/what will assign IP addresses to the computers when the wireless router is removed.

My goal is to learn more about networking. I'm fine doing some low-level sockets programming if that's what it takes.

回答1:

You can create an Ad-Hoc WiFi network between the two computers, which works without a router. The two will still try to get an IP address from a 3rd party, which will of course fail though. In this case they'll fall back on IP self-assignment and pick a random IP in the 169.x range. This will take a minute or so, but once it happened, you can access the other machine on that address. Manually setting a fixed IP on both machines is an option as well.