2

I would like to know whats the differences between loopback and dummy interfaces in Ubuntu and how they behave.

Because when I assign /24 IP address on Loopback interface and route this range in my network, the server responds to all IP addresses even to those ip addresses which is not assigned to the interface. But dummy interface behave like physical interface and responds to specific IP address which I've assigned to the interface.

1 Answer 1

3

Contrary to other interfaces, when the Linux kernel adds an address to the loopback interface, its LAN route as also added as type local and scope host (these are what matter) to the local routing table (this is what makes it harder to find), instead of the main routing table.

To check the difference, check all routing tables entries (table all) that were added by the kernel (proto kernel) and are of type local.

From a system with only lo up and nothing else done:

# ip route show proto kernel type local table all local 127.0.0.0/8 dev lo table local scope host src 127.0.0.1 local 127.0.0.1 dev lo table local scope host src 127.0.0.1 # 

Here all addresses in the range 127.0.0.0/8 belong to the host (scope host).

Create dummy0 and an address on it:

# ip link add name dummy0 up type dummy # ip addr add 192.0.2.2/24 dev dummy0 # ip route show proto kernel type local table all local 127.0.0.0/8 dev lo table local scope host src 127.0.0.1 local 127.0.0.1 dev lo table local scope host src 127.0.0.1 local 192.0.2.2 dev dummy0 table local scope host src 192.0.2.2 # ip route 192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.2 # 

Instead add it on lo

# ip addr flush dev dummy0 # ip addr add 192.0.2.2/24 dev lo # ip route show proto kernel type local table all local 127.0.0.0/8 dev lo table local scope host src 127.0.0.1 local 127.0.0.1 dev lo table local scope host src 127.0.0.1 local 192.0.2.0/24 dev lo table local scope host src 192.0.2.2 local 192.0.2.2 dev lo table local scope host src 192.0.2.2 # ip route # 

This time 192.0.2.0/24 is of scope host, making the whole range belong to the host just as 127.0.0.0/8, instead of only 192.0.2.2 (/32) in the previous results. Linux following the Weak Host Model, will answer for these addresses for requests made on any interface, including ARP requests when relevant.


There are multiple ways to obtain the same results. So what can or should be used depends on the goal to achieve. pro and con below aren't always pro and con, but that's to compare them.

  • dummy0

    • pro (for something else than dummy)

      • if routing/forwarding is enabled, the kernel, having by default added an automatic (proto kernel) LAN route will route received packets to this interface if not its own address. Doesn't make much sense for a dummy interface though, since traffic will be discarded. Yet using a dummy interface could be one way to blackhole a route (one other more permanent way being to add a route of type blackhole which doesn't rely on an interface).
    • con

      • one address. Multiple commands/operations are needed to add multiple addresses, one per command.
  • lo

    • pro

      • add a whole range of host addresses in one swoop

        This should be reserved to projects related to intercepting traffic on a large scale. Note that what matters is the route added by the kernel, not the address itself. Such route is used for example by Linux' tproxy for transparent proxying:

        # ip rule add fwmark 1 lookup 100 # ip route add local 0.0.0.0/0 dev lo table 100 

        but with specific policy-routing rules in place so it doesn't always apply.

        Outside of this, just add /32 addresses when using lo if it's ever done.

      • permanent interface, neutral role

        This interface is guaranteed to exist, so can be used as an anchor to add addresses in advance without knowing what interface will exist or should be used. The routes related to this address won't change when an interface goes down, since it's on lo (which has no reason to go down). Some routing daemons might handle in a special way addresses added on the loopback interface.

    • con

      • cannot be used for static routing/forwarding

        Routes added for the lo interface are not meant to route elsewhere: the target is the host.

4
  • How can I configure this for dummy interface: pro (for something else than dummy) Commented Feb 24, 2024 at 13:44
  • @MesbahAhmadi can you be more specific? I did answer your question. But you don't provide any information on why you're asking your question. Beware of the XY problem. If you have a reasonable additional request in your question, please edit your question and add it there. Else consider if my answer answered your question or not: if so, ponder accepting my answer, if not: explain why not. Commented Feb 24, 2024 at 18:09
  • You explain very clear and it is useful. But I want to know how can I configure dummy interface as act like loopback Interface. Is there any way ? Commented Feb 24, 2024 at 20:45
  • I don't see where you're going at but you can add manually the routes yourself instead of letting the kernel do it. ip addr add 192.0.2.2/24 dev dummy0 noprefixroute; ip route add local 192.0.2.0/24 dev dummy0 Commented Feb 24, 2024 at 22:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.