読者です 読者をやめる 読者になる 読者になる

はわわーっ

はわわわわっ

qemuのネットワーク設定

qemu uefi

qemuのネットワークの設定メモ。とりあえずホストと通信できるだけのやつ
Networking - KVM を見ながら適当に

yomi@xenial:~$ cat /etc/qemu-ifup
#!/bin/sh -e

[ -n "$1" ] || exit 1

sw=br0
tap=$1

#ip tuntap add $tap mode tap
ip link set $tap up
ip link set $tap master $sw
yomi@xenial:~$ sudo ip link add br0 type bridge
yomi@xenial:~$ sudo ip link set br0 up
yomi@xenial:~$ sudo ip addr add 192.168.31.1/24 dev br0

qemuqemu-ifupのスクリプト実行する前にtapデバイス作るらしいのでスクリプト中でデバイス作るようにしてたらエラーになった
tunctl complains that device or resource is busy if used in /etc/qemu-ifup script - Unix & Linux Stack Exchange

qemu起動

yomi@xenial:~$ sudo qemu-system-x86_64 -bios ~/ovmf/OVMF.fd -nographic -device e1000,netdev=net0 -netdev tap,id=net0

UEFI Interactive Shell v2.0
EDK II
UEFI v2.40 (EDK II, 0x00010000)
Mapping table
     BLK2: Alias(s):
          PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
     BLK0: Alias(s):
          PciRoot(0x0)/Pci(0x1,0x0)/Floppy(0x0)
     BLK1: Alias(s):
          PciRoot(0x0)/Pci(0x1,0x0)/Floppy(0x1)
Press ESC in 5 seconds to skip startup.nsh or any other key to continue.
Shell> 
Shell> ifconfig -l
eth0
  MAC        : 52-54-00-12-34-56
  Media State: Media present
  Not configured.
Shell> ifconfig -s eth0 static 192.168.31.100 255.255.255.0 192.168.31.1
Create an IP and start to get the default address
Please wait, your console may stop responding for a while ...
      Default: 192.168.31.100
Shell> ifconfig -l
eth0
  MAC        : 52-54-00-12-34-56
  Media State: Media present
  Source     : STATIC
  Permanent  : FALSE
   IP address: 192.168.31.100
         Mask: 255.255.255.0
      Gateway: 192.168.31.1
  Routes (2 entries):
    Entry[0]
       Subnet: 192.168.31.0
      Netmask: 255.255.255.0
      Gateway: 0.0.0.0
    Entry[1]
       Subnet: 0.0.0.0
      Netmask: 0.0.0.0
      Gateway: 192.168.31.1
Shell> ping 192.168.31.1
Ping 192.168.31.1 16 data bytes
16 bytes from 192.168.31.1 : icmp_seq=1 ttl=0 time=42534ms
16 bytes from 192.168.31.1 : icmp_seq=2 ttl=0 time=2483ms
16 bytes from 192.168.31.1 : icmp_seq=3 ttl=0 time=2331ms
16 bytes from 192.168.31.1 : icmp_seq=4 ttl=0 time=1375ms
16 bytes from 192.168.31.1 : icmp_seq=5 ttl=0 time=2924ms
16 bytes from 192.168.31.1 : icmp_seq=6 ttl=0 time=3026ms
16 bytes from 192.168.31.1 : icmp_seq=7 ttl=0 time=2115ms
16 bytes from 192.168.31.1 : icmp_seq=8 ttl=0 time=1586ms
16 bytes from 192.168.31.1 : icmp_seq=9 ttl=0 time=1778ms
16 bytes from 192.168.31.1 : icmp_seq=10 ttl=0 time=1855ms

10 packets transmitted, 10 received, 0% packet loss, time 62007ms

Rtt(round trip time) min=1375ms max=42534ms avg=6200ms