Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Intranet non-routing cross-network service-- single Nic and dual IP configuration

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Sometimes, in our intranet service, if you do not want to use the routing function, but also want some servers to be able to serve across the network, then you need to configure multiple IP addresses on the server Nic so that it can provide access to multiple networks. Then how to implement it under linux will be shared with you today.

Operation steps

1. Cp eth0 eth0:1 will make a copy of the interface configuration file of the network card and name it eth0:1

2. Modify the specific configuration information of the network card

Note: eth0 can be configured with DHCP and statically

Eth0:1 can only be configured statically

Since we are servers, of course it is best to use static IP in both configurations

3. Restart the network service (make sure the NetworkManager service is stopped)

4. Verify the final effect

Step 1: cp eth0 eth0:1 will make a copy of the Nic interface configuration file and name it eth0:1

[root@Centos6 network-scripts] # cp ifcfg-eth0 ifcfg-eth0:1

Step 2: modify the specific configuration information of the network card

[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] #

Step 3: restart the network service (make sure the NetworkManager service is stopped)

Note that the NetworkManager service is enabled by default. If you want to enable double IP with a single network card, you'd better turn it off first, otherwise it will not take effect.

[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] #

Step 4: verify the final effect, go from Centos7 to the dual IP configured on pingCentos6

[root@centos7 network-scripts] # ifconfig

Eno16777728: flags=4163 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

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.2MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Eno16777728:1: flags=4163 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 mtu 65536

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.536max 1.306max 3.413max 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.126max 0.128max 0.135max 0.014 ms

[root@centos7 network-scripts] #

It can be seen that both IP addresses can be ping-connected, so if it is a cross-network service, the effect of single network card and double IP will be reflected.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report