risc-v中文社区

 找回密码
 立即注册
查看: 1437|回复: 0

Linux 内核调试 七:qemu网络配置

[复制链接]

347

主题

564

帖子

2237

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2237
发表于 2022-8-2 11:20:52 | 显示全部楼层 |阅读模式
参考:
Documentation/Networking - QEMU
QEMU’s new -nic command line option - QEMU
QEMU新的-nic选项 - 知乎 (zhihu.com)
一、网络基础知识
QEMU 中的网络分为两部分:

虚拟机网络设备(qemu提供给虚拟机的虚拟网卡)。
宿主机网络后端设备(虚拟机往虚拟网卡写入的数据都会由网络后端设备流出到真实的网络环境中)。
每个部件都有一系列选项。默认情况下,QEMU 将为来宾创建一个 SLiRP 用户网络后端和一个适当的虚拟网络设备,就好像您在命令行上输入了 -net nic -net user。

按照以上两点,可以来简单区分一下这三种方式:

-net选项可以定义前端和后端;
-netdev选项只能定义后端;
-nic可以一条命令定义前端和后端;
二、-net选项
1、概述
QEMU最初的虚拟机网络配置方式是-net选项。可以通过-net nic,model=xyz,…来配置虚拟机网络设备,然后通过-net < backend >,…来配置虚拟机网络设备。-net 命令如下:

-net nic[,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]
                configure or create an on-board (or machine default) NIC and
                connect it to hub 0 (please use -nic unless you need a hub)
-net [user|tap|bridge|socket][,option][,option][,...]
                old way to initialize a host network interface
                (use the -netdev option if possible instead)

-net 语法会自动创建一个 ID 为 0 的模拟集线器,用于将流量从连接到它的任何设备转发到“VLAN”上的所有其他设备。

2、示例
1、命令
-net nic,model=e1000 -net user -net nic,model=virtio -net tap

2、网络连接


三、-netdev选项
1、概述
为了配置虚拟机网络设备和虚拟机网络设备直接相连的网络,需要使用-netdev和-device搭配使用。-netdev命令如下:

-netdev user,id=str[,ipv4=on|off][,net=addr[/mask]][,host=addr]
         [,ipv6=on|off][,ipv6-net=addr[/int]][,ipv6-host=addr]
         [,restrict=on|off][,hostname=host][,dhcpstart=addr]
         [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]
         [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=rule][,smb=dir[,smbserver=addr]]
                configure a user mode network backend with ID 'str',
                its DHCP server and optional services
-netdev tap,id=str[,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile]
         [,br=bridge][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off]
         [,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]
         [,poll-us=n]
                configure a host TAP network backend with ID 'str'
                connected to a bridge (default=br0)
                use network scripts 'file' (default=/usr/local/etc/qemu-ifup)
                to configure it and 'dfile' (default=/usr/local/etc/qemu-ifdown)
                to deconfigure it
                use '[down]script=no' to disable script execution
                use network helper 'helper' (default=/usr/local/libexec/qemu-bridge-helper) to
                configure it
                use 'fd=h' to connect to an already opened TAP interface
                use 'fds=x:y:...:z' to connect to already opened multiqueue capable TAP interfaces
                use 'sndbuf=nbytes' to limit the size of the send buffer (the
                default is disabled 'sndbuf=0' to enable flow control set 'sndbuf=1048576')
                use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag
                use vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition
                use vhost=on to enable experimental in kernel accelerator
                    (only has effect for virtio guests which use MSIX)
                use vhostforce=on to force vhost on for non-MSIX virtio guests
                use 'vhostfd=h' to connect to an already opened vhost net device
                use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices
                use 'queues=n' to specify the number of queues to be created for multiqueue TAP
                use 'poll-us=n' to specify the maximum number of microseconds that could be
                spent on busy polling for vhost net
-netdev bridge,id=str[,br=bridge][,helper=helper]
                configure a host TAP network backend with ID 'str' that is
                connected to a bridge (default=br0)
                using the program 'helper (default=/usr/local/libexec/qemu-bridge-helper)
-netdev l2tpv3,id=str,src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport]
         [,rxsession=rxsession],txsession=txsession[,ipv6=on|off][,udp=on|off]
         [,cookie64=on|off][,counter][,pincounter][,txcookie=txcookie]
         [,rxcookie=rxcookie][,offset=offset]
                configure a network backend with ID 'str' connected to
                an Ethernet over L2TPv3 pseudowire.
                Linux kernel 3.3+ as well as most routers can talk
                L2TPv3. This transport allows connecting a VM to a VM,
                VM to a router and even VM to Host. It is a nearly-universal
                standard (RFC3931). Note - this implementation uses static
                pre-configured tunnels (same as the Linux kernel).
                use 'src=' to specify source address
                use 'dst=' to specify destination address
                use 'udp=on' to specify udp encapsulation
                use 'srcport=' to specify source udp port
                use 'dstport=' to specify destination udp port
                use 'ipv6=on' to force v6
                L2TPv3 uses cookies to prevent misconfiguration as
                well as a weak security measure
                use 'rxcookie=0x012345678' to specify a rxcookie
                use 'txcookie=0x012345678' to specify a txcookie
                use 'cookie64=on' to set cookie size to 64 bit, otherwise 32
                use 'counter=off' to force a 'cut-down' L2TPv3 with no counter
                use 'pincounter=on' to work around broken counter handling in peer
                use 'offset=X' to add an extra offset between header and data
-netdev socket,id=str[,fd=h][,listen=[host]:port][,connect=host:port]
                configure a network backend to connect to another network
                using a socket connection
-netdev socket,id=str[,fd=h][,mcast=maddr:port[,localaddr=addr]]
                configure a network backend to connect to a multicast maddr and port
                use 'localaddr=addr' to specify the host address to send packets from
-netdev socket,id=str[,fd=h][,udp=host:port][,localaddr=host:port]
                configure a network backend to connect to another network
                using an UDP tunnel
-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]
                configure a vhost-user network, backed by a chardev 'dev'
-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev
                configure a vhost-vdpa network,Establish a vhost-vdpa netdev
-netdev hubport,id=str,hubid=n[,netdev=nd]
                configure a hub port on the hub with ID 'n'


2、示例
1、命令
-netdev user,id=n1 -device e1000,netdev=n1 -netdev tap,id=n2 -device virtio-net,netdev=n2

2、网络连接


3、-netdev弊端
1、使用麻烦,在某些场景下不如-net方便。例如创建默认的tap网络,可以使用定义好的/etc/qemu-ifup和/etc/qemu-ifdown脚本。例如,可以简单的使用-net nic -net tap。如果使用-netdev/-device,命令就很长了,还不得不取一个id:-netdev tap,id=n1 -device e1000,netdev=n1。

2、板载的NIC不能配置成-netdev/-device。

四、-nic选项
1、概述
如果您不关心配置 NIC 的每个细节,还可以使用 -nic 参数将 NIC 与主机后端一起创建。-nic 选项如下:

-nic [tap|bridge|user|l2tpv3|vhost-user|socket][,option][,...][mac=macaddr]
                initialize an on-board / default host NIC (using MAC address
                macaddr) and connect it to the given host network backend
-nic none       use it alone to have zero network devices (the default is to
                provided a 'user' network connection)

使用 -nic model=help 获取受支持的 NIC 型号的列表。

五、-net网络测试
1、概述
本博客使用 win10+VMware+ubuntu+qemu 环境进行测试,故网络拓扑如下:
1、qemu启动前网络拓扑


2、qemu启动后网络拓扑


2、创建 tap0
onlylove@ubuntu:~/My/qemu/qemu-lq$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 6683  bytes 762491 (762.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2331  bytes 271791 (271.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.14  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:feb8:de45  prefixlen 64  scopeid 0x20<link>
        inet6 2408:8207:304e:1c00:20c:29ff:feb8:de45  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:b8:de:45  txqueuelen 1000  (Ethernet)
        RX packets 6994  bytes 739728 (739.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1197  bytes 118950 (118.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 572  bytes 47691 (47.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 572  bytes 47691 (47.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~/My/qemu/qemu-lq$ sudo ip tuntap add dev tap0 mode tap
[sudo] password for onlylove:
onlylove@ubuntu:~/My/qemu/qemu-lq$ sudo ip link set dev tap0 up
onlylove@ubuntu:~/My/qemu/qemu-lq$ sudo ip address add dev tap0 192.168.2.128/24
onlylove@ubuntu:~/My/qemu/qemu-lq$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 6827  bytes 774768 (774.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2444  bytes 284147 (284.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.14  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:feb8:de45  prefixlen 64  scopeid 0x20<link>
        inet6 2408:8207:304e:1c00:20c:29ff:feb8:de45  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:b8:de:45  txqueuelen 1000  (Ethernet)
        RX packets 7010  bytes 741491 (741.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1217  bytes 121082 (121.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 596  bytes 50174 (50.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 596  bytes 50174 (50.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.2.128  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 2a:d7:ae:26:b7:a9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~/My/qemu/qemu-lq$


3、使用qemu启动虚拟机
onlylove@ubuntu:~/My/qemu/qemu-lq$ ./qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8" -dtb vexpress-v2p-ca9.dtb -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no
Booting Linux on physical CPU 0x0
Linux version 4.12.0 (onlylove@ubuntu) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP Fri Apr 22 23:46:21 PDT 2022
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt: Machine model: V2P-CA9
Memory policy: Data cache writeback
On node 0 totalpages: 131072
free_area_init_node: node 0, pgdat 83154c00, node_mem_map 9fbfb000
  Normal zone: 1024 pages used for memmap
  Normal zone: 0 pages reserved
  Normal zone: 131072 pages, LIFO batch:31
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 16 pages/cpu @9fbae000 s36352 r8192 d20992 u65536
pcpu-alloc: s36352 r8192 d20992 u65536 alloc=16*4096
pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: rdinit=/linuxrc console=ttyAMA0 loglevel=8
log_buf_len individual max cpu contribution: 4096 bytes
log_buf_len total cpu_extra contributions: 12288 bytes
log_buf_len min size: 16384 bytes
log_buf_len: 32768 bytes
early log buf free: 15004(91%)
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 469664K/524288K available (6144K kernel code, 359K rwdata, 1328K rodata, 40960K init, 170K bss, 54624K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x80008000 - 0x80700000   (7136 kB)
      .init : 0x80900000 - 0x83100000   (40960 kB)
      .data : 0x83100000 - 0x83159f68   ( 360 kB)
       .bss : 0x83160d24 - 0x8318b804   ( 171 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
Hierarchical RCU implementation.
        RCU debugfs-based tracing is enabled.
        RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
NR_IRQS:16 nr_irqs:16 16
GIC CPU mask not found - kernel will fail to boot.
GIC CPU mask not found - kernel will fail to boot.
L2C: platform modifies aux control register: 0x02020000 -> 0x02420000
L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 dynamic clock gating disabled, standby mode disabled
L2C-310 cache controller enabled, 8 ways, 128 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001
smp_twd: clock not found -2
sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
clocksource: arm,sp804: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
Failed to initialize '/smb@4000000/motherboard/iofpga@7,00000000/timer@12000': -22
Console: colour dummy device 80x30
Calibrating local timer... 93.77MHz.
Calibrating delay loop... 1659.69 BogoMIPS (lpj=8298496)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x60100000 - 0x60100060
smp: Bringing up secondary CPUs ...
smp: Brought up 1 node, 1 CPU
SMP: Total of 1 processors activated (1659.69 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 1024 (order: 4, 65536 bytes)
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
hw-breakpoint: debug architecture 0x4 unsupported.
Serial: AMBA PL011 UART driver
OF: amba_device_add() failed (-19) for /memory-controller@100e0000
OF: amba_device_add() failed (-19) for /memory-controller@100e1000
OF: amba_device_add() failed (-19) for /watchdog@100e5000
irq: type mismatch, failed to map hwirq-75 for /interrupt-controller@1e001000!
10009000.uart: ttyAMA0 at MMIO 0x10009000 (irq = 38, base_baud = 0) is a PL011 rev1
console [ttyAMA0] enabled
1000a000.uart: ttyAMA1 at MMIO 0x1000a000 (irq = 39, base_baud = 0) is a PL011 rev1
1000b000.uart: ttyAMA2 at MMIO 0x1000b000 (irq = 40, base_baud = 0) is a PL011 rev1
1000c000.uart: ttyAMA3 at MMIO 0x1000c000 (irq = 41, base_baud = 0) is a PL011 rev1
OF: amba_device_add() failed (-19) for /smb@4000000/motherboard/iofpga@7,00000000/wdt@f000
SCSI subsystem initialized
libata version 3.00 loaded.
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm,sp804
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 5 counters available
workingset: timestamp_bits=30 max_order=17 bucket_order=0
squashfs: version 4.0 (2009/01/31) Phillip Lougher
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
9p: Installing v9fs 9p2000 file system support
io scheduler noop registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
clcd-pl11x 10020000.clcd: PL111 designer 41 rev2 at 0x10020000
clcd-pl11x 10020000.clcd: /clcd@10020000 hardware, 1024x768@59 display
Console: switching to colour frame buffer device 128x48
clcd-pl11x 1001f000.clcd: PL111 designer 41 rev2 at 0x1001f000
clcd-pl11x 1001f000.clcd: /smb@4000000/motherboard/iofpga@7,00000000/clcd@1f000 hardware, 640x480@59 display
40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
erase region 0: offset=0x0,size=0x40000,blocks=256
40000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
erase region 0: offset=0x0,size=0x40000,blocks=256
Concatenating MTD devices:
(0): "40000000.flash"
(1): "40000000.flash"
into device "40000000.flash"
libphy: Fixed MDIO Bus: probed
libphy: smsc911x-mdio: probed
smsc911x 4e000000.ethernet eth0: MAC Address: 52:54:00:12:34:56
isp1760 4f000000.usb: bus width: 32, oc: digital
isp1760 4f000000.usb: NXP ISP1760 USB Host Controller
isp1760 4f000000.usb: new USB bus registered, assigned bus number 1
isp1760 4f000000.usb: Scratch test failed.
isp1760 4f000000.usb: can't setup: -19
isp1760 4f000000.usb: USB bus 1 deregistered
usbcore: registered new interface driver usb-storage
rtc-pl031 10017000.rtc: rtc core: registered pl031 as rtc0
mmci-pl18x 10005000.mmci: Got CD GPIO
mmci-pl18x 10005000.mmci: Got WP GPIO
mmci-pl18x 10005000.mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 34,35 (pio)
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
aaci-pl041 10004000.aaci: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 33
aaci-pl041 10004000.aaci: FIFO 512 entries
oprofile: using arm/armv7-ca9
NET: Registered protocol family 17
9pnet: Installing 9P2000 support
Registering SWP/SWPB emulation handler
input: AT Raw Set 2 keyboard as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10006000.kmi/serio0/input/input0
rtc-pl031 10017000.rtc: setting system clock to 2022-05-01 09:36:31 UTC (1651397791)
ALSA device list:
  #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 33
Warning: unable to open an initial console.
Freeing unused kernel memory: 40960K
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2

Please press Enter to activate this console.
/ # ls
bin      etc      linuxrc  proc     sbin     tmp
dev      lib      mnt      root     sys      usr
/ #


4、虚拟机中配置网络
1、虚拟机网络配置,并 ping 宿主机

/ # ip addr
1: lo: <LOOPBACK> mtu 65536 qdisc noop qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
/ # ip addr add 192.168.2.129/24 dev eth0
/ # ip addr
1: lo: <LOOPBACK> mtu 65536 qdisc noop qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.129/24 scope global eth0
       valid_lft forever preferred_lft forever
/ # ip link set eth0 up
/ # ping 192.168.2.128
PING 192.168.2.128 (192.168.2.128): 56 data bytes
64 bytes from 192.168.2.128: seq=0 ttl=64 time=19.238 ms
64 bytes from 192.168.2.128: seq=1 ttl=64 time=7.933 ms
64 bytes from 192.168.2.128: seq=2 ttl=64 time=0.905 ms
^C
--- 192.168.2.128 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.905/9.358/19.238 ms
/ #

2、宿主机 ping 虚拟机

onlylove@ubuntu:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.6.129  netmask 255.255.255.0  broadcast 192.168.6.255
        inet6 fe80::20c:29ff:feb8:de3b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:de:3b  txqueuelen 1000  (Ethernet)
        RX packets 8608  bytes 906457 (906.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4049  bytes 476846 (476.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.14  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:feb8:de45  prefixlen 64  scopeid 0x20<link>
        inet6 2408:8207:304e:1c00:20c:29ff:feb8:de45  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:b8:de:45  txqueuelen 1000  (Ethernet)
        RX packets 7584  bytes 796182 (796.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1460  bytes 144418 (144.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 703  bytes 58903 (58.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 703  bytes 58903 (58.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.128  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::28d7:aeff:fe26:b7a9  prefixlen 64  scopeid 0x20<link>
        ether 2a:d7:ae:26:b7:a9  txqueuelen 1000  (Ethernet)
        RX packets 9  bytes 658 (658.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 53  bytes 5931 (5.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

onlylove@ubuntu:~$ ping 192.168.2.129
PING 192.168.2.129 (192.168.2.129) 56(84) bytes of data.
64 bytes from 192.168.2.129: icmp_seq=1 ttl=64 time=0.589 ms
64 bytes from 192.168.2.129: icmp_seq=2 ttl=64 time=0.955 ms
64 bytes from 192.168.2.129: icmp_seq=3 ttl=64 time=0.495 ms
64 bytes from 192.168.2.129: icmp_seq=4 ttl=64 time=0.878 ms
^C
--- 192.168.2.129 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3041ms
rtt min/avg/max/mdev = 0.495/0.729/0.955/0.192 ms
onlylove@ubuntu:~$

六、-netdev网络测试
七、-nic网络测试
————————————————
版权声明:本文为CSDN博主「lqonlylove」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/OnlyLove_/article/details/124536607

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



Archiver|手机版|小黑屋|risc-v中文社区

GMT+8, 2024-4-26 03:33 , Processed in 0.017175 second(s), 17 queries .

risc-v中文社区论坛 官方网站

Copyright © 2018-2021, risc-v open source

快速回复 返回顶部 返回列表