Created
March 2, 2019 20:43
-
-
Save goffinet/cc56104479957acf78948dd6ace84bd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################################### | |
# program: nat_tables.sh # | |
# Author: Diarmuid O'Briain # | |
# Copyright ©2017 C2S Consulting # | |
# License: www.gnu.org/licenses/gpl.txt # | |
########################################### | |
# NAT masquerade rules for hypervisor, hosting OpenStack testbed # | |
# Select interface, typically 'wlp4s0' for WIFI and 'enp0s3' for wired Ethernet | |
INTERFACE=eth0 # Unhash for wired Ethernet interface | |
#INTERFACE=enp3s0 # Unhash for wired Ethernet interface | |
#INTERFACE=wlp4s0 # Unhash for wireless WIFI interface | |
# Select instance private network | |
#NETWORK=virbr2 | |
NETWORK=vboxnet1 | |
# Flush iptables | |
sudo iptables -F | |
sudo iptables -F -t nat | |
# Enable IP forwarding | |
# For KVM/QEMU | |
# For VirtualBox | |
echo | |
echo "echo \"1\" > /proc/sys/net/ipv4/ip_forward" | |
sudo echo "1" > /proc/sys/net/ipv4/ip_forward | |
echo | |
# Load GNU/Linux kernel modules | |
sudo modprobe ip_tables | |
sudo modprobe ip_conntrack | |
# Add IPTABLES rules | |
sudo iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE | |
sudo iptables -A FORWARD -i $INTERFACE -o $NETWORK -m state --state RELATED,ESTABLISHED -j ACCEPT | |
sudo iptables -A FORWARD -i $NETWORK -o $INTERFACE -j ACCEPT | |
# Print iptables | |
sudo iptables -t nat -v -L POSTROUTING | |
echo | |
sudo iptables -v -L FORWARD | |
# END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment