目前我只有一个 /30 块(1 个可用 IP)(我刚刚订购了一个 /28 块,用于 13 个可用公共 IP,正在等待)
我刚刚安装了 proxmox,设置了几个虚拟容器。端口转发了必要的服务/端口。一切正常。但是当我加载 KVM 时,我似乎无法确定我做错了什么,导致只获得传出连接,甚至没有连接。
所有容器都设置了 lan ip,并将 veth0 设备桥接到 vmbr1。KVM 也设置了桥接到 vmbr1 的网络设备(没有地方可以像容器一样在 proxmox 中指定其 LAN IP,我认为这就是我的问题所在)
/etc/network/interfaces
这是虚拟机
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.25
gateway 192.168.0.254
dns-nameserver 8.8.8.8
dns-search 8.8.8.8
这/etc/network/interfaces
是主持人
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
iface eth1 inet manual
iface eth2 inet manual
iface eth3 inet manual
auto vmbr0
iface vmbr0 inet static
address X.X.X.X
netmask 255.255.255.0
gateway X.X.X.Z
bridge_ports eth0
bridge_stp off
bridge_fd 0
auto vmbr1
iface vmbr1 inet static
address 192.168.0.254
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 '192.168.0.0/24' -o vmbr0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.0.0/24' -o vmbr0 -j MASQUERADE
# VM 100
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 10022 -j DNAT --to 192.168.0.100:22
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 10022 -j DNAT --to 192.168.0.100:22
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 192.168.0.100:80
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 192.168.0.100:80
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.0.100:443
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.0.100:443
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.0.100:443
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 192.168.0.100:443
# VM101
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 10122 -j DNAT --to 192.168.0.101:22
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 10122 -j DNAT --to 192.168.0.101:22
post-up iptables -t nat -A PREROUTING -i vmbr0 -p udp --dport 9987 -j DNAT --to 192.168.0.101:9987
post-down iptables -t nat -D PREROUTING -i vmbr0 -p udp --dport 9987 -j DNAT --to 192.168.0.101:9987
**# VM102 (KVM)**
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 10222 -j DNAT --to 192.168.0.102:22
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 10222 -j DNAT --to 192.168.0.102:22
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 25565 -j DNAT --to 192.168.0.102:25565
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 25565 -j DNAT --to 192.168.0.102:25565
# VM103
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 10322 -j DNAT --to 192.168.0.103:22
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 10322 -j DNAT --to 192.168.0.103:22
post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 3306 -j DNAT --to 192.168.0.103:3306
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 3306 -j DNAT --to 192.168.0.103:3306
答案1
我的 vmbr1 的 ip 地址是错误的,而 kvm eth0 接口配置的网关也是错误的
修正 kvm /etc/network/interface
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.25
gateway 192.168.0.1
修正主机 /etc/network/interface
iface vmbr1 inet static
address 192.168.0.1
netmask 255.255.255.0