Skip to content

Instantly share code, notes, and snippets.

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

Inject IP Tables

#/bin/bash
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 1.2.3.4 -j DNAT --to-destination $ip_vm

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

Delete IP Tables

#/bin/bash

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