Given an extra loopback interface in the 127.0.0.X (X>1) range on BoxA (which can be running either OSX or Linux), I want to bind port 22 of this extra loopback interface to a forward SSH tunnel (ie. local port forward) that is pointed at BoxB.
On OSX this works fine (strangely, in retrospect). [Taking X=2] after bringing up the loopback alias with ifconfig lo0 alias 127.0.0.2 up, SSH can establish a tunnel with ssh -NfL 127.0.0.2:22:localhost:22 BoxB. Then in a new shell on BoxA, ssh 127.0.0.2 logs me into BoxB.
On Ubuntu, I can bring up the loopback alias on BoxA, but when trying to establish the SSH tunnel, ssh complains about not being able to bind (and hence forward) BoxA's port 22. The subsequent ssh 127.0.0.2 (in a new shell on BoxA) gives a fingerprint warning, which if bypassed, logs me back into BoxA. Makes sense - sshd on BoxA is listening to all interfaces.
Looking at the sshd_config in each, both are configured to listen on 0.0.0.0 (and :: for IPv6).
lsof for OSX gives:
launchd 1 root 40u IPv6 0xddfcabed61001f0d 0t0 TCP *:ssh (LISTEN)
launchd 1 root 41u IPv4 0xddfcabed6100413d 0t0 TCP *:ssh (LISTEN)
launchd 1 root 43u IPv6 0xddfcabed61001f0d 0t0 TCP *:ssh (LISTEN)
launchd 1 root 44u IPv4 0xddfcabed6100413d 0t0 TCP *:ssh (LISTEN)
and for Ubuntu:
sshd 1287 0 3u IPv4 21903340 0t0 TCP *:ssh (LISTEN)
So both are listening on all interfaces, though I'm not sure why OSX uses 4 processes. In any case, Ubuntu gives the expected behaviour. Why does OSX behave differently?
The follow up question of course, is how to make Ubuntu behave like OSX in this regard.
While I wish for the sshd_config to have state, wildcards and/or logical operators (e.g. "do not listen on 127.0.0.*; listen on 127.0.0.1") like iptables, it doesn't seem to be the case...