qubes-setup-dnat-to-ns 661 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. addrule()
  3. {
  4. if [ $FIRSTONE = yes ] ; then
  5. FIRSTONE=no
  6. RULE1="-A PR-QBS -d $NS1 -p udp --dport 53 -j DNAT --to $1"
  7. else
  8. RULE2="-A PR-QBS -d $NS2 -p udp --dport 53 -j DNAT --to $1"
  9. NS=$NS2
  10. fi
  11. }
  12. export PATH=$PATH:/sbin:/bin
  13. . /var/run/qubes/qubes-ns
  14. if [ "X"$NS1 = "X" ] ; then exit ; fi
  15. iptables -t nat -F PR-QBS
  16. FIRSTONE=yes
  17. grep ^nameserver /etc/resolv.conf | grep -v ":.*:" | head -2 |
  18. (
  19. while read x y z ; do
  20. addrule "$y"
  21. done
  22. (echo "*nat"; echo $RULE1; echo $RULE2; echo COMMIT) | iptables-restore -n
  23. )