Я выполнил шаги документации на GitHub (https://github.com/yrutschle/sslh/blob/master/doc/config.md), используя параметр --transparent
в файле /etc/default/sslh
.
Пример, если Apache прослушивает порт 4443 вместо 443 и если мы также используем OpenVPN:
DAEMON_OPTS="--user sslh --transparent --listen 0.0.0.0:443 --ssh 127.0.0.1:22 --ssl 127.0.0.1:4443 --openvpn 127.0.0.1:1194 --pidfile /var/run/sslh/sslh.pid"
Обратите внимание, что вам может потребоваться заменить 127.0.0.1:1194
вашим IP-адресом VPN, за которым следует:1194
(https://github.com/yrutschle/sslh/issues/83#issuecomment-515675186).
Если вам нужна поддержка IPv6, вы можете заменить 0.0.0.0 доменным именем с двойным стеком -, указывающим на ваш удаленный IPv4/IPv6, и заменить 127.0.0.1 на localhost
, которое должно указывать на ваш локальный IPv4/IPv6. IPv6, если он правильно настроен в /etc/hosts
.
Чтобы сделать его постоянным после перезагрузки в Debian, мне пришлось добавить эти post-up
правила для локального интерфейса в /etc/network/interfaces
под существующей конфигурацией:
# The loopback network interface
auto lo
iface lo inet loopback
# Configure routing for those marked packets (required by sslh transparent mode for IPv4)
post-up ip rule add fwmark 0x1 lookup 100
post-up ip route add local 0.0.0.0/0 dev lo table 100
iface lo inet6 loopback
# Configure routing for those marked packets (required by sslh transparent mode for IPv6)
post-up ip -6 rule add fwmark 0x1 lookup 100
post-up ip -6 route add local ::/0 dev lo table 100
И эти правила в/etc/sysctl.conf
:
# Set route_localnet = 1 on all interfaces so that ssl can use "localhost" as destination (required by sslh transparent mode)
net.ipv4.conf.default.route_localnet=1
net.ipv4.conf.all.route_localnet=1
В документации также есть некоторые правила iptables, которые можно сделать постоянными с помощью iptables-persistent
, например (Не знаю почему, но при тестировании прозрачный режим работал без этих правил):
# DROP martian packets as they would have been if route_localnet was zero
# Note: packets not leaving the server aren't affected by this, thus sslh will still work
iptables -t raw -A PREROUTING ! -i lo -d 127.0.0.0/8 -j DROP
iptables -t mangle -A POSTROUTING ! -o lo -s 127.0.0.0/8 -j DROP
# Mark all connections made by ssl for special treatment (here sslh is run as user "sslh")
iptables -t nat -A OUTPUT -m owner --uid-owner sslh -p tcp --tcp-flags FIN,SYN,RST,ACK SYN -j CONNMARK --set-xmark 0x01/0x0f
# Outgoing packets that should go to sslh instead have to be rerouted, so mark them accordingly (copying over the connection mark)
iptables -t mangle -A OUTPUT ! -o lo -p tcp -m connmark --mark 0x01/0x0f -j CONNMARK --restore-mark --mask 0x0f
Для IPv6:
# DROP martian packets as they would have been if route_localnet was zero
# Note: packets not leaving the server aren't affected by this, thus sslh will still work
ip6tables -t raw -A PREROUTING ! -i lo -d ::1/128 -j DROP
ip6tables -t mangle -A POSTROUTING ! -o lo -s ::1/128 -j DROP
# Mark all connections made by ssl for special treatment (here sslh is run as user "sslh")
ip6tables -t nat -A OUTPUT -m owner --uid-owner sslh -p tcp --tcp-flags FIN,SYN,RST,ACK SYN -j CONNMARK --set-xmark 0x01/0x0f
# Outgoing packets that should go to sslh instead have to be rerouted, so mark them accordingly (copying over the connection mark)
ip6tables -t mangle -A OUTPUT ! -o lo -p tcp -m connmark --mark 0x01/0x0f -j CONNMARK --restore-mark --mask 0x0f