您好,登錄后才能下訂單哦!
有些時候,在我們內(nèi)網(wǎng)服務(wù)中,如果不想使用路由功能,又想讓某些服務(wù)器能夠跨網(wǎng)絡(luò)服務(wù),那么此時,就需要在服務(wù)器網(wǎng)卡上配置多個IP地址,讓它能夠提供多個網(wǎng)絡(luò)的訪問,那么在linux下該如何實現(xiàn)了,今天就給大家分享一下。
操作步驟
1、cp eth0 eth0:1將網(wǎng)卡接口配置文件復(fù)制一份命名為eth0:1
2、修改網(wǎng)卡的具體配置信息
注意:eth0可以用DHCP,可以靜態(tài)配置
eth0:1只能用靜態(tài)配置
既然我們是服務(wù)器,當(dāng)然兩個配置都使用靜態(tài)IP最好了
3、重啟網(wǎng)絡(luò)服務(wù)(確保NetworkManager服務(wù)處于停止?fàn)顟B(tài))
4、驗證最終效果
第一步:cp eth0 eth0:1將網(wǎng)卡接口配置文件復(fù)制一份命名為eth0:1
[root@Centos6 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1
第二步:修改網(wǎng)卡的具體配置信息
[root@Centos6 network-scripts]# vim ifcfg-eth0
[root@Centos6 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
IPADDR=10.1.253.253
PREFIX=16
[root@Centos6 network-scripts]# cat ifcfg-eth0:1
DEVICE=eth0:1
BOOTPROTO=none
IPADDR=192.168.253.253
PREFIX=24
[root@Centos6 network-scripts]#
第三步:重啟網(wǎng)絡(luò)服務(wù)(確保NetworkManager服務(wù)處于停止?fàn)顟B(tài))
注意系統(tǒng)默認(rèn)會開啟NetworkManager服務(wù),要想啟用單網(wǎng)卡雙IP,最好先關(guān)閉,否則會不生效
[root@Centos6 network-scripts]# service NetworkManager status
NetworkManager is stopped
[root@Centos6 network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.1.253.253 is already in use for device eth0...
Determining if ip address 192.168.253.253 is already in use for device eth0...
[ OK ]
[root@Centos6 network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:C8:72:26
inet addr:10.1.253.253 Bcast:10.1.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fec8:7226/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1185 errors:0 dropped:0 overruns:0 frame:0
TX packets:366 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:107195 (104.6 KiB) TX bytes:38655 (37.7 KiB)
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:C8:72:26
inet addr:192.168.253.253 Bcast:192.168.253.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
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:260 errors:0 dropped:0 overruns:0 frame:0
TX packets:260 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:18160 (17.7 KiB) TX bytes:18160 (17.7 KiB)
[root@Centos6 network-scripts]#
第四步:驗證最終效果,從Centos7去pingCentos6上配置的雙IP
[root@centos7 network-scripts]# ifconfig
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.254.254 netmask 255.255.0.0 broadcast 10.1.255.255
inet6 fe80::20c:29ff:fe06:f987 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:06:f9:87 txqueuelen 1000 (Ethernet)
RX packets 133425 bytes 10462696 (9.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 61400 bytes 6585145 (6.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno16777728:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.253.254 netmask 255.255.255.0 broadcast 192.168.253.255
ether 00:0c:29:06:f9:87 txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 2496 bytes 234576 (229.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2496 bytes 234576 (229.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@centos7 network-scripts]# ping -c 4 10.1.253.253
PING 10.1.253.253 (10.1.253.253) 56(84) bytes of data.
64 bytes from 10.1.253.253: icmp_seq=1 ttl=64 time=3.41 ms
64 bytes from 10.1.253.253: icmp_seq=2 ttl=64 time=0.536 ms
64 bytes from 10.1.253.253: icmp_seq=3 ttl=64 time=0.539 ms
64 bytes from 10.1.253.253: icmp_seq=4 ttl=64 time=0.738 ms
--- 10.1.253.253 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3029ms
rtt min/avg/max/mdev = 0.536/1.306/3.413/1.219 ms
[root@centos7 network-scripts]# ping -c 4 192.168.253.254
PING 192.168.253.254 (192.168.253.254) 56(84) bytes of data.
64 bytes from 192.168.253.254: icmp_seq=1 ttl=64 time=0.135 ms
64 bytes from 192.168.253.254: icmp_seq=2 ttl=64 time=0.126 ms
64 bytes from 192.168.253.254: icmp_seq=3 ttl=64 time=0.126 ms
64 bytes from 192.168.253.254: icmp_seq=4 ttl=64 time=0.128 ms
--- 192.168.253.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3017ms
rtt min/avg/max/mdev = 0.126/0.128/0.135/0.014 ms
[root@centos7 network-scripts]#
可以看出,兩個IP地址都可以ping通,所以如果是跨網(wǎng)絡(luò)服務(wù)時,單網(wǎng)卡雙IP的功效就體現(xiàn)出來了。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。