libvirt: 既存の Tap インターフェイスを VM に割り当てる

libvirt: 既存の Tap インターフェイスを VM に割り当てる

qemu / kvmを使用して仮想マシンを作成し、既存のTapインターフェースを仮想マシンに割り当てたいと思います。virshCLIまたはGUIを使用してvirt-managerこれを行うには?

私はこの手動のqemu呼び出しに対応するlibvirtを探しています。

qemu-system-x86_64 -net nic, モデル=virtio, macaddr= -net tap, ifname=MY_EXISTING_TAP_INTERFACE, script=no

ブリッジを含むすべてのネットワークを直接管理する複雑なマルチホームファイアウォールとルーターがあるので、これをしたいです。仮想マシンは私が準備したTapインターフェースのみを使用し、他の操作は実行したくありません。

ベストアンサー1

virt-manager GUIを使用すると、仮想マシンの詳細を表示したり、ボタンをクリックしたり、ダイアログボックスで詳細を選択して入力したりできますAdd HardwareNetwork

コマンドラインでを使用できます。virsh attach-interfaceまたは、NICに適したXMLフラグメントを作成/コピーした場合は、次のようにしますvirsh attach-device(BTW、attach-interfaceサブコマンドには--print-xmlインターフェイスを接続するのではなくXMLフラグメントのみを印刷するオプションがあります)。

virshマニュアルページとlibvirt.orgウェブサイトには幅広い組み込みヘルプもあります。たとえば、

# virsh attach-interface --help
  NAME
    attach-interface - attach network interface

  SYNOPSIS
    attach-interface <domain> <type> <source> [--target <string>] [--mac <string>]
      [--script <string>] [--model <string>] [--alias <string>] [--inbound <string>]
      [--outbound <string>] [--persistent] [--config] [--live] [--current] [--print-xml]
      [--managed] [--source-mode <string>]

  DESCRIPTION
    Attach new network interface.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--type] <string>  network interface type
    [--source] <string>  source of network interface
    --target <string>  target network name
    --mac <string>   MAC address
    --script <string>  script used to bridge network interface
    --model <string>  model type
    --alias <string>  custom alias name of interface device
    --inbound <string>  control domain's incoming traffics
    --outbound <string>  control domain's outgoing traffics
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain
    --print-xml      print XML document rather than attach the interface
    --managed        libvirt will automatically detach/attach the device from/to host
    --source-mode <string>  mode attribute of <source/> element


# virsh attach-device --help
  NAME
    attach-device - attach device from an XML file

  SYNOPSIS
    attach-device <domain> <file> [--persistent] [--config] [--live] [--current]

  DESCRIPTION
    Attach device from an XML <file>.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--file] <string>  XML file
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

覚えておいて、一緒にlibvirtすべてVM情報(「ドメイン」)は最終的にXMLを使用して構成されます。 libvirt自体とlibvirtが管理するすべての仮想マシンのXML構成ファイルと構成ファイルの断片を作成および変更するためのツールですvirshvirt-manager

virshドメインの完全なXML構成、または特定のデバイスのXMLフラグメントを標準出力にダンプするためのいくつかのコマンドがあります。後で使用するためにファイルにリダイレクトすることができます。あるいは、これと同様のものを使用して変更することもできますxmlstarlet(XML出力は便利にほぼ行指向の形式なので、awk、sed、perlなどを使用して合理的に変更できますが、ツールを使用する方が良いでしょう)。または、言語の正しい XML を解析して生成し、再利用して既存の VM を更新するか、若干異なる新しい VM を作成することもできます。

たとえば、コマンドとXML構成ファイル/フラグメントで実行できる操作をvirsh help | grep -i xml確認するには、実行してみてください。virsh

しかし、さまざまな「編集」サブコマンド(たとえば、、editなど)は、XMLを目的のエディタ(通常または環境変数を介して)にロードして編集できるようにします。変更を保存した後にXMLが確認に合格すると、編集中のアイテムに基づいて仮想マシンまたはそれ自体を再構成するために使用されます。iface-editpool-edit$EDITOR$VISUALlibvirt

おすすめ記事