setup-ip 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # Source Qubes library.
  3. . /usr/lib/qubes/init/functions
  4. have_qubesdb || exit 0
  5. ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null`
  6. if [ x$ip != x ]; then
  7. netmask=`/usr/bin/qubesdb-read /qubes-netmask`
  8. gateway=`/usr/bin/qubesdb-read /qubes-gateway`
  9. primary_dns=`/usr/bin/qubesdb-read /qubes-primary-dns 2>/dev/null || echo $gateway`
  10. secondary_dns=`/usr/bin/qubesdb-read /qubes-secondary-dns`
  11. /sbin/ethtool -K $INTERFACE sg off
  12. /sbin/ethtool -K $INTERFACE tx off
  13. # If NetworkManager is enabled, let it configure the network
  14. if qsvc network-manager ; then
  15. nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
  16. cat > $nm_config <<__EOF__
  17. [802-3-ethernet]
  18. duplex=full
  19. [ethernet]
  20. mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
  21. [connection]
  22. id=VM uplink $INTERFACE
  23. uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
  24. type=802-3-ethernet
  25. [ipv6]
  26. method=ignore
  27. [ipv4]
  28. method=manual
  29. may-fail=false
  30. __EOF__
  31. if ! qsvc disable-dns-server ; then
  32. echo "dns=$primary_dns;$secondary_dns" >> $nm_config
  33. fi
  34. if ! qsvc disable-default-route ; then
  35. echo "addresses1=$ip;32;$gateway" >> $nm_config
  36. else
  37. echo "addresses1=$ip;32" >> $nm_config
  38. fi
  39. chmod 600 $nm_config
  40. # reload connection
  41. nmcli connection load $nm_config || :
  42. else
  43. # No NetworkManager enabled, configure the network manually
  44. /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
  45. /sbin/ifconfig $INTERFACE up
  46. /sbin/route add -host $gateway dev $INTERFACE
  47. if ! qsvc disable-default-route ; then
  48. /sbin/route add default gw $gateway
  49. fi
  50. if ! is_protected_file /etc/resolv.conf ; then
  51. echo > /etc/resolv.conf
  52. if ! qsvc disable-dns-server ; then
  53. echo "nameserver $primary_dns" > /etc/resolv.conf
  54. echo "nameserver $secondary_dns" >> /etc/resolv.conf
  55. fi
  56. fi
  57. fi
  58. network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
  59. if [ "x$network" != "x" ] && ! qsvc disable-dns-server ; then
  60. gateway=$(qubesdb-read /qubes-netvm-gateway)
  61. netmask=$(qubesdb-read /qubes-netvm-netmask)
  62. primary_dns=$(qubesdb-read /qubes-netvm-primary-dns 2>/dev/null || echo $gateway)
  63. secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
  64. echo "NS1=$primary_dns" > /var/run/qubes/qubes-ns
  65. echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
  66. /usr/lib/qubes/qubes-setup-dnat-to-ns
  67. fi
  68. if [ "x$network" != "x" ]; then
  69. if [ -x /rw/config/qubes-ip-change-hook ]; then
  70. /rw/config/qubes-ip-change-hook
  71. fi
  72. # XXX: Backward compatibility
  73. if [ -x /rw/config/qubes_ip_change_hook ]; then
  74. /rw/config/qubes_ip_change_hook
  75. fi
  76. fi
  77. fi