为什么 VM 无法获取我从提供商处获得的公共 IP?

为什么 VM 无法获取我从提供商处获得的公共 IP?

我有一个 KVM-Host(在 Debian 上)

root@kvm-host:/# cat /etc/network/interfaces

auto  eth0
iface eth0 inet manual

auto vmbr0
iface vmbr0 inet static
  address 176.x.y.133
  netmask 255.255.255.224
  gateway 176.x.y.129 # Provider's GW IP
  bridge_ports eth0
  bridge_stp off
  bridge_fd 0


root@kvm-host:/# route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
176.x.y.128     0.0.0.0         255.255.255.224 U     0      0        0 vmbr0
0.0.0.0         176.x.y.129     0.0.0.0         UG    0      0        0 vmbr0


root@kvm-host:/# arp -an

? (176.x.y.155) at <incomplete> on vmbr0
? (176.x.y.129) at xx:yy:zz:11:22:33 [ether] on vmbr0


root@kvm-host:/# ifconfig

1: lo: ...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether AA:BB:CC:DD:EE:FF brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a60:6eff:feDD:EEFF/64 scope link 
       valid_lft forever preferred_lft forever
3: vmbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 
    link/ether AA:BB:CC:DD:EE:FF brd ff:ff:ff:ff:ff:ff
    inet 176.x.y.133/27 brd 176.x.y.159 scope global vmbr0
    inet6 fe80::a60:6eff:feDD:EEFF/64 scope link 
       valid_lft forever preferred_lft forever
4: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 
    link/void 
    inet6 fe80::1/128 scope link 
       valid_lft forever preferred_lft forever

我有公共 IP:176.xy133(KVM-Host)、176.xy151、176.xy155。

现在我正在尝试获取每台虚拟机上的网络:

user@VM:/$ cat /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 176.x.y.155
  netmask 255.255.255.255
  pointtopoint 176.x.y.133
  gateway 176.x.y.133

我卸载了网络管理器。

下一步:

user@VM:/$ sudo ifup eth0
RTNETLINK answers: File exists
Failed to bring up eth0


user@VM:/$ ping 176.x.y.133
connect: Network is unreachable

root@VM:/# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

(即为空,甚至没有默认网关)

user@VM:/$ sudo add default via 176.x.y.133
RTNETLINK answers: no such process

user@VM:/$ sudo arp -a
(i.e. empty)

user@VM:/$ sudo arp -s 176.x.y.133 AA:BB:CC:DD:EE:FF
SIOCSARP Network is unreachable

我甚至无法设置静态路由(MAC 地址/IP 地址)。

在虚拟机上设置网络可能存在什么问题?(我希望我提供了所有需要的具体信息)

答案1

检查 MAC 地址是否不是随机生成的;许多 ISP 只会将 IP 分配给有效提供商颁发的 MAC 地址。我能够通过获取已知良好的 IP 并将最后一个八位字节加一来获取机器上的 IP。

编辑:确保“brctl show vmbr0”显示一些合理的内容。例如

xen-br0         8000.90b11c316da4       no              eth0

答案2

在硬件节点(主机)上,/etc/network/interface可能看起来像:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# Which interface are to be started at boot
auto lo vmbr0

# The loopback network interface
iface lo inet loopback

# The bridge for VM    
iface vmbr0 inet static
        address 176.x.y.133
        netmask 255.255.255.224
        network 176.x.y.128
        broadcast 176.x.y.159
        gateway 176.x.y.129 # Provider's GW IP
        bridge_ports eth0
        bridge_maxwait 2
        up /sbin/ifconfig eth0 inet 0.0.0.0 promisc
        up /sbin/sysctl -w net.ipv4.conf.br0.proxy_arp=1
        up /sbin/sysctl -w net.ipv4.conf.default.forwarding=1
        up /sbin/sysctl -w net.ipv4.ip_forward=1

当然,您可能更愿意创建一个vm-routing文件/etc/sysctl.d/来存储sysctl配置。

虚拟机主机,你必须能够使用相同的网络配置:

iface eth0 inet static
        address 176.x.y.155
        netmask 255.255.255.224
        network 176.x.y.128
        broadcast 176.x.y.159
        gateway 176.x.y.129 # Provider's GW IP

相关内容