Created
April 3, 2017 07:53
-
-
Save uksysadmin/bbb6c0cc467c96c9ca71f913327774a9 to your computer and use it in GitHub Desktop.
router.sh
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
#!/bin/sh | |
# The interface that has outbound connectivity to the Internet | |
GATEWAY_INTERFACE=p2p1 | |
# What network interfaces do you want to allow routing out via this router | |
INTERNAL_INTERFACES="p4p1.254 | |
p4p1.239 | |
p4p1.236" | |
echo "Setting up routing..." | |
echo "[${GATEWAY_INTERFACE}] GATEWAY INTERFACE" | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
iptables -F | |
iptables -X | |
iptables -t nat -F | |
iptables -t nat -X | |
iptables -t mangle -F | |
iptables -t mangle -X | |
iptables -P INPUT ACCEPT | |
iptables -P FORWARD ACCEPT | |
iptables -P OUTPUT ACCEPT | |
iptables -t nat -A POSTROUTING -o p2p1 -j MASQUERADE | |
for I in ${INTERNAL_INTERFACES} | |
do | |
echo "[${I}] -> [${GATEWAY_INTERFACE}]" | |
iptables -A FORWARD -i ${I} -o ${GATEWAY_INTERFACE} -m state --state RELATED,ESTABLISHED -j ACCEPT | |
iptables -A FORWARD -i ${I} -o ${GATEWAY_INTERFACE} -j ACCEPT | |
done | |
echo "Routing complete" | |
echo | |
echo "Routing Table" | |
netstat -rn | |
echo | |
echo "[IPTABLES: NAT]" | |
iptables -t nat -L -n -v | |
echo | |
echo "[IPTABLES: FORWARD]" | |
iptables -L -n -v | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment