0

When I run ip address show I see that the loopback network interface has 127.0.0.1/8 assigned.

This means that if I want to use the loopback network interface I can run npx http-server -a 127.X.X.X because the /8 suffix implies that in order to use the loopback interface I can use any IP address that starts with 127. For example: npx http-server -a 127.4.7.1.

ip address show also shows that the network interface called enp0s3 has 10.0.2.15/24 assigned.

However, when I attempt to use an address that is not assigned, it results in an error. For example, npx http-server -a 10.0.2.16 returns the error:

Error: listen EADDRNOTAVAIL: address not available 

Why is address 10.0.2.16 "not available"?

What should I do to be able to use 10.0.2.16, when only 10.0.2.15 is assigned, like with 127.4.7.1?

2 Answers 2

2

You severely misunderstand the role of the netmask.

You can listen to addresses bound to local interfaces. Netmasks shows the TCP/IP stack which addresses are local, and which are only reachable via a router. To listen to an IP, you have to assign it to an interface.

loand 127.0.0.0/8 is special, because it's reserved for loopback use.

2

10.2.0.16 is "not available" because your machine does not own it. The only addresses you can use that way are addresses that your machine is set to respond to. You're creating a server, something that is listening on a specific address; unless your machine actually owns that address, some other machine on your network may well own it, and if so the network infrastructure may route those packets away from you and you'll never see them... even if two machines on the same network were allowed to have the same IP address. The reason that you can specify an address that way is because machines that are "multi-homed" can have multiple different IP addresses that they can respond to. And as vidarlo mentions, 127.x.x.x and lo are special because you can own all those addresses, since they never leave your physical machine.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.