我有 2 台服务器。两台服务器的设置相同,运行在 Centos 7.8 上。我使用 Rocky 9.3 重新镜像了一台机器,但无法让公共 IP 路由到虚拟机正常工作。
测试是否成功是能否从互联网 ping 客户虚拟机。我可以 ping 我分配给 brpub0 的公共 IP。
我保存了 Rocky7 中的配置文件以放入 Rocky9,使用任何配置工具都找不到任何差异。vagrant 文件和 vms 以非特权用户身份运行vmuser
。我知道使用这些ifcfg
文件并不是在 Rocky 9.3 上执行操作的真正方式,但我正在尝试排除差异。我尝试brpub0
使用创建的非工作主机上的防火墙被禁用nmtui
- 没有乐趣
我正在使用 Hetzner 裸机服务器,并使用 vagrant 和 Virtualbox 附加公共 IP4 \28 地址。由于它们的网络工作方式,IP 范围不会分配 MAC 地址,因此我们必须使用路由器。 Hetzner - 附加 IP 地址,Hetzner - Centos 的网络配置 - 用于虚拟化的 IP4 子网
工作原理——VMHost
Main IP: aaa.bbb.217.101
Gateway: aaa.bbb.217.65
Netmask: 255.255.255.192
Broadcast: aaa.bbb.217.127
Public Range: mmm.nnn.207.144 / 28
Gateway: aaa.bbb.217.101
Netmask: 255.255.255.240
Broadcast: mmm.nnn.207.159
mmm.nnn.207.144 to mmm.nnn.207.159
ip route
default via aaa.bbb.217.65 dev enp0s31f6
mmm.nnn.207.144/28 dev brpub0 proto kernel scope link src mmm.nnn.207.145
aaa.bbb.217.65 dev enp0s31f6 proto kernel scope link src aaa.bbb.217.101
169.254.0.0/16 dev enp0s31f6 scope link metric 1002
169.254.0.0/16 dev brpub0 scope link metric 1003
192.168.35.0/24 dev vboxnet0 proto kernel scope link src 192.168.35.1
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 aaa.bbb.217.65 0.0.0.0 UG 0 0 0 eno1
mmm.nnn.207.144 0.0.0.0 255.255.255.240 U 0 0 0 brpub0
aaa.bbb.217.65 0.0.0.0 255.255.255.255 UH 0 0 0 eno1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eno1
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 brpub0
192.168.35.0 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet1
#/etc/sysconfig/network-scripts/ifcfg-enp0s31f6
### Hetzner Online GmbH installimage
DEVICE=enp0s31f6
ONBOOT=yes
BOOTPROTO=none
IPADDR=aaa.bbb.217.101
PREFIX=32
SCOPE="peer aaa.bbb.217.65"
DEFROUTE=yes
IPV6INIT=yes
IPV6ADDR=2a01:4f8:13b:1ad2::2/64
IPV6_DEFAULTGW=fe80::1
IPV6_DEFROUTE=yes
IPV6_DEFAULTDEV=enp0s31f6
ifcfg-brpub0
# /etc/sysconfig/network-scripts/ifcfg-brpub0 (pointopoint, Hetzner Standard)
DEVICE=brpub0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=none
IPADDR=mmm.nnn.207.145
NETMASK=255.255.255.240
STP=off
DELAY=0
#/etc/sysconfig/network-scripts/route-enp0s31f6
### Hetzner Online GmbH installimage
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=aaa.bbb.217.65
Vagrant file
Vagrant 文件-工作
$vmName = "WorkingVM"
$vmPrivateIp = "192.168.35.85"
$vmPublicIp = "mmm.nnn.207.150"
Vagrant.configure("2") do |config|
config.vm.define $vmName do |vminstance|
vminstance.vm.box = "bento/centos-7.6"
vminstance.vm.network "private_network", ip: $vmPrivateIp, zone: "internal"
vminstance.vm.network "public_network", ip: $vmPublicIp, bridge: "brpub0", \
netmask: "255.255.255.240", gateway: $vmGatewayIp, dns1: "8.8.8.8", \
zone: "public""
vminstance.vm.network "forwarded_port", guest: 22, host: $vmForwardPort
end # of vminstance
end # of config
VM-有效
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:c2:05:d3 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
valid_lft 67512sec preferred_lft 67512sec
inet6 fe80::d1d5:4ed0:dcb7:badd/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:45:d2:90 brd ff:ff:ff:ff:ff:ff
inet 192.168.35.84/24 brd 192.168.35.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe45:d290/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:74:de:bd brd ff:ff:ff:ff:ff:ff
inet mmm.nnn.207.149/28 brd mmm.nnn.207.159 scope global noprefixroute eth2
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe74:debd/64 scope link
valid_lft forever preferred_lft forever
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 aaa.bbb.217.101 0.0.0.0 UG 102 0 0 eth2
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
mmm.nnn.207.144 0.0.0.0 255.255.255.240 U 102 0 0 eth2
aaa.bbb.217.101 0.0.0.0 255.255.255.255 UH 102 0 0 eth2
192.168.35.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1
VMHost - 不起作用
Main IP: aaa.bbb.129.56
Gateway: aaa.bbb.129.1
Netmask: 255.255.255.192
Broadcast: aaa.bbb.129.63
Public Range: xxx.yyy.89.0 / 28
Gateway: aaa.bbb.129.56
Netmask: 255.255.255.240
Broadcast: xxx.yyy.89.15
xxx.yyy.89.0 to xxx.yyy.89.15
vmhost-130
ip route
default via aaa.bbb.129.1 dev eno1 proto static metric 100
xxx.yyy.89.0/28 dev brpub0 proto kernel scope link src xxx.yyy.89.1 metric 425 linkdown
aaa.bbb.129.1 dev eno1 proto static scope link metric 100
192.168.56.0/24 dev vboxnet0 proto kernel scope link src 192.168.56.1
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 aaa.bbb.129.1 0.0.0.0 UG 100 0 0 eno1
xxx.yyy.89.0 0.0.0.0 255.255.255.240 U 425 0 0 brpub0
aaa.bbb.129.1 0.0.0.0 255.255.255.255 UH 100 0 0 eno1
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 vboxnet0
# /etc/sysconfig/network-scripts/ifcfg-eno1
### Hetzner Online GmbH installimage
DEVICE=eno1
ONBOOT=yes
BOOTPROTO=none
IPADDR=aaa.bbb.129.56
PREFIX=32
GATEWAY=aaa.bbb.129.1
DEFROUTE=yes
DNS1=185.12.64.1
DNS2=2a01:4ff:ff00::add:2
IPV6INIT=yes
IPV6ADDR=2a01:4f8:13b:3ac7::2/64
IPV6_AUTOCONF=no
IPV6_DEFAULTGW=fe80::1
IPV6_DEFROUTE=yes
# /etc/sysconfig/network-scripts/ifcfg-brpub0 (pointopoint, Hetzner Standard)
DEVICE=brpub0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=none
IPADDR=xxx.yyy.89.1
NETMASK=255.255.255.240
STP=off
DELAY=0
# /etc/sysconfig/network-scripts/route-en01
### Hetzner Online GmbH installimage
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=aaa.bbb.129.1
Vagrant 文件-不起作用
$vmName = "NotWorking"
$vmBox = "generic/rocky9"
$vmPublicIp = "xxx.yyy.89.12"
$vmGatewayIp = "aaa.bbb.129.56"
$vmPrivateIp = "192.168.56.10"
Vagrant.configure("2") do |config|
config.vm.define $vmName do |vminstance|
vminstance.vm.box = $vmBox
vminstance.vm.network "private_network", ip: $vmPrivateIp, zone: "internal"
vminstance.vm.network "public_network", ip: $vmPublicIp, bridge: "brpub0", \
netmask: ""255.255.255.240"", gateway: $vmGatewayIp, dns1: "8.8.8.8", \
zone: "public""
vminstance.vm.network "forwarded_port", guest: 22, host: $vmForwardPort
end
end
VM-不起作用
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:cb:b3:b6 brd ff:ff:ff:ff:ff:ff
altname enp0s3
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute eth0
valid_lft 85553sec preferred_lft 85553sec
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:01:17:49 brd ff:ff:ff:ff:ff:ff
altname enp0s8
inet 192.168.56.10/24 brd 192.168.56.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe01:1749/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:80:d4:52 brd ff:ff:ff:ff:ff:ff
altname enp0s9
inet xxx.yyy.89.12/28 brd xxx.yyy.89.15 scope global noprefixroute eth2
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe80:d452/64 scope link
valid_lft forever preferred_lft forever
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 eth0
0.0.0.0 aaa.bbb.129.56 0.0.0.0 UG 102 0 0 eth2
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
xxx.yyy.89.0 0.0.0.0 255.255.255.240 U 102 0 0 eth2
aaa.bbb.129.56 0.0.0.0 255.255.255.255 UH 102 0 0 eth2
192.168.56.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1