Skip to content

Instantly share code, notes, and snippets.

@azharimad
Last active September 11, 2023 10:29
Show Gist options
  • Save azharimad/ba0a8006717e91d810c8d5b528d06e40 to your computer and use it in GitHub Desktop.
Save azharimad/ba0a8006717e91d810c8d5b528d06e40 to your computer and use it in GitHub Desktop.
Gre Front
#!/bin/bash
#
# Install iptables iproute2
# Variables
#
#
GRE_FRONT_IP=""
GRE_BACK_IP=""
#
# DO NOT CHANGE ANYTHING PAST THIS POINT
#
# make sure iptables isn't blocking FORWARD
iptables -P FORWARD ACCEPT
# enable IP forwarding and proxy ARP so we can forward our DDOS IP
sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv4.conf.eth0.proxy_arp=1
# bring up our GRE to our Backend server
ip tunnel add gre1 mode gre local $GRE_FRONT_IP remote $GRE_BACK_IP ttl 255
ip link set gre1 up
# add local IP addresses
ip addr add 192.168.168.1/30 dev gre1
# Setup NAT
iptables -t nat -A POSTROUTING -s 192.168.168.0/30 ! -o gre+ -j SNAT --to-source $GRE_FRONT_IP
# Setup Forwarding
iptables -t nat -A PREROUTING -d $GRE_FRONT_IP -j DNAT --to-destination 192.168.168.2
iptables -A FORWARD -d 192.168.168.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
##!/bin/sh
##A-Server-Front
#apt install iptables iproute2
#lsmod | grep gre
#modprobe ip_gre
#lsmod | grep gre
#echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
#sysctl -p
#ip tunnel add gre1 mode gre local front-ip remote backend-ip ttl 255
#ip addr add 10.0.0.1/30 dev gre1
#ip link set gre1 up
#iptables -t nat -A POSTROUTING -s 10.0.0.0/30 ! -o gre+ -j SNAT --to-source front-ip
#iptables -A FORWARD -d 10.0.0.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#iptables -A FORWARD -s 10.0.0.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#iptables -t nat -A PREROUTING -d front-ip -j DNAT --to-destination 10.0.0.2
#iptables -A FORWARD -d 10.0.0.2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment