kvm debian下ipv4网络桥接, ipv6网络桥接
目录
debian下kvm网络桥接,debian ipv4网络桥接,debian ipv6网络桥接。已经在debian8,debian9,debian10上实测。
KVM桥接依赖
1 2 3 4 5 |
apt install -y bridge-utils # vim /etc/sysctl.conf net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1 |
物理机网络,干掉ipv6,仅保留IPV4, KVM桥接网络
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
source /etc/network/interfaces.d/* auto lo iface lo inet loopback auto vmbr0 iface vmbr0 inet static address 95.xxx.xxx.xxx netmask 255.255.255.xxx gateway 95.xxx.xxx.xxx dns-nameservers 1.1.1.1 8.8.8.8 bridge_ports enp0s31f6 bridge_stp off bridge_fd 0 auto vmbr1 iface vmbr1 inet static address 10.10.10.1 netmask 255.255.255.0 bridge_ports none bridge_stp off bridge_fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE # 转发至nat-kvm-machine示例, 主机2222端口转发为10.10.10.2的22端口 post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to 10.10.10.2:22 post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to 10.10.10.2:22 |
物理机网络,保留IPV4和IPV6,KVM桥接网络
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
source /etc/network/interfaces.d/* auto lo iface lo inet loopback iface lo inet6 loopback auto enp0s31f6 iface enp0s31f6 inet manual up route add -net 46.4.102.xxx netmask 255.255.255.224 gw 46.4.102.xxx dev enp0s31f6 auto vmbr0 iface vmbr0 inet static address 46.4.102.xxx netmask 255.255.255.224 gateway 46.4.102.xxx bridge_ports enp0s31f6 bridge_stp off bridge_fd 0 iface vmbr0 inet6 static address 2a01:xxxxxxxxxxxx netmask 64 gateway fe80::1 auto vmbr1 iface vmbr1 inet static address 10.10.10.1 netmask 255.255.255.0 bridge_ports none bridge_stp off bridge_fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE # kvm machine post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to 10.10.10.2:22 post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to 10.10.10.2:22 |
虚拟机网络使用方法
- 虚拟机如有独立IP则直接用vmbr0,且填写MAC,配置静态IP地址及静态IPV6地址。
- 虚拟机NAT联网,IPV4则使用vmbr1,配置静态内网IP地址;若需要虚拟机NAT支持IPV6,就加一块vmbr0网卡,配置静态IPV6地址。
然而实际在使用过程中,貌似配置IPv6没有多大作用,而且出国方向路由也不是很好,IPV6丢包率奇高不说,路由全球飘。
IPV4 和 IPV6路由对比
去程路由对比
ipv4
ipv6
回程路由对比
ipv4
ipv6
by: cpp.la
One Reply to “kvm debian下ipv4网络桥接, ipv6网络桥接”