Tôi chỉ cần cho phép ssh thông qua VPN (openvpn) bằng iptables. Tất cả các dịch vụ (ssh, vpn) được đặt trên cùng một máy. Quy tắc hiện tại của tôi cho vpn và ssh:
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
iptables -A INPUT -i $LO -j CHẤP NHẬN
iptables -A OUTPUT -o $LO -j CHẤP NHẬN
iptables -A INPUT -p tcp ! --syn -m conntrack --ctstate NEW -j DROP -m comment --comment "phân đoạn tcp đầu tiên yêu cầu bit SYN"
iptables -A INPUT -p tcp --tcp-flags TẤT CẢ TẤT CẢ -j DROP -m comment --comment "drop XMAS packets"
iptables -A INPUT -p tcp --tcp-flags TẤT CẢ KHÔNG CÓ -j DROP -m comment --comment "drop NULL packets"
iptables -A INPUT -p icmp --icmp-type address-mask-request -j DROP -m comment --comment "bỏ các cuộc tấn công smurf ICMP"
iptables -A INPUT -p icmp --icmp-type timestamp-request -j DROP
iptables -A INPUT -p icmp --icmp-type router-sotication -j DROP
iptables -A INPUT -p icmp -m giới hạn --limit 2/giây -j CHẤP NHẬN
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP -m comment --comment "bỏ các gói bị đọc sai (không hợp lệ)"
iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP
iptables -A OUTPUT -m conntrack --ctstate INVALID -j DROP
iptables -A INPUT -i $WAN -p tcp -m conntrack --ctstate MỚI, THÀNH LẬP --dport $PORT_OPENVPN -j CHẤP NHẬN
iptables -A OUTPUT -o $WAN -p tcp -m conntrack --ctstate ESTABLISHED --sport $PORT_OPENVPN -j CHẤP NHẬN
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o $WAN -j MASQUERADE
iptables -A FORWARD -s 10.8.0.0/24 -o $WAN -j CHẤP NHẬN
iptables -A FORWARD -i $TUN -o $WAN -m conntrack --ctstate LIÊN QUAN, THÀNH LẬP -j CHẤP NHẬN
iptables -A FORWARD -i $WAN -o $TUN -m conntrack --ctstate LIÊN QUAN, THÀNH LẬP -j CHẤP NHẬN
iptables -t nat -I POSTROUTING -p tcp -m tcp --sport $PORT_SSH -o $TUN -j MASQUERADE
iptables -A FORWARD -i $TUN -o $WAN -p tcp --dport $PORT_SSH -j CHẤP NHẬN
iptables -A FORWARD -i $WAN -o $TUN -p tcp --sport $PORT_SSH -j CHẤP NHẬN
iptables -A INPUT -p tcp -m tcp --dport $PORT_SSH -j CHẤP NHẬN
iptables -A OUTPUT -p tcp -m tcp --sport $PORT_SSH -j CHẤP NHẬN
nhưng hiện tại ssh không hoạt động qua vpn cũng như không có nó. Tôi đang làm gì sai?
CẬP NHẬT đầu ra của ssh -vv
:
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Đọc dữ liệu cấu hình .ssh/config
debug2: resolve_canonicalize: tên máy chủ <ĐỊA CHỈ IP VPS TẠI ĐÂY> là địa chỉ
gỡ lỗi2: ssh_connect_direct
debug1: Đang kết nối với <ĐỊA CHỈ IP VPS TẠI ĐÂY> [<ĐỊA CHỈ IP VPS TẠI ĐÂY>] cổng 22.
debug1: Đã thiết lập kết nối.
debug1: tệp nhận dạng .ssh/id_rsa loại -1
debug1: tệp nhận dạng .ssh/id_rsa-cert loại -1
debug1: tệp nhận dạng .ssh/id_dsa loại -1
debug1: tệp nhận dạng .ssh/id_dsa-cert loại -1
debug1: tệp nhận dạng .ssh/id_ecdsa loại -1
debug1: tệp nhận dạng .ssh/id_ecdsa-cert loại -1
debug1: tệp nhận dạng .ssh/id_ed25519 gõ -1
debug1: tệp nhận dạng .ssh/id_ed25519-cert loại -1
debug1: tệp nhận dạng .ssh/id_xmss gõ -1
debug1: tệp nhận dạng .ssh/id_xmss-cert loại -1
debug1: Chuỗi phiên bản cục bộ SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Phiên bản giao thức từ xa 2.0, phiên bản phần mềm từ xa OpenSSH_7.6p1 Ubuntu-4ubuntu0.5
debug1: khớp: OpenSSH_7.6p1 Ubuntu-4ubuntu0.5 vỗ OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7. Tương thích 7* 0x04000002
debug2: cài đặt fd 3 O_NONBLOCK
debug1: Xác thực <ĐỊA CHỈ IP VPS TẠI ĐÂY>:22 là '<ĐĂNG NHẬP TẠI ĐÂY>'
gỡ lỗi1: Đã gửi SSH2_MSG_KEXINIT
gỡ lỗi1: Đã nhận được SSH2_MSG_KEXINIT
debug2: đề xuất KEXINIT của khách hàng cục bộ
debug2: Thuật toán KEX: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16 -sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: thuật toán khóa máy chủ: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,rsa- sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384, ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-ed25519-cert-v01@openssh.com,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MAC ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: Kho MAC: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: nén ctos: none,zlib@openssh.com,zlib
debug2: kho lưu trữ nén: none,zlib@openssh.com,zlib
debug2: ngôn ngữ ctos:
debug2: kho ngôn ngữ:
gỡ lỗi2: first_kex_follows 0
gỡ lỗi2: dành riêng 0
debug2: đề xuất KEXINIT của máy chủ ngang hàng
debug2: Thuật toán KEX: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16 -sha512, diffie-hellman-group18-sha512, diffie-hellman-group14-sha256, diffie-hellman-group14-sha1
debug2: thuật toán khóa máy chủ: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MAC ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: Kho MAC: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: nén ctos: none,zlib@openssh.com
debug2: kho lưu trữ nén: none,zlib@openssh.com
debug2: ngôn ngữ ctos:
debug2: kho ngôn ngữ:
gỡ lỗi2: first_kex_follows 0
gỡ lỗi2: dành riêng 0
gỡ lỗi1: kex: thuật toán: đường cong25519-sha256
debug1: kex: thuật toán khóa máy chủ: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> nén: không có
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> nén: không có
gỡ lỗi1: mong đợi SSH2_MSG_KEX_ECDH_REPLY
debug1: Khóa máy chủ của máy chủ: ecdsa-sha2-nistp256 SHA256:qUdNYwEs+cvEVkMKTz4RNOObOBsIByhRaehiNvybIi4
debug1: Máy chủ '<ĐỊA CHỈ IP VPS TẠI ĐÂY>' đã biết và khớp với khóa máy chủ ECDSA.
debug1: Đã tìm thấy khóa trong .ssh/known_hosts:3
gỡ lỗi2: set_newkeys: chế độ 1
debug1: thoát ra sau 134217728 khối
gỡ lỗi1: Đã gửi SSH2_MSG_NEWKEYS
gỡ lỗi1: mong đợi SSH2_MSG_NEWKEYS
gỡ lỗi1: Đã nhận được SSH2_MSG_NEWKEYS
gỡ lỗi2: set_newkeys: chế độ 0
debug1: nhập lại sau khối 134217728
debug1: pubkey_prepare: ssh_get_authentication_socket: Không có tệp hoặc thư mục như vậy
debug1: Sẽ thử khóa: .ssh/id_rsa
debug1: Sẽ thử khóa: .ssh/id_dsa
debug1: Sẽ thử khóa: .ssh/id_ecdsa
debug1: Sẽ thử khóa: .ssh/id_ed25519
debug1: Sẽ thử khóa: .ssh/id_xmss
gỡ lỗi2: pubkey_prepare: xong
gỡ lỗi1: Đã nhận được SSH2_MSG_EXT_INFO
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2 -nistp521>
gỡ lỗi2: service_accept: ssh-userauth
gỡ lỗi1: Đã nhận được SSH2_MSG_SERVICE_ACCEPT
debug1: Xác thực có thể tiếp tục: khóa công khai, mật khẩu
debug1: Phương thức xác thực tiếp theo: publickey
debug1: Đang thử khóa riêng tư: .ssh/id_rsa
debug1: Đang thử khóa riêng tư: .ssh/id_dsa
debug1: Đang thử khóa riêng: .ssh/id_ecdsa
debug1: Đang thử khóa riêng tư: .ssh/id_ed25519
debug1: Đang thử khóa riêng tư: .ssh/id_xmss
debug2: chúng tôi đã không gửi gói, vô hiệu hóa phương thức
debug1: Phương thức xác thực tiếp theo: mật khẩu
debug1: read_passphrase: không thể mở/dev/tty: Không có tệp hoặc thư mục như vậy
<ĐĂNG NHẬP TẠI ĐÂY>@<ĐỊA CHỈ IP VPS TẠI ĐÂY> Mật khẩu của:
debug2: chúng tôi đã gửi gói mật khẩu, đợi phản hồi
debug1: Xác thực thành công (mật khẩu).
Đã xác thực với <ĐỊA CHỈ IP VPS TẠI ĐÂY> ([<ĐỊA CHỈ IP VPS TẠI ĐÂY>]:22).
debug1: kênh 0: [phiên khách hàng] mới
debug2: kênh 0: gửi mở
debug1: Yêu cầu no-more-sessions@openssh.com
debug1: Đang vào phiên tương tác.
gỡ lỗi1: cam kết: mạng
gỡ lỗi1: ENABLE_VIRTUAL_TERMINAL_INPUT được hỗ trợ. Đọc VTSequence từ bảng điều khiển
gỡ lỗi1: ENABLE_VIRTUAL_TERMINAL_PROCESSING được hỗ trợ. Bảng điều khiển hỗ trợ phân tích cú pháp ansi
gỡ lỗi1: client_input_global_request: rtype hostkeys-00@openssh.com muốn_reply 0
debug2: channel_input_open_confirmation: kênh 0: bắt đầu gọi lại
debug2: cài đặt fd 3 TCP_NODELAY
gỡ lỗi2: client_session2_setup: id 0
debug2: kênh 0: yêu cầu pty-req xác nhận 1
debug2: kênh 0: yêu cầu shell xác nhận 1
debug2: channel_input_open_confirmation: kênh 0: gọi lại xong
debug2: kênh 0: mở xác nhận rwindow 0 rmax 32768
debug2: channel_input_status_confirm: nhập 99 id 0
debug2: Yêu cầu phân bổ PTY được chấp nhận trên kênh 0
debug2: kênh 0: rcvd điều chỉnh 2097152
debug2: channel_input_status_confirm: nhập 99 id 0
debug2: yêu cầu shell được chấp nhận trên kênh 0