26 lines
942 B
Bash
26 lines
942 B
Bash
#!/bin/bash
|
|
|
|
iprt=$1
|
|
oprt=$2
|
|
oipa=$3
|
|
|
|
#echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
#iptables -F
|
|
#iptables -t nat -F
|
|
#iptables -t nat -A PREROUTING -p tcp --dport $iprt -j DNAT --to-destination $oipa:$oprt
|
|
#sudo iptables -t nat -A POSTROUTING -j MASQUERADE
|
|
#sudo iptables -t nat -L -n -v
|
|
#sudo iptables-persistent
|
|
|
|
sudo nft -f /etc/nftables.conf
|
|
sudo echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/95-IPv4-forwarding.conf
|
|
sudo sysctl -p /etc/sysctl.d/95-IPv4-forwarding.conf
|
|
sudo sysctl -w net.ipv4.ip_forward=1
|
|
sudo nft add table ip nat
|
|
sudo nft add chain ip nat prerouting { type nat hook prerouting priority -100 \; }
|
|
sudo nft add chain ip nat postrouting { type nat hook postrouting priority 100 \; }
|
|
sudo nft add rule ip nat prerouting tcp dport $iprt dnat to $oipa:$oprt
|
|
sudo nft add rule ip nat postrouting ip daddr $oipa masquerade
|
|
#sudo mkdir /etc/nftables/
|
|
sudo ufw reload
|
|
sudo nft list ruleset #| sudo tee /etc/nftables/port-forwarding.nft |