0

i have problem like this
this is my iptables rules

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination (( my first server ))
iptables -t nat -A PREROUTING -j DNAT --to-destination (( my second server ))
iptables -t nat -A POSTROUTING -j MASQUERADE

i want to change these rules to nftables what should i do ?

also i always add these to nano /etc/rc.local and then chmod +x /etc/rc.local

so how could i build rc.local nftables and save them for always ??

Tomek
  • 3,390
  • 1
  • 16
  • 10
E M A
  • 1

1 Answers1

0

This probably would look like below:

table inet nftables_svc {
        chain PREROUTING {
                type nat hook prerouting priority dstnat; policy accept;
                meta l4proto tcp th dport 22 dnat ip to (( my first server ))
                dnat ip to (( my second server ))
        }

        chain POSTROUTING {
                type nat hook postrouting priority srcnat; policy accept;
                masquerade
        }
}

Please note that the rules as they are may redirect ALL traffic to your servers (nothing will ever get delivered to the host with the rules) and also will masquerade ALL traffic leaving the host. The rules seem too broad (and definitely the PREROUTING rules should match on destination IP address).

Tomek
  • 3,390
  • 1
  • 16
  • 10
  • it mean no way to connect to server 1 ssh ?? also where should i add these lines ? rc.local ? – E M A May 14 '23 at 10:25
  • Yes, these rules redirect ALL traffic somewhere else. And the placement of the rules depends on the distro you use, which you didn't specify. – Tomek May 14 '23 at 12:11