代码之家  ›  专栏  ›  技术社区  ›  NO2 SIIZEXL

具有公共IP的新NIC没有互联网连接,而现有NIC工作正常

  •  0
  • NO2 SIIZEXL  · 技术社区  · 1 年前

    我的Azure VM上新添加的网络接口(NIC)出现问题。虽然现有的NIC工作正常,但新的NIC无法连接到互联网。以下是详细信息:

    当前设置:

    • 使用“基本SKU动态”网络配置创建的VM

    • 现有NIC有多个公共IP(基本SKU,动态),工作正常

    • 可以成功使用 curl --interface <existing interface ipv4 address> http://example.com

    问题

    1. 向VM添加了具有新公共IP的新NIC

      (eth1 is a newly added nic.)
      azureuser@instanceXX:~$ ip addr show
      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 mq state UP group default qlen 1000
          link/ether 60:45:bd:48:e7:f1 brd ff:ff:ff:ff:ff:ff
          inet 10.0.0.5/24 brd 10.0.0.255 scope global eth0
             valid_lft forever preferred_lft forever
       # ~~~~skipping the middle~~~~ 
          inet6 fe80::6245:bdff:fe48:e7f1/64 scope link
             valid_lft forever preferred_lft forever
      3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
          link/ether 7c:1e:52:2b:a9:ff brd ff:ff:ff:ff:ff:ff
          inet 10.0.0.104/24 metric 200 brd 10.0.0.255 scope global eth1
             valid_lft forever preferred_lft forever
          inet6 fe80::7e1e:52ff:fe2b:a9ff/64 scope link
             valid_lft forever preferred_lft forever
      4: enP12745s1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master eth0 state UP group default qlen 1000
          link/ether 60:45:bd:48:e7:f1 brd ff:ff:ff:ff:ff:ff
          altname enP12745p0s2
          inet6 fe80::6245:bdff:fe48:e7f1/64 scope link
             valid_lft forever preferred_lft forever
      

      查看#route-n,我得到以下输出:

      Kernel IP routing table
      Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
      0.0.0.0         10.0.0.1        0.0.0.0         UG    100    0        0 eth0
      10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
      10.0.0.0        0.0.0.0         255.255.255.0   U     200    0        0 eth1
      10.0.0.1        0.0.0.0         255.255.255.255 UH    100    0        0 eth0
      168.63.129.16   10.0.0.1        255.255.255.255 UGH   100    0        0 eth0
      168.63.129.16   0.0.0.0         255.255.255.255 UH    200    0        0 eth1
      169.254.169.254 10.0.0.1        255.255.255.255 UGH   100    0        0 eth0
      
    2. 新NIC上的主要和次要类型IP都无法连接:

      azureuser@instanceXX:~$ curl --interface 10.0.0.104 http://example.com
      curl: (28) Failed to connect to example.com port 80 after 134224 ms: Connection timed out
      
      
    3. 现有NIC及其IP仍然正常工作

    4. 两个NIC共享同一个网络安全组(NSG),该组自VM创建以来未被修改

    预期行为: 两个NIC,每个NIC有225个公共IP(基本SKU,动态),所有NIC都正常运行。

    附加说明:

    • 由于成本限制,不使用标准SKU

    • NSG设置是初始VM创建时的默认设置

    是否有人遇到过类似的问题,或者可以提出一个解决方案,让新的NIC与互联网连接一起工作?任何见解都将不胜感激。。。!!!

    尝试的解决方案:

    1. 使用Azure的连接故障排除和支持+故障排除工具(无解决方案)

    2. 尝试创建具有不同SKU的IP,但由于SKU不匹配,VM无法启动

    3. 创建了一个新的虚拟机并复制了安装程序,但遇到了同样的问题

    1 回复  |  直到 1 年前
        1
  •  1
  •   Arko    1 年前

    要解决Azure VM上新添加的网络接口在现有NIC正常工作时无法连接到互联网的问题,请执行以下步骤-

    创建虚拟网络和子网

    az network vnet create \
      --resource-group arkorg \
      --name myVNet \
      --address-prefix 10.0.0.0/16 \
      --subnet-name mySubnet \
      --subnet-prefix 10.0.0.0/24
    

    enter image description here

    创建网络安全组(NSG)

    az network nsg create \
      --resource-group arkorg \
      --name myNSG
    

    enter image description here

    将HTTP和SSH的入站规则添加到NSG

    az network nsg rule create \
      --resource-group arkorg \
      --nsg-name myNSG \
      --name AllowInternetInBound \
      --priority 1000 \
      --direction Inbound \
      --access Allow \
      --protocol Tcp \
      --destination-port-range 80 \
      --source-address-prefix Internet \
      --destination-address-prefix '*'
    
    az network nsg rule create \
      --resource-group arkorg \
      --nsg-name myNSG \
      --name AllowSSH \
      --priority 1100 \
      --direction Inbound \
      --access Allow \
      --protocol Tcp \
      --destination-port-range 22 \
      --source-address-prefix Internet \
      --destination-address-prefix '*'
    

    enter image description here

    enter image description here

    为NIC创建公共IP地址

    az network public-ip create \
      --resource-group arkorg \
      --name myExistingPublicIP \
      --sku Basic \
      --allocation-method Dynamic
    
    az network public-ip create \
      --resource-group arkorg \
      --name myNewPublicIP \
      --sku Basic \
      --allocation-method Dynamic
    

    enter image description here

    enter image description here

    创建网络接口并将其与公共IP相关联

    az network nic create \
      --resource-group arkorg \
      --name myExistingNIC \
      --vnet-name myVNet \
      --subnet mySubnet \
      --network-security-group myNSG \
      --public-ip-address myExistingPublicIP
    
    az network nic create \
      --resource-group arkorg \
      --name myNewNIC \
      --vnet-name myVNet \
      --subnet mySubnet \
      --network-security-group myNSG \
      --public-ip-address myNewPublicIP
    

    enter image description here

    enter image description here

    使用现有NIC创建VM

    az vm create \
      --resource-group arkorg \
      --name myVM \
      --nics myExistingNIC \
      --image Ubuntu2204 \
      --admin-username azureuser \
      --generate-ssh-keys
    

    enter image description here

    现在,您的主要问题是用新的IP更新VM,它应该能够连接到网络。

    所以,首先释放旧的

    az vm deallocate \
      --resource-group arkorg \
      --name myVM
    

    enter image description here

    然后添加新的NIC并重新启动VM

    az vm nic add \
      --resource-group arkorg \
      --vm-name myVM \
      --nics myNewNIC
    
    az vm start \
      --resource-group arkorg \
      --name myVM
    

    enter image description here

    enter image description here

    如果在这里完成,那么你就被解决了。现在,您只需使用现有NIC的公共IP通过SSH连接到VM

    ssh azureuser@<existing-public-ip>
    

    运行以下命令以设置基于源的路由:

    sudo su
    echo "200 eth0" >> /etc/iproute2/rt_tables
    echo "201 eth1" >> /etc/iproute2/rt_tables
    ip rule add from 10.0.0.4/32 table eth0
    ip rule add from 10.0.0.5/32 table eth1
    ip route add 10.0.0.0/24 dev eth0 src 10.0.0.4 table eth0
    ip route add default via 10.0.0.1 dev eth0 table eth0
    ip route add 10.0.0.0/24 dev eth1 src 10.0.0.5 table eth1
    ip route add default via 10.0.0.1 dev eth1 table eth1
    

    enter image description here

    验证路由规则

    ip rule show
    ip route show table eth0
    ip route show table eth1
    

    enter image description here

    测试连接性

    curl --interface 10.0.0.4 http://example.com
    curl --interface 10.0.0.5 http://example.com
    

    enter image description here

    推荐文章