Skip to content

Instantly share code, notes, and snippets.

Last active Sep 6, 2022
What would you like to do?
IPTables Script

Inject IP Tables

iptables -t nat -v -L -n --line-number
echo -n "IP VM who want to exposed (x.x.x.x:port): "
read ip_vm
echo $ip_vm

echo -n "Enter Port Access: " 
read port
echo $port
echo "Will be accessible on port $port"

iptables -t nat -A PREROUTING -p tcp --dport $port -d -j DNAT --to-destination $ip_vm

echo "VM with IP $ip_vm will be publicly on$port"
echo "Escalation Succesfully"
iptables -t nat -v -L -n --line-number

Delete IP Tables


iptables -t nat -v -L -n --line-number

echo -n "Please enter type IP Tables (PREROUTING/POSTROUTING): " 
read TYPE
#echo $TYPE

echo -n "Please enter line number who want you to delete: " 
read number
#echo $number

iptables -t nat --delete $TYPE $number
echo "IP Tables with Line number $number & $TYPE type has been deleted"
iptables -t nat -v -L -n --line-number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment