core-agent-linux/network/setup-ip
Marek Marczykowski-Górecki 4637735882 network: support for not setting DNS and/or default gateway
This patch introduces two new qvm-services:
 - set-default-route
 - set-dns-server
Both enabled by default. You can disable any of them to not set default
route and/or DNS servers in the VM. Those settings have no effect on
NetVM, where such settings are controlled by NetworkManager.

This is based on patch sent by Joonas Lehtonen
<joonas.lehtonen@openmailbox.org>
https://groups.google.com/d/msgid/qubes-devel/54C39656.3090303%40openmailbox.org

Conflicts:
	network/setup-ip
	vm-init.d/qubes-core
	vm-systemd/qubes-sysinit.sh
2015-01-30 00:48:55 +01:00

67 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null`
if [ x$ip != x ]; then
netmask=`/usr/bin/qubesdb-read /qubes-netmask`
gateway=`/usr/bin/qubesdb-read /qubes-gateway`
secondary_dns=`/usr/bin/qubesdb-read /qubes-secondary-dns`
/sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
/sbin/ifconfig $INTERFACE up
/sbin/route add -host $gateway dev $INTERFACE
if [ -f /var/run/qubes-service/set-default-route ]; then
/sbin/route add default gw $gateway
fi
/sbin/ethtool -K $INTERFACE sg off
/sbin/ethtool -K $INTERFACE tx off
echo > /etc/resolv.conf
if [ -f /var/run/qubes-service/set-dns-server ]; then
echo "nameserver $gateway" > /etc/resolv.conf
echo "nameserver $secondary_dns" >> /etc/resolv.conf
fi
if [ -f /var/run/qubes-service/network-manager ]; then
nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
cat > $nm_config <<__EOF__
[802-3-ethernet]
duplex=full
[ethernet]
mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
[connection]
id=VM uplink $INTERFACE
uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
type=802-3-ethernet
[ipv6]
method=ignore
[ipv4]
method=manual
may-fail=false
__EOF__
if [ -f /var/run/qubes-service/set-dns-server ]; then
echo "dns=$gateway;$secondary_dns" >> $nm_config
fi
if [ -f /var/run/qubes-service/set-default-route ]; then
echo "address1=$ip/32,$gateway" >> $nm_config
else
echo "address1=$ip/32" >> $nm_config
fi
chmod 600 $nm_config
fi
network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
if [ "x$network" != "x" ] && [ -f /var/run/qubes-service/set-dns-server ]; then
gateway=$(qubesdb-read /qubes-netvm-gateway)
netmask=$(qubesdb-read /qubes-netvm-netmask)
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
echo "NS1=$gateway" > /var/run/qubes/qubes-ns
echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
/usr/lib/qubes/qubes-setup-dnat-to-ns
fi
if [ "x$network" != "x" ]; then
[ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
# XXX: Backward compatibility
[ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
fi
fi