Created
December 16, 2019 00:50
-
-
Save Asher256/3b78f0e164b635b72feb34a61b052db0 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env /bin/sh | |
# | |
# This script uses Linux iptables to route and masquerade ipv4 traffic | |
# from a network interface to another. | |
# | |
# License: MIT | |
# | |
# Author: Asher256 | |
# Github: https://github.com/Asher256 | |
# Website: http://www.asher256.com/ | |
# | |
set -e | |
set -u | |
in_nic=eth0 | |
out_nic=eth1 | |
# Flush old iptables rules | |
iptables -F; iptables -X | |
iptables -t nat -F; iptables -t nat -X | |
iptables -t mangle -F; iptables -t mangle -X | |
# Iptables policies (accept OUTPUT only) | |
iptables -P INPUT DROP | |
iptables -P FORWARD DROP | |
iptables -P OUTPUT ACCEPT | |
# Route and masquerade traffic | |
iptables -A FORWARD -i "$in_nic" -o "$out_nic" -j ACCEPT | |
iptables -A FORWARD -i "$out_nic" -o "$in_nic" -m state --state RELATED,ESTABLISHED -j ACCEPT | |
iptables -t nat -A POSTROUTING -o "$out_nic" -j MASQUERADE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment