内网无路由跨网络服务——单网卡双IP配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内网无路由跨网络服务——单网卡双IP配置相关的知识,希望对你有一定的参考价值。

    有些时候,在我们内网服务中,如果不想使用路由功能,又想让某些服务器能够跨网络服务,那么此时,就需要在服务器网卡上配置多个IP地址,让它能够提供多个网络的访问,那么在linux下该如何实现了,今天就给大家分享一下。


操作步骤

1、cp eth0 eth0:1将网卡接口配置文件复制一份命名为eth0:1

2、修改网卡的具体配置信息

注意:eth0可以用DHCP,可以静态配置

 eth0:1只能用静态配置

 既然我们是服务器,当然两个配置都使用静态IP最好了

3、重启网络服务(确保NetworkManager服务处于停止状态)

4、验证最终效果


第一步:cp eth0 eth0:1将网卡接口配置文件复制一份命名为eth0:1

[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1


第二步:修改网卡的具体配置信息

[[email protected] network-scripts]# vim ifcfg-eth0

[[email protected] network-scripts]# cat ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

IPADDR=10.1.253.253

PREFIX=16

[[email protected] network-scripts]# cat ifcfg-eth0:1

DEVICE=eth0:1

BOOTPROTO=none

IPADDR=192.168.253.253

PREFIX=24

[[email protected] network-scripts]# 


第三步:重启网络服务(确保NetworkManager服务处于停止状态)

注意系统默认会开启NetworkManager服务,要想启用单网卡双IP,最好先关闭,否则会不生效

[[email protected] network-scripts]# service NetworkManager status

NetworkManager is stopped


[[email protected] 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  ]


[[email protected] 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)


[[email protected] network-scripts]# 


第四步:验证最终效果,从Centos7去pingCentos6上配置的双IP

[[email protected] 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


[[email protected] 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

[[email protected] 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

[[email protected] network-scripts]# 

可以看出,两个IP地址都可以ping通,所以如果是跨网络服务时,单网卡双IP的功效就体现出来了。


本文出自 “爱情防火墙” 博客,请务必保留此出处http://183530300.blog.51cto.com/894387/1846131

以上是关于内网无路由跨网络服务——单网卡双IP配置的主要内容,如果未能解决你的问题,请参考以下文章

Linux双网卡内外网服务器IP配置?

2008R2 双网卡 设置问题

求助:双网卡route命令设置不能用

在linux系统下配置双网卡,一个内网一个外网,能够是两个都通,怎么配

Linux多网卡外网访问策略路由设置

Squid代理应用