qubes-setup-dnat-to-ns 897 B

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