Skip to content

General networking knowledge

Created: 2016-10-16 16:05:43 -0700 Modified: 2016-10-16 16:06:50 -0700

  • Video I did on this:
  • At a high level, a bind address is the address/interface that you tell a service to listen on. You won’t get a response from network traffic via a different address/interface.
    • The available interfaces should show in ifconfig (macOS) or os.networkInterfaces() in Node.js. You won’t see one with your public IP; you’ll just see one with the IP that your router assigned. If you only want to bind to one address and want your service available publicly, you would pick one that your router assigned and also forward ports.
    • You can use netstat to see bind addresses. It’s easiest if you use a unique port so that you can grep the port, e.g. netstat -a | grep 7895 (-a shows socket information).
  • A network interface is a software interface to networking hardware (reference). The hardware could be virtual.

Just by looking at Node.js, we can see how http-server works. http-server . -a will fail with this message:

╰─❯ http-server ./ -a
throw er; // Unhandled 'error' event
Error: listen EADDRNOTAVAIL: address not available
at Server.setupListenHandle [as _listen2] (node:net:1734:21)
at listenInCluster (node:net:1799:12)
at doListen (node:net:1948:7)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1778:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -49,
syscall: 'listen',
address: '',
port: 8080

The reason is that os.networkInterfaces() doesn’t list for me. It does list these, for example:

lo0: [
address: '',
netmask: '',
family: 'IPv4',
mac: '00:00:00:00:00:00',
internal: true,
cidr: ''
address: '::1',
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
family: 'IPv6',
mac: '00:00:00:00:00:00',
internal: true,
cidr: '::1/128',
scopeid: 0
address: 'fe80::1',
netmask: 'ffff:ffff:ffff:ffff::',
family: 'IPv6',
mac: '00:00:00:00:00:00',
internal: true,
cidr: 'fe80::1/64',
scopeid: 1

Note: to listen on a link-scoped address, you need to specify the scope ID.

  • fe80::1
  • fe80::1%lo0

Note: you are not listening to all addresses on a given interface, just one:

  • `http-server ./ -a ::1 -p 7895
    • curl -i
    • curl -i "[::1]:7895"

The network interfaces that print out all have names, e.g.:

  • awdl0
  • en0
  • en1
  • llw0
  • lo0
  • utun0
  • utun1
  • utun2
  • utun3

These all do have a meaning (reference), e.g. lo is typically for loopback (so it’s where you find and ::1), awdl is for Apple Wireless Direct Link, etc.