setup-ip 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. ip=`/usr/bin/xenstore-read qubes-ip 2> /dev/null`
  3. if [ x$ip != x ]; then
  4. netmask=`/usr/bin/xenstore-read qubes-netmask`
  5. gateway=`/usr/bin/xenstore-read qubes-gateway`
  6. secondary_dns=`/usr/bin/xenstore-read qubes-secondary-dns`
  7. /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
  8. /sbin/ifconfig $INTERFACE up
  9. /sbin/route add -host $gateway dev $INTERFACE
  10. /sbin/route add default gw $gateway
  11. /sbin/ethtool -K $INTERFACE sg off
  12. /sbin/ethtool -K $INTERFACE tx off
  13. echo "nameserver $gateway" > /etc/resolv.conf
  14. echo "nameserver $secondary_dns" >> /etc/resolv.conf
  15. network=$(/usr/bin/xenstore-read qubes-netvm-network 2>/dev/null)
  16. if [ "x$network" != "x" ]; then
  17. gateway=$(/usr/bin/xenstore-read qubes-netvm-gateway)
  18. netmask=$(/usr/bin/xenstore-read qubes-netvm-netmask)
  19. secondary_dns=$(/usr/bin/xenstore-read qubes-netvm-secondary-dns)
  20. echo "NS1=$gateway" > /var/run/qubes/qubes-ns
  21. echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
  22. /usr/lib/qubes/qubes-setup-dnat-to-ns
  23. [ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
  24. # XXX: Backward compatibility
  25. [ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
  26. fi
  27. if [ -f /var/run/qubes-service/network-manager ]; then
  28. cat > /etc/sysconfig/network-scripts/ifcfg-$INTERFACE <<__EOF__
  29. DEVICE=$INTERFACE
  30. IPADDR=$ip
  31. NETMASK=255.255.255.255
  32. NETWORK=$ip
  33. ONBOOT=yes
  34. GATEWAYDEV=$INTERFACE
  35. GATEWAY=$gateway
  36. __EOF__
  37. fi
  38. fi