backgroup
- 为libvirtd 中虚拟机指定ip,操作如下:
virsh --connect qemu:///system dumpxml vm01 | grep "mac address"
virsh --connect qemu:///system net-list
virsh --connect qemu:///system net-edit default
# 增加行 " <host mac='52:54:00:de:fd:d3' name='vm01' ip='192.168.x.x'/>"
# 保存退出
virsh --connect qemu:///system net-destroy default
virsh --connect qemu:///system net-start default
- 操作之后,
brctl show 查看,看到网桥上的网卡信息丢失,包括绑定的物理网卡和虚拟网卡,我的解决办法如下:
brctl addif virbr0 xxx
brctl addif virbr0 xxx
brctl addif virbr0 xxx
附:在 man virsh 中可以看到 virsh 提供了及其丰富的命令,以下是其中虚拟网络相关的命令:
net-autostart network [--disable]
Configure a virtual network to be automatically started at boot. The --disable option disable autostarting.
net-create file
Create a transient (temporary) virtual network from an XML file and instantiate (start) the network. See the documentation
at <https://libvirt.org/formatnetwork.html> to get a description of the XML network format used by libvirt.
net-define file
Define an inactive persistent virtual network or modify an existing persistent one from the XML file.
net-destroy network
Destroy (stop) a given transient or persistent virtual network specified by its name or UUID. This takes effect immediately.
net-dumpxml network [--inactive]
Output the virtual network information as an XML dump to stdout. If --inactive is specified, then physical functions are not expanded into their associated virtual functions.
net-edit network
Edit the XML configuration file for a network.
This is equivalent to:
virsh net-dumpxml --inactive network > network.xml
vi network.xml (or make changes with your other text editor)
virsh net-define network.xml
except that it does some error checking.
The editor used can be supplied by the $VISUAL or $EDITOR environment variables, and defaults to "vi".
net-event {[network] event [--loop] [--timeout seconds] [--timestamp] | --list}
Wait for a class of network events to occur, and print appropriate details of events as they happen. The events can
optionally be filtered by network. Using --list as the only argument will provide a list of possible event values known by
this client, although the connection might not allow registering for all these events.
By default, this command is one-shot, and returns success once an event occurs; you can send SIGINT (usually via "Ctrl-C") to
quit immediately. If --timeout is specified, the command gives up waiting for events after seconds have elapsed. With
--loop, the command prints all events until a timeout or interrupt key.
When --timestamp is used, a human-readable timestamp will be printed before the event.
net-info network
Returns basic information about the network object.
net-list [--inactive | --all] { [--table] | --name | --uuid } [--persistent] [<--transient>] [--autostart] [<--no-autostart>]
Returns the list of active networks, if --all is specified this will also include defined but inactive networks, if
--inactive is specified only the inactive ones will be listed. You may also want to filter the returned networks by
--persistent to list the persistent ones, --transient to list the transient ones, --autostart to list the ones with autostart
enabled, and --no-autostart to list the ones with autostart disabled.
If --name is specified, network names are printed instead of the table formatted one per line. If --uuid is specified
network's UUID's are printed instead of names. Flag --table specifies that the legacy table-formatted output should be used.
This is the default. All of these are mutually exclusive.
NOTE: When talking to older servers, this command is forced to use a series of API calls with an inherent race, where a pool
might not be listed or might appear more than once if it changed state between calls while the list was being collected.
Newer servers do not have this problem.
net-name network-UUID
Convert a network UUID to network name.
net-update network command section xml [--parent-index index] [[--live] [--config] | [--current]]
Update the given section of an existing network definition, with the changes optionally taking effect immediately, without
needing to destroy and re-start the network.
command is one of "add-first", "add-last", "add" (a synonym for add-last), "delete", or "modify".
section is one of "bridge", "domain", "ip", "ip-dhcp-host", "ip-dhcp-range", "forward", "forward-interface", "forward-pf",
"portgroup", "dns-host", "dns-txt", or "dns-srv", each section being named by a concatenation of the xml element hierarchy
leading to the element being changed. For example, "ip-dhcp-host" will change a <host> element that is contained inside a
<dhcp> element inside an <ip> element of the network.
xml is either the text of a complete xml element of the type being changed (e.g. "<host mac="00:11:22:33:44:55'
ip='1.2.3.4'/>", or the name of a file that contains a complete xml element. Disambiguation is done by looking at the first
character of the provided text - if the first character is "<", it is xml text, if the first character is not "<", it is the
name of a file that contains the xml text to be used.
The --parent-index option is used to specify which of several parent elements the requested element is in (0-based). For
example, a dhcp <host> element could be in any one of multiple <ip> elements in the network; if a parent-index isn't
provided, the "most appropriate" <ip> element will be selected (usually the only one that already has a <dhcp> element), but
if --parent-index is given, that particular instance of <ip> will get the modification.
If --live is specified, affect a running network. If --config is specified, affect the next startup of a persistent network.
If --current is specified, affect the current network state. Both --live and --config flags may be given, but --current is
exclusive. Not specifying any flag is the same as specifying --current.
net-dhcp-leases network [mac]
Get a list of dhcp leases for all network interfaces connected to the given virtual network or limited output just for one
interface if mac is specified.