[root@localhost ~]#
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.2.5.181 netmask 255.255.255.0 broadcast 10.2.5.255
inet6 fe80::5054:ff:fe98:e17e prefixlen 64 scopeid 0x20<link>
ether 52:54:00:98:e1:7e txqueuelen 1000 (Ethernet)
RX packets 86967904 bytes 61065855943 (56.8 GiB)
RX errors 0 dropped 46 overruns 0 frame 0
TX packets 5052886 bytes 2188249614 (2.0 GiB)
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 196161 bytes 51961541 (49.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196161 bytes 51961541 (49.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:0b:1b:7b txqueuelen 1000 (Ethernet)
RX packets 4277155 bytes 12869552776 (11.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3461117 bytes 13566708939 (12.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.1 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::d094:14ff:fe46:fb4f prefixlen 64 scopeid 0x20<link>
ether d2:94:14:46:fb:4f txqueuelen 1000 (Ethernet)
RX packets 224 bytes 26192 (25.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 141 bytes 15433 (15.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
[root@localhost ~]# ovs-vsctl show
90a0e0df-7785-4ba0-9042-b971b76dd96e
Bridge "virbr2"
Port "virbr2"
Interface "virbr2"
type: internal
ovs_version: "2.12.0"
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ip link add link virbr0 name virbr0.10 type vlan id 10
[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.2.5.181 netmask 255.255.255.0 broadcast 10.2.5.255
inet6 fe80::5054:ff:fe98:e17e prefixlen 64 scopeid 0x20<link>
ether 52:54:00:98:e1:7e txqueuelen 1000 (Ethernet)
RX packets 86968178 bytes 61065879085 (56.8 GiB)
RX errors 0 dropped 46 overruns 0 frame 0
TX packets 5052931 bytes 2188256592 (2.0 GiB)
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 196161 bytes 51961541 (49.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196161 bytes 51961541 (49.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ovs-system: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 56:a8:e8:e4:76:33 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
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:0b:1b:7b txqueuelen 1000 (Ethernet)
RX packets 4277155 bytes 12869552776 (11.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3461117 bytes 13566708939 (12.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.1 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::d094:14ff:fe46:fb4f prefixlen 64 scopeid 0x20<link>
ether d2:94:14:46:fb:4f txqueuelen 1000 (Ethernet)
RX packets 224 bytes 26192 (25.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 141 bytes 15433 (15.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:0b:1b:7b 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
virbr0.10: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:0b:1b:7b 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
[root@localhost ~]# ifconfig virbr0.10 192.168.10.10 up
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# /usr/libexec/qemu-kvm centos70-64.qcow2 -enable-kvm -smp 2 -m 2G -device virtio-net-pci,netdev=vnet0 -netdev tap,id=vnet0 -monitor telnet::3333,server,nowait -serial stdio
VNC server running on ::1:5900
CentOS Linux 7 (Core)
Kernel 3.10.0-1127.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Thu Jun 3 07:16:18 on ttyS0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.76 netmask 255.255.255.0 broadcast 192.168.122.255
inet6 fe80::e940:5ead:bd61:cde5 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:12:34:56 txqueuelen 1000 (Ethernet)
RX packets 57 bytes 4711 (4.6 KiB)
RX errors 0 dropped 21 overruns 0 frame 0
TX packets 45 bytes 3977 (3.8 KiB)
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 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
[root@localhost ~]# ip link add link enp5s0 name eth0.10 type vlan id 10
Cannot find device "enp5s0"
[root@localhost ~]# ip link add link eth0 name eth0.10 type vlan id 10
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.76 netmask 255.255.255.0 broadcast 192.168.122.255
inet6 fe80::e940:5ead:bd61:cde5 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:12:34:56 txqueuelen 1000 (Ethernet)
RX packets 57 bytes 4711 (4.6 KiB)
RX errors 0 dropped 21 overruns 0 frame 0
TX packets 48 bytes 4247 (4.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0.10: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:12:34:56 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
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 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
[root@localhost ~]# ifconfig enp5s0.10 192.168.10.11 up
SIOCSIFADDR: No such device
enp5s0.10: ERROR while getting interface flags: No such device
enp5s0.10: ERROR while getting interface flags: No such device
[root@localhost ~]# ifconfig eth0.10 192.168.10.11 up
[root@localhost ~]#
[root@localhost ~]# ping 192.168.10.10 -c 5 -I eth0.10
PING 192.168.10.10 (192.168.10.10) from 192.168.10.11 eth0.10: 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.851 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.425 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.354 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.449 ms
64 bytes from 192.168.10.10: icmp_seq=5 ttl=64 time=0.508 ms
--- 192.168.10.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 0.354/0.517/0.851/0.175 ms
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ping www.baidu.com -c 5 -I eth0.10
PING www.a.shifen.com (110.242.68.3) from 192.168.10.11 eth0.10: 56(84) bytes of data.
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4000ms
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.122.1 0.0.0.0 UG 100 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.10
192.168.122.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.122.1
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ping www.baidu.com -c 5 -I eth0.10
PING www.a.shifen.com (110.242.68.4) from 192.168.10.11 eth0.10: 56(84) bytes of data.
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4000ms
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# route add default gw 192.168.10.10
[root@localhost ~]#
[root@localhost ~]# echo "nameserver 192.168.10.10" >> /etc/resolv.conf
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.122.1
nameserver 192.168.10.10
[root@localhost ~]#
[root@localhost ~]# ping www.baidu.com -c 5 -I eth0.10
PING www.a.shifen.com (110.242.68.3) from 192.168.10.11 eth0.10: 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=49 time=12.4 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=49 time=41.6 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=3 ttl=49 time=10.2 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=4 ttl=49 time=45.1 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=5 ttl=49 time=54.2 ms
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 10.233/32.724/54.201/17.963 ms
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 0 0 0 eth0.10
default gateway 0.0.0.0 UG 100 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.10
192.168.122.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.10 0.0.0.0 UG 0 0 0 eth0.10
0.0.0.0 192.168.122.1 0.0.0.0 UG 100 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.10
192.168.122.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost ~]#
[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.2.5.181 netmask 255.255.255.0 broadcast 10.2.5.255
inet6 fe80::5054:ff:fe98:e17e prefixlen 64 scopeid 0x20<link>
ether 52:54:00:98:e1:7e txqueuelen 1000 (Ethernet)
RX packets 86968742 bytes 61065926676 (56.8 GiB)
RX errors 0 dropped 46 overruns 0 frame 0
TX packets 5053132 bytes 2188336550 (2.0 GiB)
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 196163 bytes 51961653 (49.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196163 bytes 51961653 (49.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ovs-system: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 56:a8:e8:e4:76:33 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
tap0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 8a:ed:37:6b:58:0f txqueuelen 1000 (Ethernet)
RX packets 10 bytes 1372 (1.3 KiB)
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
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:0b:1b:7b txqueuelen 1000 (Ethernet)
RX packets 4277155 bytes 12869552776 (11.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3461117 bytes 13566708939 (12.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.1 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::d094:14ff:fe46:fb4f prefixlen 64 scopeid 0x20<link>
ether d2:94:14:46:fb:4f txqueuelen 1000 (Ethernet)
RX packets 224 bytes 26192 (25.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 141 bytes 15433 (15.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:0b:1b:7b 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
virbr0.10: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
ether 52:54:00:0b:1b:7b 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
[root@localhost ~]#
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.5254000b1b7b yes virbr0-nic
[root@localhost ~]#
[root@localhost ~]# cat /etc/qemu-ifup
#!/bin/bash
switch=virbr0
#switch=br0
ifconfig $1 up
brctl addif $switch $1
#switch=virbr2
#ifconfig $1 up
#ovs-vsctl add-port $switch $1
[root@localhost ~]# ifconfig tap0 up
[root@localhost ~]# brctl addif virbr0 tap0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 ! -d 192.168.10.0/24 -j MASQUERADE
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
RETURN all -- 192.168.122.0/24 base-address.mcast.net/24
RETURN all -- 192.168.122.0/24 255.255.255.255
MASQUERADE tcp -- 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
MASQUERADE udp -- 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
MASQUERADE all -- 192.168.122.0/24 !192.168.122.0/24
MASQUERADE all -- 192.168.100.0/24 !192.168.100.0/24
MASQUERADE all -- 192.168.10.0/24 !192.168.10.0/24
Chain OUTPUT_direct (0 references)
target prot opt source destination
Chain POSTROUTING_ZONES (0 references)
target prot opt source destination
Chain POSTROUTING_ZONES_SOURCE (0 references)
target prot opt source destination
Chain POSTROUTING_direct (0 references)
target prot opt source destination
Chain POST_public (0 references)
target prot opt source destination
Chain POST_public_allow (0 references)
target prot opt source destination
Chain POST_public_deny (0 references)
target prot opt source destination
Chain POST_public_log (0 references)
target prot opt source destination
Chain PREROUTING_ZONES (0 references)
target prot opt source destination
Chain PREROUTING_ZONES_SOURCE (0 references)
target prot opt source destination
Chain PREROUTING_direct (0 references)
target prot opt source destination
Chain PRE_public (0 references)
target prot opt source destination
Chain PRE_public_allow (0 references)
target prot opt source destination
Chain PRE_public_deny (0 references)
target prot opt source destination
Chain PRE_public_log (0 references)
target prot opt source destination
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ps aux | grep dnsmasq
nobody 20887 0.0 0.0 53900 1092 ? S 5月20 0:15 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 20888 0.0 0.0 53872 568 ? S 5月20 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 24155 0.0 0.0 112824 972 pts/6 D+ 07:30 0:00 grep --color=auto dnsmasq
nobody 25372 0.0 0.0 53904 868 ? S 5月20 0:00 dnsmasq --strict-order --except-interface=lo --interface=virbr2 --listen-address=192.168.100.1 --bind-interface --dhcp-range=192.168.100.2,192.168.100.254 --conf-file= --pid-file=/var/run/qemu-dhcp-virbr2.pid --dhcp-leasefile=/var/run/qemu-dhcp-virbr2.leases --dhcp-no-override
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vim /var/lib/libvirt/dnsmasq/default.conf
[root@localhost ~]#
KVM network vlan
最新推荐文章于 2024-05-28 14:35:27 发布