qubes-setup-dnat-to-ns 942 B

1234567891011121314151617181920212223242526272829
  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. fi
  14. }
  15. export PATH=$PATH:/sbin:/bin
  16. # shellcheck disable=SC1091
  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. # shellcheck disable=SC2034
  24. while read -r x y z ; do
  25. addrule "$y"
  26. done
  27. (echo "*nat"; echo "$RULE1"; echo "$RULE2"; echo COMMIT) | iptables-restore -n
  28. )