Coming from a networking background, it's very common to create loopback interfaces on devices to use for management for example. Because it's so common, it's also incredibly easy. On Cisco IOS for example I can have loopback up and running in two commands:
ip address 10.0.0.1 255.255.255.255
So much to my dismay, when I started messing around with loopbacks on Ubuntu it was not such a friendly experience.
The best option I found to achieve the result is to use dummy interfaces. These are not enabled by default, so lets look at enabling the drivers for them.
You can see if they are loaded by doing:
root@tayles-rtr-fra1:~# lsmod | grep dummy root@tayles-rtr-fra1:~#
It returned nothing so it is not enabled. Luckily, enabling is pretty easy:
root@tayles-rtr-fra1:~# modprobe dummy root@tayles-rtr-fra1:~# lsmod | grep dummy dummy 16384 0 root@tayles-rtr-fra1:~#
But that's only enabled to the next reboot, which is not good. So to make it persistent open "/etc/modules" with your favourite text editor and add "dummy" to the end of the file:
root@tayles-rtr-fra1:~# vim /etc/modules # /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. dummy
Next, we need to actually create a fake interface and bring it up on start-up. To do this, use a text editor to edit "/etc/rc.local" and add the following lines before the "exit 0" statement.
ip link set name eth10 dev dummy0 ifup eth10
This will ensure it comes up at boot, but if you want to bring it up without rebooting, simply run the above as commands.
Next, we need to edit the interfaces config to give the interface some config. Here is my config, just edit as you see fit. Adding "eth10" to the auto line is important, make sure you don't miss it. If you don't want IPv6 just remove that whole section:
auto lo eth10 iface lo inet loopback iface eth10 inet static address 172.20.227.164 netmask 255.255.255.255 network 172.20.227.164 dns-nameservers 172.23.0.53 iface eth10 inet6 static address fd00:9990::2 netmask 128
To apply this config, either restart or use "ifdown eth10 && ifup eth10".
Now you have a working "fake" ethernet interface that can be used as a loopback!
root@tayles-rtr-fra1:~# ifconfig eth10 eth10 Link encap:Ethernet HWaddr 56:a8:f6:3e:c0:58 inet addr:172.20.227.164 Bcast:172.20.227.164 Mask:255.255.255.255 inet6 addr: fe80::54a8:f6ff:fe3e:c058/64 Scope:Link inet6 addr: fd00:9990::2/128 Scope:Global UP BROADCAST RUNNING NOARP MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:48 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:4794 (4.7 KB)