Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active October 27, 2024 11:07
Show Gist options
  • Save gilangvperdana/28d7410a75954cdc4995407078ac7ae8 to your computer and use it in GitHub Desktop.
Save gilangvperdana/28d7410a75954cdc4995407078ac7ae8 to your computer and use it in GitHub Desktop.
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

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

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