지금 ssh
은 인터넷을 ssh
통해 호스트에서 가상 머신으로 호스트 할 수 있습니다. 내가하고 싶은 일은 ssh
외부에서 게스트 컴퓨터로 직접 보내는 것입니다.
나는 이것을 사용하여 이것을 시도했다 iptables
:
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 2222 -j DNAT --to-destination 192.168.130.128:22
또한 관련 포트를 열었습니다 UFW
.
ufw allow routed
ufw allow outgoing
ufw deny incoming
ufw allow 2222/tcp
방화벽을 다시로드 한 후 원격 ssh
이 멈추고 debug1: Connecting to x.x.x.x [x.x.x.x] port 2222
사용 tcpdump -i vmnet8 'port 22'
하면 다음을 볼 수 있습니다.
listening on vmnet8, link-type EN10MB (Ethernet), capture size 65535 bytes
18:56:03.002790 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [S], seq 1077492285, win 29200, options [mss 1260,sackOK,TS val 1388564 ecr 0,nop,wscale 7], length 0
18:56:03.003235 IP y.y.y.y.ssh > x.x.x.x.13203: Flags [S.], seq 3535035554, ack 1077492286, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 307333897 ecr 1388564,sackOK,eol], length 0
18:56:03.003290 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [R], seq 1077492286, win 32767, length 0
18:56:03.996287 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [S], seq 1077492285, win 29200, options [mss 1260,sackOK,TS val 1388664 ecr 0,nop,wscale 7], length 0
18:56:03.996770 IP y.y.y.y.ssh > x.x.x.x.13203: Flags [S.], seq 1749343118, ack 1077492286, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 307334888 ecr 1388664,sackOK,eol], length 0
18:56:03.996841 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [R], seq 1077492286, win 32767, length 0
18:56:05.997104 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [S], seq 1077492285, win 29200, options [mss 1260,sackOK,TS val 1388864 ecr 0,nop,wscale 7], length 0
18:56:06.001310 IP y.y.y.y.ssh > x.x.x.x.13203: Flags [S.], seq 3571006762, ack 1077492286, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 307336889 ecr 1388864,sackOK,eol], length 0
18:56:06.001344 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [R], seq 1077492286, win 32767, length 0
18:56:10.006741 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [S], seq 1077492285, win 29200, options [mss 1260,sackOK,TS val 1389265 ecr 0,nop,wscale 7], length 0
18:56:10.007142 IP y.y.y.y.ssh > x.x.x.x.13203: Flags [S.], seq 1524745855, ack 1077492286, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 307340890 ecr 1389265,sackOK,eol], length 0
18:56:10.007217 IP x.x.x.x.13203 > y.y.y.y.ssh: Flags [R], seq 1077492286, win 32767, length 0
tcpdump
내 MacOS
손님에 동일한 결과가 발생합니다.
- 호스트 : Ubuntu 14.04
- 게스트 : 맥 OS 매버릭스
- 가상화 플랫폼 : Vmware Workstation 11
최신 정보:
이것은 ufw
로그 메시지입니다 (로그 높음).
Jun 21 09:47:44 srv05-crawler kernel: [518567.737815] [UFW AUDIT] IN=eth0 OUT=vmnet8 MAC=00:25:90:ef:aa:a0:00:24:c4:c0:d3:40:08:00 SRC=x.x.x.x DST=192.168.130.128 LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=15454 DF PROTO=TCP SPT=20039 DPT=22 WINDOW=29200 RES=0x00 SYN URGP=0
Jun 21 09:47:44 srv05-crawler kernel: [518567.737828] [UFW ALLOW] IN=eth0 OUT=vmnet8 MAC=00:25:90:ef:aa:a0:00:24:c4:c0:d3:40:08:00 SRC=x.x.x.x DST=192.168.130.128 LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=15454 DF PROTO=TCP SPT=20039 DPT=22 WINDOW=29200 RES=0x00 SYN URGP=0
Jun 21 09:47:45 srv05-crawler kernel: [518568.733572] [UFW AUDIT] IN=eth0 OUT=vmnet8 MAC=00:25:90:ef:aa:a0:00:24:c4:c0:d3:40:08:00 SRC=x.x.x.x DST=192.168.130.128 LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=15455 DF PROTO=TCP SPT=20039 DPT=22 WINDOW=29200 RES=0x00 SYN URGP=0
Jun 21 09:47:45 srv05-crawler kernel: [518568.733592] [UFW ALLOW] IN=eth0 OUT=vmnet8 MAC=00:25:90:ef:aa:a0:00:24:c4:c0:d3:40:08:00 SRC=x.x.x.x DST=192.168.130.128 LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=15455 DF PROTO=TCP SPT=20039 DPT=22 WINDOW=29200 RES=0x00 SYN URGP=0a
그리고이 명령을 사용하여 삭제 된 패킷 로그를 얻습니다.
iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A OUTPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPT Drops: " --log-level 4
iptables -A LOGGING -j DROP
하지만 어떤 dropped
패키지도 추적 할 수 없었습니다 .
업데이트 2 :
친구들이 요청한 iptables 구성 :
# Generated by iptables-save v1.4.21 on Sun Jun 21 16:46:49 2015
*nat
:PREROUTING ACCEPT [1363:113716]
:INPUT ACCEPT [39:2210]
:OUTPUT ACCEPT [3135:202553]
:POSTROUTING ACCEPT [3146:203213]
-A PREROUTING -p tcp -m tcp --dport 2222 -j DNAT --to-destination 192.168.130.128:22
COMMIT
# Completed on Sun Jun 21 16:46:49 2015
# Generated by iptables-save v1.4.21 on Sun Jun 21 16:46:49 2015
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:LOGGING - [0:0]
:fail2ban-ssh - [0:0]
:ufw-after-forward - [0:0]
:ufw-after-input - [0:0]
:ufw-after-logging-forward - [0:0]
:ufw-after-logging-input - [0:0]
:ufw-after-logging-output - [0:0]
:ufw-after-output - [0:0]
:ufw-before-forward - [0:0]
:ufw-before-input - [0:0]
:ufw-before-logging-forward - [0:0]
:ufw-before-logging-input - [0:0]
:ufw-before-logging-output - [0:0]
:ufw-before-output - [0:0]
:ufw-logging-allow - [0:0]
:ufw-logging-deny - [0:0]
:ufw-not-local - [0:0]
:ufw-reject-forward - [0:0]
:ufw-reject-input - [0:0]
:ufw-reject-output - [0:0]
:ufw-skip-to-policy-forward - [0:0]
:ufw-skip-to-policy-input - [0:0]
:ufw-skip-to-policy-output - [0:0]
:ufw-track-forward - [0:0]
:ufw-track-input - [0:0]
:ufw-track-output - [0:0]
:ufw-user-forward - [0:0]
:ufw-user-input - [0:0]
:ufw-user-limit - [0:0]
:ufw-user-limit-accept - [0:0]
:ufw-user-logging-forward - [0:0]
:ufw-user-logging-input - [0:0]
:ufw-user-logging-output - [0:0]
:ufw-user-output - [0:0]
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -p tcp -m tcp --dport 22022 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -j ufw-before-logging-input
-A INPUT -j ufw-before-input
-A INPUT -j ufw-after-input
-A INPUT -j ufw-after-logging-input
-A INPUT -j ufw-reject-input
-A INPUT -j ufw-track-input
-A INPUT -j LOGGING
-A FORWARD -j ufw-before-logging-forward
-A FORWARD -j ufw-before-forward
-A FORWARD -j ufw-after-forward
-A FORWARD -j ufw-after-logging-forward
-A FORWARD -j ufw-reject-forward
-A FORWARD -j ufw-track-forward
-A OUTPUT -j ufw-before-logging-output
-A OUTPUT -j ufw-before-output
-A OUTPUT -j ufw-after-output
-A OUTPUT -j ufw-after-logging-output
-A OUTPUT -j ufw-reject-output
-A OUTPUT -j ufw-track-output
-A OUTPUT -j LOGGING
-A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPtables dropped: "
-A LOGGING -j DROP
-A fail2ban-ssh -j RETURN
-A ufw-after-input -p udp -m udp --dport 137 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 138 -j ufw-skip-to-policy-input
-A ufw-after-input -p tcp -m tcp --dport 139 -j ufw-skip-to-policy-input
-A ufw-after-input -p tcp -m tcp --dport 445 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 67 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 68 -j ufw-skip-to-policy-input
-A ufw-after-input -m addrtype --dst-type BROADCAST -j ufw-skip-to-policy-input
-A ufw-after-logging-input -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW BLOCK] "
-A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 12 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A ufw-before-forward -j ufw-user-forward
-A ufw-before-input -i lo -j ACCEPT
-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
-A ufw-before-input -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 12 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A ufw-before-input -p udp -m udp --sport 67 --dport 68 -j ACCEPT
-A ufw-before-input -j ufw-not-local
-A ufw-before-input -d 224.0.0.251/32 -p udp -m udp --dport 5353 -j ACCEPT
-A ufw-before-input -d 239.255.255.250/32 -p udp -m udp --dport 1900 -j ACCEPT
-A ufw-before-input -j ufw-user-input
-A ufw-before-output -o lo -j ACCEPT
-A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-output -j ufw-user-output
-A ufw-logging-allow -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW ALLOW] "
-A ufw-logging-deny -m conntrack --ctstate INVALID -m limit --limit 3/min --limit-burst 10 -j RETURN
-A ufw-logging-deny -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW BLOCK] "
-A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN
-A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN
-A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN
-A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny
-A ufw-not-local -j DROP
-A ufw-skip-to-policy-forward -j ACCEPT
-A ufw-skip-to-policy-input -j DROP
-A ufw-skip-to-policy-output -j ACCEPT
-A ufw-track-forward -p tcp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-track-forward -p udp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-track-output -p tcp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-track-output -p udp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 22022 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 2222 -j ACCEPT
-A ufw-user-limit -m limit --limit 3/min -j LOG --log-prefix "[UFW LIMIT BLOCK] "
-A ufw-user-limit -j REJECT --reject-with icmp-port-unreachable
-A ufw-user-limit-accept -j ACCEPT
COMMIT
# Completed on Sun Jun 21 16:46:49 2015
그리고 ufw status numbered
:
Status: active
To Action From
-- ------ ----
[ 1] 22022/tcp ALLOW IN Anywhere
[ 2] 2222/tcp ALLOW IN Anywhere
tcpdump
출력 보다 방화벽 로그가 더 흥미 롭습니다 . VM이 요청에 응답 할 수 있지만 누가 호스트가 나가지 않는다고 말하는가? 또한 시스템에서 IPv4 전달이 활성화되어 있다고 가정합니까? 그러나 DNAT는 두 가지 방식으로 작동하지만 패킷이 나가는 경우에만 가능합니다.