setup-ip 1.5 KB

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