Instantly share code, notes, and snippets.

Embed
What would you like to do?
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