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