Skip to content

Instantly share code, notes, and snippets.

@thomaspatzke
Created January 19, 2016 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspatzke/4c5ded4b492a6572528d to your computer and use it in GitHub Desktop.
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)
#!/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