Configure virtual IP addresses in Ubuntu

Source: Internet
Author: User
The purpose of configuring a virtual IP address is to achieve high availability. After that, let's take a look at how to set a virtual IP address in Ubuntu12.04. First, let's take a look at my Ubuntu IP: chenshu @ sloop2 :~ $ Ifconfigeth0Linkencap: Ethernet & nbs

The purpose of configuring a virtual IP address is to achieve high availability. After that, let's take a look at how to set a virtual IP address in Ubuntu 12.04.

First, let's take a look at my Ubuntu IP:

  1. Chenshu @ sloop2 :~ $ Ifconfig
  2. Eth0 Link encap: Ethernet HWaddr d0: 67: e5: ef: 5a: 6e
  3. Inet addr: 10.112.18.158 Bcast: 10.112.18.255 Mask: 255.255.255.0
  4. Inet6 addr: fe80: d267: e5ff: feef: 5a6e/64 Scope: Link
  5. Up broadcast running multicast mtu: 1500 Metric: 1
  6. RX packets: 341661 errors: 0 dropped: 0 overruns: 0 frame: 0
  7. TX packets: 242801 errors: 0 dropped: 0 overruns: 0 carrier: 0
  8. Collisions: 0 FIG: 1000
  9. RX bytes: 328287656 (328.2 MB) TX bytes: 31858367 (31.8 MB)
  10. Interrupt: 17
  11. Lo Link encap: Local Loopback
  12. Inet addr: 127.0.0.1 Mask: 255.0.0.0
  13. Inet6 addr: 1/128 Scope: Host
  14. Up loopback running mtu: 16436 Metric: 1
  15. RX packets: 17904 errors: 0 dropped: 0 overruns: 0 frame: 0
  16. TX packets: 17904 errors: 0 dropped: 0 overruns: 0 carrier: 0
  17. Collisions: 0 txqueuelen: 0
  18. RX bytes: 2160236 (2.1 MB) TX bytes: 2160236 (2.1 MB)
Ping 191 and find that the network does not exist. Use it as a virtual IP address.

Run the following command after sudo-s,

  1. Ifconfig eth0: 0 10.112.18.191 netmask 255.255.255.0 up
Make sure that the virtual IP address and the local IP address are in one CIDR block.

Let's see if it is successful:

  1. Ifconfig
  2. Eth0 Link encap: Ethernet HWaddr d0: 67: e5: ef: 5a: 6e
  3. Inet addr: 10.112.18.158 Bcast: 10.112.18.255 Mask: 255.255.255.0
  4. Inet6 addr: fe80: d267: e5ff: feef: 5a6e/64 Scope: Link
  5. Up broadcast running multicast mtu: 1500 Metric: 1
  6. RX packets: 347634 errors: 0 dropped: 0 overruns: 0 frame: 0
  7. TX packets: 246488 errors: 0 dropped: 0 overruns: 0 carrier: 0
  8. Collisions: 0 FIG: 1000
  9. RX bytes: 335797145 (335.7 MB) TX bytes: 32178089 (32.1 MB)
  10. Interrupt: 17
  11. Eth0: 0 Link encap: Ethernet HWaddr d0: 67: e5: ef: 5a: 6e
  12. Inet addr: 10.112.18.191 Bcast: 10.112.18.255 Mask: 255.255.255.0
  13. Up broadcast running multicast mtu: 1500 Metric: 1
  14. Interrupt: 17
  15. Lo Link encap: Local Loopback
  16. Inet addr: 127.0.0.1 Mask: 255.0.0.0
  17. Inet6 addr: 1/128 Scope: Host
  18. Up loopback running mtu: 16436 Metric: 1
  19. RX packets: 17953 errors: 0 dropped: 0 overruns: 0 frame: 0
  20. TX packets: 17953 errors: 0 dropped: 0 overruns: 0 carrier: 0
  21. Collisions: 0 txqueuelen: 0
  22. RX bytes: 2164072 (2.1 MB) TX bytes: 2164072 (2.1 MB)
Local test:
  1. Ping 10.112.18.191
  2. PING 10.112.18.191 (10.112.18.191) 56 (84) bytes of data.
  3. 64 bytes from 10.112.18.191: icmp_req = 1 ttl = 64 time = 0.028 MS
Test the replacement machine:
  1. Edward @ edward-catamaran :~ $ Ping 10.112.18.191
  2. PING 10.112.18.191 (10.112.18.191) 56 (84) bytes of data.
  3. 64 bytes from 10.112.18.191: icmp_req = 1 ttl = 64 time = 0.916 MS
  4. 64 bytes from 10.112.18.191: icmp_req = 2 ttl = 64 time = 0.258 MS

Delete a virtual IP address.

Ifconfig eth0: 0 down


What should I do later? Of course, the configuration is saved to ensure that the virtual IP address is still there after restart.

Directly Add the following content to the/etc/network/interfaces file:

  1. Auto lo
  2. Iface lo inet loopback
  3. Auto eth0: 0
  4. Iface eth0: 0 inet static
  5. Name Ethernet alias LAN card
  6. Address 10.112.18.191
  7. Netmask 255.255.255.0
  8. Broadcast 10.112.18.255
  9. Network 10.112.18.0

Restart the network service.

/Etc/init. d/networking restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.