歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 在一個網卡上綁定2個或2個以上的IP地址

在一個網卡上綁定2個或2個以上的IP地址

日期:2017/2/27 9:29:56   编辑:更多Linux
  前言:這是我以RedHat 7.3為例來說明的,有可能系統版本不同,不過我覺得大同小異吧。哈。。。    1.進入目錄:  [root@Linuxsir root]# cd /etc/sysconfig/network-scripts/    2:ifcfg-eh0:0中的eh0:0是網卡的代號,當然你也可以用eh0:1之類的,隨你喜歡怎麼弄,但在eh0:X之前必須有ifcfg,也就是下面這種形式的,我們以eh0:0為例。    [root@Linuxsir root]#cp ifcfg-eth0 ifcfg-eth0:0    3,編輯ifcfg-eth0:0  [root@Linuxsir root]# vi ifcfg-eth0:0    ifcfg-eth0:0裡面有這樣的內容,你可以這樣設置,然後IP可以自己設置了。象我這樣設置也一樣。    # Please read /usr/share/doc/initscripts-*/sysconfig.txt  # for the documentation of these parameters.  USERCTL='no'  NETMASK='255.255.255.0' -》子掩碼  BOOTPROTO='static' -》協議  DEVICE='eth0:0' -》虛擬網卡的代號  IPADDR='192.168.0.9' -》我自己設定的IP  TYPE='Ethernet'  onBOOT='yes' -》是否開機激活  NETWORK='192.168.0.0' -》網域  BROADCAST='192.168.0.255' -》廣播    4.保存退出,然後運行如下的命令,來激活虛擬的網卡。  [root@Linuxsir root]# ifup eh0:0  5.我們來查看我們虛擬的網卡是不是激活了,用ifconfig,也就是下面這樣的。    [root@Linuxsir network-scripts]# ifconfig  eth0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05  inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1  RX packets:3 errors:0 dropped:0 overruns:0 frame:0  TX packets:54 errors:0 dropped:0 overruns:0 carrier:0  collisions:0 txqueuelen:100  RX bytes:180 (180.0 b) TX bytes:7157 (6.9 Kb)  Interrupt:11 Base address:0x2000    eth0:0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05  inet addr:192.168.0.9 Bcast:192.168.0.255 Mask:255.255.255.0  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1  Interrupt:11 Base address:0x2000    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:12 errors:0 dropped:0 overruns:0 frame:0  TX packets:12 errors:0 dropped:0 overruns:0 carrier:0  collisions:0 txqueuelen:0  RX bytes:846 (846.0 b) TX bytes:846 (846.0 b)    6.ping一下IP,就能知道我們做的是不是成功了。    [root@Linuxsir network-scripts]# ping 192.168.0.9  PING 192.168.0.9 (192.168.0.9) from 192.168.0.9 : 56(84) bytes of data.  64 bytes from 192.168.0.9: icmp_seq=1 ttl=255 time=0.097 ms  64 bytes from 192.168.0.9: icmp_seq=2 ttl=255 time=0.043 ms  64 bytes from 192.168.0.9: icmp_seq=3 ttl=255 time=0.043 ms  64 bytes from 192.168.0.9: icmp_seq=4 ttl=255 time=0.044 ms  64 bytes from 192.168.0.9: icmp_seq=5 ttl=255 time=0.043 ms    --- 192.168.0.9 ping statistics ---  14 packets transmitted, 14 received, 0% loss, time 12996ms  rtt min/avg/max/mdev = 0.039/0.046/0.097/0.016 ms    [root@Linuxsir network-scripts]# ping 192.168.0.1  PING 192.168.0.1 (192.168.0.1) from 192.168.0.1 : 56(84) bytes of data.  64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.069 ms  64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.042 ms  64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.040 ms  64 bytes from 192.168.0.1: icmp_seq=4 ttl=255 time=0.042 ms    --- 192.168.0.1 ping statistics ---  7 packets transmitted, 7 received, 0% loss, time 5995ms  rtt min/avg/max/mdev = 0.040/0.046/0.069/0.009 ms




Copyright © Linux教程網 All Rights Reserved