一臺主機虛擬多個ip

小亮520cl發表於2015-08-11
複製一份eth0的配置檔案為eth0:0在去修改一個DEVICE=eth0:0
下面的就按需分配了!
儲存後用ifup eth0:0就可以啟動了!
這樣就可以給一塊網路卡配兩個IP地址了!
多個ip就複製多份

點選(此處)摺疊或開啟

  1. [rootgc1:/root]$ more /etc/sysconfig/network-scripts/ifcfg-eth0
  2. ifcfg-eth0 ifcfg-eth0:0 ifcfg-eth0:1

點選(此處)摺疊或開啟

  1. [rootgc1:/root]$ more /etc/sysconfig/network-scripts/ifcfg-eth0
  2. # Please read /usr/share/doc/initscripts-*/sysconfig.txt
  3. # for the documentation of these parameters.
  4. TYPE=Ethernet
  5. DEVICE=eth0
  6. HWADDR=08:00:27:70:78:0e
  7. BOOTPROTO=none
  8. ONBOOT=yes
  9. USERCTL=no
  10. IPV6INIT=no
  11. PEERDNS=yes
  12. NETMASK=255.255.255.0
  13. IPADDR=192.168.6.114
  14. GATEWAY=192.168.6.1

點選(此處)摺疊或開啟

  1. [rootgc1:/root]$ more /etc/sysconfig/network-scripts/ifcfg-eth0:0
  2. # Please read /usr/share/doc/initscripts-*/sysconfig.txt
  3. # for the documentation of these parameters.
  4. TYPE=Ethernet
  5. DEVICE=eth0:0
  6. BOOTPROTO=none
  7. USERCTL=no
  8. IPV6INIT=no
  9. PEERDNS=yes
  10. NETMASK=255.255.255.0
  11. IPADDR=192.168.6.104
  12. GATEWAY=192.168.6.1
  13. ONPARENT=yes

方法二:直接在eth0 ip下面加一個也可以
方法三:圖形化介面


方法四:(service network restart重啟網路卡會失效,還是得加到/etc/sysconfig/network-scripts/下去,,所以還是用前幾種方法吧!)

  1. [root@gc2 ~]# ip address add 10.0.0.119/24 broadcast + dev eth0 label eth0:vbird
  2. [root@gc2 ~]# ifconfig
  3. eth0 Link encap:Ethernet HWaddr 08:00:27:76:7C:C9
  4.           inet addr:10.0.0.120 Bcast:10.0.0.255 Mask:255.255.255.0
  5.           inet6 addr: fe80::a00:27ff:fe76:7cc9/64 Scope:Link
  6.           UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  7.           RX packets:1127213 errors:0 dropped:0 overruns:0 frame:0
  8.           TX packets:607063 errors:0 dropped:0 overruns:0 carrier:0
  9.           collisions:0 txqueuelen:1000
  10.           RX bytes:1551136168 (1.4 GiB) TX bytes:72197038 (68.8 MiB)
  11.           Base address:0xd010 Memory:f0000000-f0020000

  12. eth0:vbird Link encap:Ethernet HWaddr 08:00:27:76:7C:C9
  13.           inet addr:10.0.0.119 Bcast:10.0.0.255 Mask:255.255.255.0
  14.           UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  15.           Base address:0xd010 Memory:f0000000-f0020000

  16. lo Link encap:Local Loopback
  17.           inet addr:127.0.0.1 Mask:255.0.0.0
  18.           inet6 addr: ::1/128 Scope:Host
  19.           UP LOOPBACK RUNNING MTU:16436 Metric:1
  20.           RX packets:43346 errors:0 dropped:0 overruns:0 frame:0
  21.           TX packets:43346 errors:0 dropped:0 overruns:0 carrier:0
  22.           collisions:0 txqueuelen:0
  23.           RX bytes:10650402 (10.1 MiB) TX bytes:10650402 (10.1 MiB)

  24. [root@gc2 ~]# ip address del 10.0.0.119/24 dev eth0
  25. [root@gc2 ~]# ifconfig
  26. eth0 Link encap:Ethernet HWaddr 08:00:27:76:7C:C9
  27.           inet addr:10.0.0.120 Bcast:10.0.0.255 Mask:255.255.255.0
  28.           inet6 addr: fe80::a00:27ff:fe76:7cc9/64 Scope:Link
  29.           UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  30.           RX packets:1127213 errors:0 dropped:0 overruns:0 frame:0
  31.           TX packets:607064 errors:0 dropped:0 overruns:0 carrier:0
  32.           collisions:0 txqueuelen:1000
  33.           RX bytes:1551136168 (1.4 GiB) TX bytes:72197160 (68.8 MiB)
  34.           Base address:0xd010 Memory:f0000000-f0020000

  35. lo Link encap:Local Loopback
  36.           inet addr:127.0.0.1 Mask:255.0.0.0
  37.           inet6 addr: ::1/128 Scope:Host
  38.           UP LOOPBACK RUNNING MTU:16436 Metric:1
  39.           RX packets:43348 errors:0 dropped:0 overruns:0 frame:0
  40.           TX packets:43348 errors:0 dropped:0 overruns:0 carrier:0
  41.           collisions:0 txqueuelen:0
  42.           RX bytes:10650502 (10.1 MiB) TX bytes:10650502 (10.1 MiB)

或者
[root@node2 ~]# ifconfig eth0:0 192.168.8.111 netmask 255.255.255.0 up


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-1768193/,如需轉載,請註明出處,否則將追究法律責任。

相關文章