更新 port_forward/port_forward.sh
This commit is contained in:
parent
c89bbb1fa0
commit
b435b1983a
@ -14,6 +14,20 @@ add_port_forwarding() {
|
|||||||
echo "Port forwarding added: $src_port -> $dest_ip:$dest_port"
|
echo "Port forwarding added: $src_port -> $dest_ip:$dest_port"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to delete port forwarding rule
|
||||||
|
delete_port_forwarding() {
|
||||||
|
local protocol=$1
|
||||||
|
local src_port=$2
|
||||||
|
local dest_ip=$3
|
||||||
|
local dest_port=$4
|
||||||
|
|
||||||
|
# Delete the port forwarding rule
|
||||||
|
iptables -t nat -D PREROUTING -p tcp --dport $src_port -j DNAT --to-destination $dest_ip:$dest_port
|
||||||
|
iptables -t nat -D POSTROUTING -p tcp -d $dest_ip --dport $dest_port -j MASQUERADE
|
||||||
|
|
||||||
|
echo "Port forwarding deleted: $src_port -> $dest_ip:$dest_port"
|
||||||
|
}
|
||||||
|
|
||||||
# Function to list port forwarding rules
|
# Function to list port forwarding rules
|
||||||
list_port_forwarding() {
|
list_port_forwarding() {
|
||||||
echo "Current port forwarding rules:"
|
echo "Current port forwarding rules:"
|
||||||
@ -23,9 +37,12 @@ list_port_forwarding() {
|
|||||||
# Main script logic
|
# Main script logic
|
||||||
if [ "$1" == "add" ] && [ "$2" == "ipv4" ]; then
|
if [ "$1" == "add" ] && [ "$2" == "ipv4" ]; then
|
||||||
add_port_forwarding "tcp" $3 $4 $5
|
add_port_forwarding "tcp" $3 $4 $5
|
||||||
|
elif [ "$1" == "delete" ] && [ "$2" == "ipv4" ]; then
|
||||||
|
delete_port_forwarding "tcp" $3 $4 $5
|
||||||
elif [ "$1" == "list" ]; then
|
elif [ "$1" == "list" ]; then
|
||||||
list_port_forwarding
|
list_port_forwarding
|
||||||
else
|
else
|
||||||
echo "Usage: $0 add ipv4 <src_port> <dest_ip> <dest_port>"
|
echo "Usage: $0 add ipv4 <src_port> <dest_ip> <dest_port>"
|
||||||
|
echo " $0 delete ipv4 <src_port> <dest_ip> <dest_port>"
|
||||||
echo " $0 list"
|
echo " $0 list"
|
||||||
fi
|
fi
|
Loading…
Reference in New Issue
Block a user