From 21a9c4d5ebbda6dac8d227dc076b6fb529c7dea9 Mon Sep 17 00:00:00 2001 From: veypi Date: Mon, 21 Dec 2020 18:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1=E6=98=A0?= =?UTF-8?q?=E5=B0=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux/rip | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 linux/rip diff --git a/linux/rip b/linux/rip new file mode 100755 index 0000000..184158e --- /dev/null +++ b/linux/rip @@ -0,0 +1,54 @@ +#!/bin/bash + +chan=pride +chan_pre=$chan'_pre' +chan_forward=$chan'_forward' +chan_post=$chan'_post' +to=192.168.122.245 +to_port=3389 +from=10.69.115.207 +from_port=19520 + +## 清空 引用 +sudo iptables -t nat -nvL PREROUTING --line-number | awk -F ' ' 'BEGIN{c=0} /'${chan_pre}'/ {printf "%s %s %s\n",c, $1,$4;system("sudo iptables -t nat -D PREROUTING "$1-c);c++}' +sudo iptables -t filter -nvL FORWARD --line-number | awk -F ' ' 'BEGIN{c=0} /'${chan_forward}'/ {printf "%s %s %s\n",c, $1,$4;system("sudo iptables -t filter -D FORWARD "$1-c);c++}' +sudo iptables -t nat -nvL POSTROUTING --line-number | awk -F ' ' 'BEGIN{c=0} /'${chan_post}'/ {printf "%s %s %s\n",c, $1,$4;system("sudo iptables -t nat -D POSTROUTING "$1-c);c++}' + +## 清空自定义链 +sudo iptables -t nat -F $chan_pre +sudo iptables -t filter -F $chan_forward +sudo iptables -t nat -F $chan_post +## 删除自定义链 +sudo iptables -t nat -X $chan_pre +sudo iptables -t filter -X $chan_forward +sudo iptables -t nat -X $chan_post + +## 创建自定义链 +sudo iptables -t nat -N $chan_pre +sudo iptables -t filter -N $chan_forward +sudo iptables -t nat -N $chan_post + +sudo iptables -t nat -p tcp -d $from --dport $from_port -j DNAT --to $to:$to_port -I $chan_pre +sudo iptables -t nat -p udp -d $from --dport $from_port -j DNAT --to $to:$to_port -I $chan_pre + +sudo iptables -t filter -d $to -j ACCEPT -I $chan_forward + +sudo iptables -t nat -p tcp -d $to --dport $to_port -j SNAT --to $from -I $chan_post +sudo iptables -t nat -p udp -d $to --dport $to_port -j SNAT --to $from -I $chan_post + +## 引用新链 +sudo iptables -t nat -I PREROUTING -j $chan_pre +sudo iptables -t filter -I FORWARD -j $chan_forward +sudo iptables -t nat -I POSTROUTING -j $chan_post + +#iptables -L +sudo iptables -t nat -nvL $chan_pre --line-number +sudo iptables -t nat -nvL PREROUTING --line-number +echo "\n\n" +sudo iptables -t filter -nvL $chan_forward --line-number +sudo iptables -t filter -nvL FORWARD --line-number +echo "\n\n" +sudo iptables -t nat -nvL $chan_post --line-number +sudo iptables -t nat -nvL POSTROUTING --line-number + +