The loopback networking interface

is a virtual network device implemented entirely in software.

But how is this implementation actually accomplished and how do you manipulate it?

As far as I know, IPs are marked as local in the local routing table:

ip route show table local  

Sending to an IP marked as local will trigger the loopback device. But is this detection done by purely by routing tables or also by some other kernel operations?

Edit: My ultimate goal is to manipulate the loop-device configuration, so that sending datagrams among my interfaces (two wlan adapters) on my laptop will result in real traffic / datagrams in the network and not in local loops. Interface 1 -> WLAN -> Interface 2 and NOT: Interface 1 -> LOOP -> Interface 2


It's entirely handled through the routing tables.

It's pretty easy to try out in a virtual machine, if you want to have fun. I don't take responsibility for anything that might happen on the machine where you try this.

First let's change the netmask of lo to

sudo ip addr del dev lo; sudo ip addr add dev lo

Now let's look at our lo:

$ ip -4 addr show dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    inet scope host lo

Where would packets to go?

$ sudo ip route get via dev eth0  src 
    cache  mtu 1500 advmss 1460 hoplimit 64

We start pinging in another terminal:

$ ping

Let's monitor ICMP traffic on eth0:

$ sudo tcpdump -i eth0 icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
07:28:42.060077 IP > ICMP echo request, id 5665, seq 4, length 64
07:28:43.059920 IP > ICMP echo request, id 5665, seq 5, length 64

I'll leave you with the exercise of changing the netmask of lo on a remote machine to and adding the IP address to their network interface. You can see ICMP replies coming back. Note that routers might not play nicely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.