mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
DHCP
This commit is contained in:
parent
298ec4c90b
commit
66df790cb4
@ -15,7 +15,7 @@ set -eu
|
|||||||
# Functions
|
# Functions
|
||||||
# ######################################
|
# ######################################
|
||||||
|
|
||||||
configureMacVlan () {
|
configureDHCP() {
|
||||||
|
|
||||||
VM_NET_TAP="_VmMacvtap"
|
VM_NET_TAP="_VmMacvtap"
|
||||||
echo "Info: Retrieving IP via DHCP using MAC ${VM_NET_MAC}..."
|
echo "Info: Retrieving IP via DHCP using MAC ${VM_NET_MAC}..."
|
||||||
@ -49,10 +49,10 @@ configureMacVlan () {
|
|||||||
mknod ${_tmpTapPath} c $MAJOR $MINOR && : || ("ERROR: Cannot mknod: ${_tmpTapPath}" && exit 20)
|
mknod ${_tmpTapPath} c $MAJOR $MINOR && : || ("ERROR: Cannot mknod: ${_tmpTapPath}" && exit 20)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30 ${NET_OPTS} 30<>${_tmpTapPath} 40<>/dev/vhost-net"
|
NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30 30<>${_tmpTapPath} 40<>/dev/vhost-net"
|
||||||
}
|
}
|
||||||
|
|
||||||
configureNatNetwork () {
|
configureNAT () {
|
||||||
|
|
||||||
VM_NET_IP='20.20.20.21'
|
VM_NET_IP='20.20.20.21'
|
||||||
VM_NET_TAP="_VmNatTap"
|
VM_NET_TAP="_VmNatTap"
|
||||||
@ -81,7 +81,7 @@ configureNatNetwork () {
|
|||||||
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
|
||||||
chmod 644 /var/lib/misc/dnsmasq.leases
|
chmod 644 /var/lib/misc/dnsmasq.leases
|
||||||
|
|
||||||
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0 ${NET_OPTS}"
|
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"
|
||||||
|
|
||||||
# Build DNS options from container /etc/resolv.conf
|
# Build DNS options from container /etc/resolv.conf
|
||||||
nameservers=($(grep '^nameserver' /etc/resolv.conf | sed 's/nameserver //'))
|
nameservers=($(grep '^nameserver' /etc/resolv.conf | sed 's/nameserver //'))
|
||||||
@ -136,15 +136,16 @@ update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
|||||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||||
|
|
||||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
||||||
NET_OPTS="-device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
|
||||||
|
|
||||||
if [[ "$GATEWAY" == "172."* ]]; then
|
if [[ "$GATEWAY" == "172."* ]]; then
|
||||||
# Configuration for bridge network
|
# Configuration for static IP
|
||||||
configureNatNetwork
|
configureNAT
|
||||||
else
|
else
|
||||||
# Configuration for macvlan network
|
# Configuration for DHCP IP
|
||||||
configureMacVlan
|
configureDHCP
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
||||||
|
|
||||||
# Hack for guest VMs complaining about "bad udp checksums in 5 packets"
|
# Hack for guest VMs complaining about "bad udp checksums in 5 packets"
|
||||||
iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill
|
iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill
|
||||||
|
Loading…
x
Reference in New Issue
Block a user