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

The method of establishing Virtual ip by Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Introduction of virtual ip

A virtual IP address (VIP) is an IP address that is not connected to a specific computer or to a network interface card (NIC) in a computer. The packet is sent to this VIP address, but all the data goes through the real network interface.

Above is the definition of Baidu.

It means that there are two ip on a network card, and then the traffic to any ip will pass through the physical network card.

2. The function of virtual ip.

Most virtual ip is basically used on top of highly available architectures. The host enables virtual ip, and all requests for access go to the host. When the host goes down, the highly available software drops the virtual ip down of the host, and then enables the virtual ip on the standby. In this way, the switching between the active and standby is completed. In order to ensure the availability of the business.

3. The method of creating virtual ip in linux

There are two ways to create a virtual ip in linux: alias IP and secondary IP.

(1) alias ip

The alias ip is a virtual ip created and manipulated by the ifconfig command.

Create a virtual ip

Use the ifconfig command to view

Create using the command

Ifconfig eth0:1 192.168.8.5 netmask 255.255.255.0 up

Above you can see the virtual network card that generated the eth0:1 and the ip is 192.168.8.5.

Delete alias ip

Ifconfig eth0:1 192.168.8.5 netmask 255.255.255.0 down

It's very simple. Just change the following up to down.

Power on to generate virtual ip

If you want to power on the virtual ip, you can create a new configuration file of the network card in the configuration directory of the network card.

Centos and Red Hat are both in this directory / etc/sysconfig/network-scripts

Cp ifcfg-eth0 ifcfg-eth0:1

Then change the ip and restart the network card.

(2) Secondary ip

Auxiliary ip is created and operated by linux's ip command.

Create a secondary ip

Ip addr add 192.168.8.5/24 dev eth0

View secondary ip

You can view it with the command ip a, but you cannot use ifconfig-a to view it.

Delete secondary ip

Ip addr del 192.168.8.5/24 dev eth0

It's also simple, just change add to del.

Take effect permanently

For a virtual ip created in this way, the command to generate the virtual ip can be written to / etc/rc.local.

It can be loaded automatically when it is turned on. It may be used when configuring redis-sentinel.

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

Servers

Wechat

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

12
Report