Wednesday, April 11, 2018

To add/delete a NAT rule

==========================

# To add a rule

// you are listening on a server @127.0.0.1 and want to expose to ouside.
// you can add a rule as below.
// now anyone accessing YOUR_NODE_IP_ADDRESS:8443 will be redirected to 127.0.0.1:8443
iptables -t nat -A PREROUTING -p tcp --dport 8443 -j DNAT --to-destination 127.0.0.1:8443

==========================
# To delete a RULE

// This will list according to groups like PREROUTING , INPUT, OUTPUT, POSTROUTING , etc.,
iptables -t nat -L --line-numbers

// to delete a specific rule
iptables -t nat -D PREROUTING <number>

// For example, here to delete third rule
iptables -t nat -D PREROUTING 3

==========================

No comments:

Post a Comment