
모든 연결을 차단하고 싶지만 sshd
하나의 동적 IP가 a에 할당되어 있으므로 <subdomain>.ddns.net
다음 위치에 입력했습니다 /etc/hosts.deny
.
sshd: ALL EXCEPT <subdomain>.ddns.net
SSH에 연결할 수 없습니다.
대신 해당 호스트 이름으로 확인된 IP를 배치하면( dig <subdomain>.ddns.net
확인) 작동합니다.
sshd: ALL EXCEPT <ipv4.resolved.by.hostname>
나는 또한 with UseDNS yes
또는 no
in 을 시도했지만 sshd_config
아무것도 바뀌지 않았습니다.
방화벽(UFW)은 규칙에 따라 열려 있습니다.ufw limit ssh
내 실제 내용 /etc/ssh/sshd_config
은 다음과 같습니다.
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
KexAlgorithms [email protected]
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]
PermitRootLogin no
AllowUsers remotessh
IgnoreRhosts yes
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding no
PrintMotd no
PubkeyAuthentication yes
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no
UseDNS no
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
답변1
이 문제는 연결하려는 IP 주소가 subdomain.ddns.net이 아닌 xxx.yourisp.com과 반대이기 때문에 발생할 가능성이 높습니다.
(동적) IP 주소에서 sshd에 연결을 시도하면 tcpwrappers는 IP 주소에서 역방향 DNS 조회를 수행합니다. 이것이 xxx.yourisp.com으로 확인되면 Hosts.allow 또는 (hosts.deny에서) 일치하는 항목을 찾지 못하므로 IP에서 sshd에 대한 연결을 허용하지 않습니다.
해결 방법으로 subdomain.ddns.net을 /etc/hosts 파일에 추가하고 몇 분마다 실행되는 cron 작업을 생성하고 변경될 때마다 동적 IP 주소로 이 항목을 업데이트하는 것을 고려할 수 있습니다. 이는 매우 우아한 해결책은 아니지만 최근에 제가 직접 이 문제에 직면했을 때 생각해낼 수 있는 최선의 방법입니다. 더 깨끗한 솔루션을 아는 사람이 있으면 의견을 말해주세요.
답변2
/etc/hosts.allow
이 작업을 수행하려면 및 둘 다 사용합니다 /etc/hosts.deny
. 에 /etc/hosts.allow
다음을 입력합니다.
sshd: blablabla.ddns.net
/etc/hosts.deny에 다음 내용을 삽입합니다.
sshd: ALL
/etc/hosts.allow
겹치기 때문에 작동합니다 /etc/hosts.deny
. 하지만 문제가 있습니다. 서버가 헤어핀 NAT(NAT 반사라고도 함) 뒤에 있는 경우 일부 연결은 게이트웨이의 내부 IP 주소와 함께 서버에 표시되므로 차단하기 어려울 수 있습니다.
또 다른 옵션은 다음과 같이 iptables를 사용하는 것입니다.
iptables -t filter -A INPUT -s blablabla.ddns.net -p tcp --dport 22 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport -j DROP
iptables는 규칙의 순서를 고려한다는 점에 유의하세요.
행운을 빌어요.
답변3
도메인 목록을 IP 목록으로 만들고 이를 호스트.허용에 포함시키는 스크립트를 사용하고 있습니다.
설명은 다음과 같습니다.