为一个虚拟机分配 2 个 IP 地址

为一个虚拟机分配 2 个 IP 地址

我想为一个虚拟机分配 2 个 IP 地址,但无法实现。我有

IP              MAC
151.180.39.138   02:aa:cc:73:b1:39
78.132.120.30   02:cc:aa:79:fb:e7

/etc/网络/接口

auto eth0
iface eth0 inet static
        address 151.180.39.138
        netmask 255.255.255.0
        broadcast 151.180.39.138
        dns-nameservers 8.8.8.8
        dns-search server3
        pre-up ifconfig eth0 hw ether 02:aa:cc:73:b1:39
        post-up route add 137.159.142.254 dev eth0
        post-up route add default gw 137.159.142.254
        pre-down route del 137.159.142.254 dev eth0
        pre-down route del default gw 137.159.142.254

auto eth1
iface eth1 inet static
       address 78.132.120.30
       netmask 255.255.255.0
       broadcast 78.132.120.30
       dns-nameservers 8.8.8.8
       post-up route add 137.159.142.254 dev eth1

是否配置

eth0      Link encap:Ethernet  HWaddr 02:aa:cc:73:b1:39  
          inet addr:151.180.39.138  Bcast:151.180.39.138  Mask:255.255.255.0
          inet6 addr: fe80::ff:fe73:b139/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6121 errors:0 dropped:4 overruns:0 frame:0
          TX packets:993 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:487116 (487.1 KB)  TX bytes:141802 (141.8 KB)

eth1      Link encap:Ethernet  HWaddr 02:cc:aa:79:fb:e7  
          inet addr:78.132.120.30  Bcast:78.132.120.30  Mask:255.255.255.0
          inet6 addr: fe80::ff:fe79:fbe7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5225 errors:0 dropped:4 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:409486 (409.4 KB)  TX bytes:1066 (1.0 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1822 (1.8 KB)  TX bytes:1822 (1.8 KB)

我在配置文件中有两个接口,当我执行 virsh edit server3 时,我可以看到

<interface type='bridge'>
  <mac address='02:aa:cc:73:b1:39'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='bridge'>
  <mac address='02:cc:aa:79:fb:e7'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</interface>

如何使其工作,以便我可以访问两个 IP 地址,因为目前第二个 IP 地址无法访问。

相关内容