On 2020-08-27 09:40, Grant Edwards wrote:
> I'm trying to figure out how to conifgure openssh sshd to listen on
> specific interface(s). I know how to configure it to listen on a
> specific IP address, but what do you do when using DHCP and don't know
> what IP address is going to be assigned.
>
> I do _not_ want it to listen on 0.0.0.0.
>
> I want it to listen on 127.0.0.1 and on whatever IP addresses are
> assigned to two specified interfaces.
>
You could modify the OpenRC init script to figure out what IP addresses
belong to those interfaces beforehand. The grep/sed here is ugly and I'm
sure there's a better way to do it, but this proves it's possible.
#!/bin/sh
INTERFACES="lo enp3s0"
SSHD_OPTS=""
for iface in ${INTERFACES}; do
for ip in $(ip addr show dev "${iface}" | \
grep inet | \
sed "s/ *inet \([0-9\.]*\).*/\1/g"); do
SSHD_OPTS="${SSHD_OPTS} -o \"ListenAddress ${ip}\""
done
done
echo "${SSHD_OPTS}"