-# Bring interface down
-
-cmd_ifconfig = "/sbin/ifconfig %s down" % (vif)
-os.system(cmd_ifconfig)
-
# Remove iptables rules
+public_src = os.popen("ifconfig | grep $(ip route | grep default | awk '{print $3}' | awk -F. '{print $1\"[.]\"$2}') | head -1 | awk '{print $2}' | awk -F : '{print $2}'").read().rstrip()
cmd_iptables_del_in = "/sbin/iptables -D INPUT -i %s -m mark ! --mark %d -j DROP 2>/dev/null" % (vif, sliceid)
cmd_iptables_del_out = "/sbin/iptables -D OUTPUT -o %s -m mark ! --mark %d -j DROP 2>/dev/null" % (vif, sliceid)
+cmd_iptables_del_pr = "/sbin/iptables -t nat -D POSTROUTING -s $(ip ro | grep 'dev %s' | head -1 | awk '{print $1}') -j SNAT --to-source %s --random" % (vif, public_src,)
os.system(cmd_iptables_del_in)
os.system(cmd_iptables_del_out)
+os.system(cmd_iptables_del_pr)
+
+# Bring interface down
+cmd_ifconfig = "/sbin/ifconfig %s down" % (vif)
+os.system(cmd_ifconfig)
+