setup-ip 2.9 KB

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