loopback

Published: 05-07-2020

Updated: 05-07-2020

By: Maxime de Roucy

tags: network system

L’interface loopback est spécial dans le sens ou :

lo is special in that it will answer for an address belonging to a network configured on it. So if you add 192.168.40.1/24 it will actually respond to any 192.168.40.* address, not just .1

max@test % sudo ip a add 172.16.0.1/16 dev lo
max@test % ping 172.16.0.2
PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data.
64 bytes from 172.16.0.2: icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from 172.16.0.2: icmp_seq=2 ttl=64 time=0.100 ms
^C
--- 172.16.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1022ms
rtt min/avg/max/mdev = 0.047/0.073/0.100/0.026 ms
max@test % nc -l 172.16.0.2 1234 &
max@test % nc -vz 172.16.0.1 1234
nc: connect to 172.16.0.1 port 1234 (tcp) failed: Connection refused
max@test % nc -vz 172.16.0.2 1234
Connection to 172.16.0.2 1234 port [tcp/search-agent] succeeded!