qubes-setup-dnat-to-ns 769 B

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