Score:0

nftabels rules and rc.local

bv flag

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 ??

djdomi avatar
za flag
for me it looks like you would like to ask on superuser.com instead of here
Score:0
fr flag

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).

E M A avatar
bv flag
it mean no way to connect to server 1 ssh ?? also where should i add these lines ? rc.local ?
fr flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.