内网无路由跨网络服务——单网卡双IP配置-创新互联
有些时候,在我们内网服务中,如果不想使用路由功能,又想让某些服务器能够跨网络服务,那么此时,就需要在服务器网卡上配置多个IP地址,让它能够提供多个网络的访问,那么在linux下该如何实现了,今天就给大家分享一下。
我们拥有十年网页设计和网站建设经验,从网站策划到网站制作,我们的网页设计师为您提供的解决方案。为企业提供网站设计、成都做网站、微信开发、小程序开发、手机网站开发、H5高端网站建设、等业务。无论您有什么样的网站设计或者设计方案要求,我们都将富于创造性的提供专业设计服务并满足您的需求。操作步骤
1、cp eth0 eth0:1将网卡接口配置文件复制一份命名为eth0:1
2、修改网卡的具体配置信息
注意:eth0可以用DHCP,可以静态配置
eth0:1只能用静态配置
既然我们是服务器,当然两个配置都使用静态IP最好了
3、重启网络服务(确保NetworkManager服务处于停止状态)
4、验证最终效果
第一步:cp eth0 eth0:1将网卡接口配置文件复制一份命名为eth0:1
[root@Centos6 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1
第二步:修改网卡的具体配置信息
[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]#
第三步:重启网络服务(确保NetworkManager服务处于停止状态)
注意系统默认会开启NetworkManager服务,要想启用单网卡双IP,最好先关闭,否则会不生效
[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
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
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
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
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
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通,所以如果是跨网络服务时,单网卡双IP的功效就体现出来了。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:内网无路由跨网络服务——单网卡双IP配置-创新互联
网页链接:http://myzitong.com/article/gdsss.html