From 8f392d32abdb6f2191d0a9b37f9b28f80fc26cf3 Mon Sep 17 00:00:00 2001 From: Randall Date: Thu, 4 Jul 2024 10:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20pve/port=5Fforward/port=5F?= =?UTF-8?q?forward.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pve/port_forward/port_forward.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pve/port_forward/port_forward.sh b/pve/port_forward/port_forward.sh index 34f6928..0f95b4c 100644 --- a/pve/port_forward/port_forward.sh +++ b/pve/port_forward/port_forward.sh @@ -8,11 +8,11 @@ add_forwarding() { local internal_port=$4 if [ "$proto" == "ipv4" ]; then - iptables -t nat -A PREROUTING -p tcp --dport $external_port -j DNAT --to-destination $internal_ip:$internal_port + iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport $external_port -j DNAT --to-destination $internal_ip:$internal_port iptables -A FORWARD -p tcp -d $internal_ip --dport $internal_port -j ACCEPT echo "已添加 IPv4 转发: $external_port -> $internal_ip:$internal_port" elif [ "$proto" == "ipv6" ]; then - ip6tables -t nat -A PREROUTING -p tcp --dport $external_port -j DNAT --to-destination [$internal_ip]:$internal_port + ip6tables -t nat -A PREROUTING -i vmbr0 -p tcp --dport $external_port -j DNAT --to-destination [$internal_ip]:$internal_port ip6tables -A FORWARD -p tcp -d $internal_ip --dport $internal_port -j ACCEPT echo "已添加 IPv6 转发: $external_port -> $internal_ip:$internal_port" else @@ -26,11 +26,11 @@ delete_forwarding() { local external_port=$2 if [ "$proto" == "ipv4" ]; then - iptables -t nat -D PREROUTING -p tcp --dport $external_port -j DNAT + iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport $external_port -j DNAT iptables -D FORWARD -p tcp --dport $external_port -j ACCEPT echo "已删除 IPv4 转发: $external_port" elif [ "$proto" == "ipv6" ]; then - ip6tables -t nat -D PREROUTING -p tcp --dport $external_port -j DNAT + ip6tables -t nat -D PREROUTING -i vmbr0 -p tcp --dport $external_port -j DNAT ip6tables -D FORWARD -p tcp --dport $external_port -j ACCEPT echo "已删除 IPv6 转发: $external_port" else @@ -110,4 +110,4 @@ case "$command" in usage exit 1 ;; -esac \ No newline at end of file +esac