ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux-如何在一塊網卡上設多個IP

Linux-如何在一塊網卡上設多個IP

原创 Linux操作系统 作者:vongates 时间:2019-05-17 10:00:06 0 删除 编辑

我們在日常工作中,在很多情況下可能會被要求用多個ip來訪問同一台實體主機,當然我們根據實際的應用可能有多種方法來實現,我們來看一種最基本的方法,也是最簡單的。看下面的例子吧:


[root@rhas network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C4
          inet addr:10.0.0.2  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2216162492 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2209106363 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3561065854 (3396.0 Mb)  TX bytes:232465243 (221.6 Mb)
          Base address:0x2500 Memory:f9fe0000-fa000000

eth1      Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C5
          inet addr:192.168.60.222  Bcast:192.168.60.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:204306764 errors:0 dropped:0 overruns:0 frame:0
          TX packets:208086787 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1047871892 (999.3 Mb)  TX bytes:3755139216 (3581.1 Mb)
          Base address:0x2540 Memory:f9fc0000-f9fe0000

eth1:0    Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C5
          inet addr:192.168.60.227  Bcast:192.168.60.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Base address:0x2540 Memory:f9fc0000-f9fe0000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1413870 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1413870 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:91837492 (87.5 Mb)  TX bytes:91837492 (87.5 Mb)

[root@rhas network-scripts]#

[root@rhas network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@rhas network-scripts]# ls |grep ifcfg-
ifcfg-eth0
ifcfg-eth1
ifcfg-eth1:0
ifcfg-lo
[root@rhas network-scripts]# cp ifcfg-eth0 ifcfg-eht0:0
[root@rhas network-scripts]# ls |grep ifcfg-
ifcfg-eth0
ifcfg-eth0:0
ifcfg-eth1
ifcfg-eth1:0
ifcfg-lo
[root@rhas network-scripts]#

[root@rhas network-scripts]# vi ifcfg-eth0:0
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.0.0.2
NETMASK=255.0.0.0
ONBOOT=yes

改成

DEVICE=eth0:0
BOOTPROTO=static
IPADDR=10.0.0.5
NETMASK=255.0.0.0
ONBOOT=yes

[root@rhas network-scripts]# ifdown eth0
[root@rhas network-scripts]# ifup eth0
[root@rhas network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C4
          inet addr:10.0.0.2  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2216827415 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2209838574 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3940290540 (3757.7 Mb)  TX bytes:738187453 (703.9 Mb)
          Base address:0x2500 Memory:f9fe0000-fa000000

eth0:0    Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C4
          inet addr:10.0.0.5  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Base address:0x2500 Memory:f9fe0000-fa000000

eth1      Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C5
          inet addr:192.168.60.222  Bcast:192.168.60.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:204337577 errors:0 dropped:0 overruns:0 frame:0
          TX packets:208118730 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1052551704 (1003.7 Mb)  TX bytes:3766609193 (3592.1 Mb)
          Base address:0x2540 Memory:f9fc0000-f9fe0000

eth1:0    Link encap:Ethernet  HWaddr 00:09:6B:71:E6:C5
          inet addr:192.168.60.227  Bcast:192.168.60.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Base address:0x2540 Memory:f9fc0000-f9fe0000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1414091 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1414091 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:91851968 (87.5 Mb)  TX bytes:91851968 (87.5 Mb)

[root@rhas network-scripts]#

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29987/viewspace-51794/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-09-11

  • 博文量
    201
  • 访问量
    143338