Created
January 19, 2016 22:46
-
-
Save thomaspatzke/4c5ded4b492a6572528d to your computer and use it in GitHub Desktop.
Shell script to quickly switch between real Internet connection (NAT) and simulated (INetSim)
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/bash | |
case "$1" in | |
router) | |
sysctl -w net.ipv4.ip_forward=1 | |
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |
systemctl start dnsmasq.service | |
;; | |
router-stop) | |
sysctl -w net.ipv4.ip_forward=0 | |
iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE | |
systemctl stop dnsmasq.service | |
;; | |
inetsim) | |
iptables -t nat -A PREROUTING -i eth1 -j REDIRECT | |
inetsim | |
iptables -t nat -D PREROUTING -i eth1 -j REDIRECT | |
;; | |
*) | |
echo "Usage: $0 {router|router-stop|inetsim}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment