3일에 걸친 트러블 슈팅을 했다.
그 줄거리를 쓰려고한다.
우선 결론만 말하면 아직 원인을 못찾았다.
예상되는 문제는 루프백 문제고, NAT모드에서는 루프백 기능이 제공되는 공유기여야 외부 IP로 접속이 가능하다는데
분명 내가 그렇게 접속을 했으니 루프백 기능을 제공하는거같긴한데, 중간에 끊긴걸 보면 어떤 문제가 생긴듯하다.
아직도 못 밝힌 문제는 브리지모드, NAT모드 둘다 내부IP로 접속을 시도하면 IPV4수신대기를 안해서 접속을 못하고 있다는 것이다. 접속을 시도하면 인증키를 못찾고, 수신대기를 해보면 IPV6만 대기를 하고있는데 이 원인을 못찾고있다.
실제로 해볼 수 있는 시도는 다해본거같다.
1. CONFIG 설정
이거는 진짜 너무 많이 해봐서 외울지경이다.
PORT, ADDRESS ANY, 0.0.0.0, :: 뭐 이런거 다해봐도 이 문제는 아니다.
IPV4만 수신대기 하는 모든 설정
이걸 하면 IPV6만 대기가 가능한 상황이라 그냥 SSH가 오류가 발생한다.
방화벽, 네트워크, 포트
방화벽은 다 없애고, 네트워크는 공유기에 랜선을 직접 찝어서 직접연결도 해보고, 왠만한 설정은 다 해봤는데 안되었다.
포트는 머릿속으로 그릴 수 있는 모든 포트를 다 포워딩해봤고, 기본 포트로 다시 해봐도 안되었다.
이제 줄거리를 말해보려고한다.
개발 DB를 만지던 중에 SSH접속이 끊기고 재접속이 안된다.
1번 트러블 슈팅에 했던 방법대로 SSH 망가진 패키지를 찾아보았지만 패키지 문제가 아니었다. 1번에서 다시 어떻게 연결한건지 모르겠다.
SSH를 새로 깔아보았다.
해결되지 않았다.
문제를 찾아보다가 여러 명령어를 써보았다.
sudo apt remove --purge openssh-server -y
sudo apt autoremove -y
sudo apt clean
sudo rm -rf /etc/ssh
sudo apt update
sudo apt install openssh-server -y
sudo systemctl status ssh
sudo nano /etc/ssh/sshd_config
PasswordAuthentication yes
sudo systemctl restart ssh
sudo ss -tuln | grep ssh
sudo ufw allow 22
sudo ufw reload
이렇게 모든 설정을 다지우고 다시 해보다가 이상한 현상을 발견한다.
✘ youngjoo ~ ssh -vvv -p 2222 joo@172.30.1.48
OpenSSH_9.7p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/ matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for
debug2: resolve_canonicalize: hostname 172.30.1.48 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/youngjoo/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/youngjoo/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: channel_clear_timeouts: clearing
debug3: ssh_connect_direct: entering
debug1: Connecting to 172.30.1.48 [172.30.1.48] port 2222.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
debug1: identity file /Users/youngjoo/.ssh/id_rsa type -1
debug1: identity file /Users/youngjoo/.ssh/id_rsa-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_ecdsa type -1
debug1: identity file /Users/youngjoo/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/youngjoo/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_ed25519 type 3
debug1: identity file /Users/youngjoo/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/youngjoo/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_xmss type -1
debug1: identity file /Users/youngjoo/.ssh/id_xmss-cert type -1
debug1: identity file /Users/youngjoo/.ssh/id_dsa type -1
debug1: identity file /Users/youngjoo/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.7
오류 내용은 인증키 문제였다. 인증키를 새로 시도하다보니 여러개가 만들어졌고, 권한문제 등 많이걸려서 계속 오류가 발생해서 모두지우고 하나의 인증키로 접근한다.
어림없다 되지않는다.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
권한을 바꾼다
되지않는다.
CONFIG 설정을 다시 본다
Include /etc/ssh/sshd_config.d/*.conf
Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
HostKey /etc/ssh/ssh_host_ed25519_key
PermitRootLogin no
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
X11Forwarding yes
PrintMotd no
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
PubkeyAuthentication yes
이렇게 해놨다.
되지않는다.
로그를 확인해본다.
2024-11-14T15:40:24.075410+09:00 livflow sshd[3633]: Invalid user demo from 203.246.113.63 port 57772
2024-11-14T15:40:24.082412+09:00 livflow sshd[3633]: pam_unix(sshd:auth): check pass; user unknown
2024-11-14T15:40:24.082472+09:00 livflow sshd[3633]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=203.246.113.63
2024-11-14T15:40:26.722796+09:00 livflow sshd[3633]: Failed password for invalid user demo from 203.246.113.63 port 57772 ssh2
2024-11-14T15:40:27.070027+09:00 livflow sshd[3633]: Connection closed by invalid user demo 203.246.113.63 port 57772 [preauth]
2024-11-14T15:40:30.428144+09:00 livflow sshd[3635]: Invalid user cuongnd from 203.246.113.63 port 44096
2024-11-14T15:40:30.436843+09:00 livflow sshd[3635]: pam_unix(sshd:auth): check pass; user unknown
2024-11-14T15:40:30.436981+09:00 livflow sshd[3635]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=203.246.113.63
2024-11-14T15:40:32.488752+09:00 livflow sshd[3635]: Failed password for invalid user cuongnd from 203.246.113.63 port 44096 ssh2
2024-11-14T15:40:32.912468+09:00 livflow sshd[3635]: Connection closed by invalid user cuongnd 203.246.113.63 port 44096 [preauth]
이상하게 로그가 길다.
이상한 포트로 접근을 누가 시도한다.
처음엔 내가한줄알았다.
잠시 뒤 다시 로그를 본다
2024-11-14T15:52:54.295408+09:00 livflow sshd[2058]: Connection closed by invalid user jekim 203.246.113.63 port 38200 [preauth]
2024-11-14T15:53:00.329058+09:00 livflow sshd[2060]: Invalid user ubuntu from 203.246.113.63 port 47514
2024-11-14T15:53:00.335391+09:00 livflow sshd[2060]: Connection closed by invalid user ubuntu 203.246.113.63 port 47514 [preauth]
2024-11-14T15:53:05.986108+09:00 livflow sshd[2130]: Invalid user quylm from 203.246.113.63 port 47522
2024-11-14T15:53:05.992276+09:00 livflow sshd[2130]: Connection closed by invalid user quylm 203.246.113.63 port 47522 [preauth]
2024-11-14T15:53:12.091687+09:00 livflow sshd[2618]: Invalid user test from 203.246.113.63 port 34378
2024-11-14T15:53:12.101667+09:00 livflow sshd[2618]: Connection closed by invalid user test 203.246.113.63 port 34378 [preauth]
2024-11-14T15:53:17.829762+09:00 livflow sshd[2911]: Invalid user vagrant from 203.246.113.63 port 34386
2024-11-14T15:53:17.844432+09:00 livflow sshd[2911]: Connection closed by invalid user vagrant 203.246.113.63 port 34386 [preauth]
2024-11-14T15:53:23.683355+09:00 livflow sshd[2968]: Invalid user jenkins from 203.246.113.63 port 36266
2024-11-14T15:53:23.696381+09:00 livflow sshd[2968]: Connection closed by invalid user jenkins 203.246.113.63 port 36266 [preauth]
누가 난수의 이름과 난수의 포트로 내 서버에 접속을 계속 시도하고있다.
해킹봇인가보다.
별의별일이 다있지만 이녀석이 접속에 부하를 걸어서 내 접속이 끊겼다는 생각이 들었다.
IP가 고정되어있길래 공유기에 IP를 등록하고 DENY를 걸어준다.
LOG가 멈췄다.
이제 해결됬나보다
SSH를 접속해본다.
어림없다 되지않는다.
다시 상태를본다.
ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/usr/lib/systemd/system/ssh.service; disabled; preset: ena>
Active: active (running) since Fri 2024-11-15 18:23:14 KST; 5min ago
TriggeredBy: ● ssh.socket
Docs: man:sshd(8)
man:sshd_config(5)
Process: 4140 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 4141 (sshd)
Tasks: 1 (limit: 6855)
Memory: 2.1M (peak: 3.8M)
CPU: 59ms
CGroup: /system.slice/ssh.service
└─4141 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
SSH가 정상인가? DISABLE이 뜨긴하는데 정상이란다.
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xeu ssh.service" for details.
이번엔SSH 상태가 이상하다고 뜬다.
강제로 IPV4 수신대기를 했더니 수신가능한 IPV6가 없어져서 상태 이상이 뜬다.
(generate:5021): WARNING : 19:40:27.548: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
(process:5020): WARNING : 19:40:28.090: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
(process:5020): WARNING : 19:40:28.289: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
그렇게 접속이 안된다.
sudo chmod 600 /etc/netplan/01-netcfg.yaml
sudo chown root:root /etc/netplan/01-netcfg.yaml
권한을 준다.
PING 테스트를 해본다
PING google.com (172.217.175.78) 56(84) bytes of data.
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=1 ttl=57 time=41.6 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=2 ttl=57 time=37.4 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=3 ttl=57 time=39.6 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=4 ttl=57 time=37.5 ms
인터넷은 잘된다.
░░ 결과는 failed 입니다.
11월 15 19:36:51 livflow systemd[1]: ssh.service: Scheduled restart job, restar>
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ Automatic restarting of the unit ssh.service has been scheduled, as the resu>
░░ the configured Restart= setting for the unit.
11월 15 19:36:51 livflow systemd[1]: ssh.service: Start request repeated too qu>
11월 15 19:36:51 livflow systemd[1]: ssh.service: Failed with result 'exit-code>
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit ssh.service has entered the 'failed' state with result 'exit-code'.
11월 15 19:36:51 livflow systemd[1]: Failed to start ssh.service - OpenBSD Secu>
░░ Subject: ssh.service 유닛 동작 실패
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ ssh.service 유닛 동작에 실패했습니다.
░░
░░ 결과는 failed 입니다.
어림없다 되지않는다.
sudo sysctl -a | grep net.ipv4
sudo sysctl -w net.ipv4.conf.all.rp_filter=1
sudo sysctl -w net.ipv4.conf.default.rp_filter=1
sudo sysctl -p
sudo systemctl restart ssh
IPV4 수신에 대한 설정을 바꾼다
tcp6 0 0 :::22 :::* LISTEN 1/init
IPV4는 대기하지않는다.
혹시 DOCKER 소켓이 포트에서 수신을 방해할 가능성도 있다.
sudo systemctl stop docker
sudo systemctl restart ssh
joo@livflow:~$ sudo systemctl stop docker
sudo systemctl restart ssh
Stopping 'docker.service', but its triggering units are still active:
docker.socket
sudo systemctl stop docker.socket
sudo systemctl stop docker.service
sudo systemctl status docker
sudo systemctl status docker.socket
DOCKER 를 모두 멈춰본다
어림없다 되지않는다.
sudo nano /etc/systemd/system/ssh.service.d/override.conf
오버라이드 CONF를 수정해본다.
[Service]
ExecStart=
ExecStart=/usr/sbin/sshd -D -4
RESTART가 되지않는다.
내가 졌다. 브리지모드로 넘어간다.
모든 NAT 설정을 바꾸고 브리지모드 설정을 새로한다음 시도해본다.
PING google.com (172.217.175.78) 56(84) bytes of data.
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=1 ttl=57 time=41.6 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=2 ttl=57 time=37.4 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=3 ttl=57 time=39.6 ms
64 bytes from nrt20s20-in-f14.1e100.net (172.217.175.78): icmp_seq=4 ttl=57 time=37.5 ms
핑을 테스트해보니
브릿지모드가 제대로 된듯하다.
이제 끝이다.
joo@livflow:~$ sudo netstat -tulnp | grep ':22'
tcp6 0 0 :::22 :::* LISTEN 1/init
말도 안된다. 이럴수는 없다. IPV4는 수신대기를 하지않는다.
이유를 알수없다.
좋아 내가 졌다.
아무래도 네트워크 설정을 하다가 꼬인게 분명하다.
VM을 새로깔아보겠다.
기존의 홈서버를 지우고 새로운 서버를 깔았다.
joo@liv:~$ sudo systemctl restart ssh
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xeu ssh.service" for details.
거짓말하지마라 이럴수는 없다.
IPV4만 수신대기를 걸었더니 다시 오류가 발생한다.
도무지 이유를 찾지 못했다.
그러다가 문득 생각이 들었다.
브리지모드의 장점은 포트포워딩이 없는것과 루프백이 없는것.
다시말해 외부 IP로 접속이 가능하지않나...?
맙소사 성공했다.
외부IP로 PEM키를 등록하고 접속하니 SSH가 장장 3일만에 다시 접속이 되었다.
너무 보고싶은 글자였다.
SSH를 사용한다면 브리지모드로 외부접속을 하자..
혹 다시 트러블 슈팅을 하는일이 없길 바라며...