Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of specifying source ip for ping operation under Linux

Shulou Source: shulou.com Published: 2022-06-02 02:22:00 10月04日 Update

[preface]

Communication between two virtual machines on a computer is currently being done.

For each virtual machine, there are two network cards, one bridge mode and one NAT mode.

So here's the problem.

If you use a simple command in the form of ping ip to get the result of ping, which can only prove that two virtual machines can communicate with ping, which network card is used to ping another virtual machine?

[answer]

The ping instruction takes parameters to specify the source ip to ping the destination ip.

The form is as follows: ping-I 192.168.195.130 192.168.195.132

(192.168.195.130 is the source ip,192.168.195.132 is the destination ip)

[example]

The two virtual machines are configured as follows:

Virtual machine 1: (the picture only intercepts part of the information)

Virtual machine 2:

Network card on ping virtual machine 2 on virtual machine 1 (the picture only intercepts part of the information)

PS: the orange part represents the ping instruction, the first ip address is ip on virtual machine 1, and the second ip address is ip on virtual machine 2.

You can see that when the two ip are ip of the same network segment, they will communicate with each other through ping, and when the network segment is different, the ping will not be connected.

Network card on ping virtual machine 1 on virtual machine 2:

PS: the result of ping on virtual machine 2 is exactly the same as that of 1.

If you do not use the I parameter, ping 192.168.195.132 and ping 10.115.63.42 directly on the virtual machine or ping 192.168.195.130 and ping 10.115.63.53 on virtual machine 2 can get the ping result. However, using the I parameter, you can know more clearly which network cards in the two virtual machines are ping each other.

[conclusion] under normal conditions, the network cards of the same network segment can be connected by ping, but the network cards of different network segments can not communicate with ping.

The method of specifying the source ip for ping operation under the above Linux is all the content that the editor has shared with you. I hope I can give you a reference and support it.

Tags: Network card two network segment parameter result part different information picture address form instruction mode purpose method content just command instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Docker Microsoft Linux