6

Is it possible to put a real IP (not in the 127.x.x.x) range on a loopback device?

  • Yes, of course. – Ipor Sircer Nov 28 '17 at 12:35
  • 3
    ... a danger is of course that you forget this IP is there and then you have head-scratching networking issues as the packets don't go to the expected public IP address ... – thrig Nov 28 '17 at 13:40
3

Nothing forbids to do it.

# ifconfig lo:1 10.0.0.1/8
# ifconfig lo:1
lo:1      Link encap:Local Loopback  
          inet addr:10.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
# ping -c 1 10.0.0.1    
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.025 ms

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.025/0.025/0.025/0.000 ms

Update:

For this address to persist after a reboot on Ubuntu 16.04, you can modify your /etc/network/interfaces file with these ethtool commands:

auto lo lo:1

iface lo inet loopback

iface lo:1 inet static
  address 10.0.0.1
  network 10.0.0.0
  netmask 255.0.0.0
  • Does this persist after a reboot? – Peter Smit Nov 29 '17 at 17:02
  • No. Better to state the precise OS / distribution you are using to get a reliable answer, and possibly ask a new question or check if it hasn't already be answered. – jlliagre Nov 29 '17 at 19:12
  • Ubuntu 16.04 LTS – Peter Smit Nov 29 '17 at 19:51
  • Answer updated. – jlliagre Nov 29 '17 at 20:49
3

On the current Linux kernel with the ip utility it is quite simple:

ip addr add 10.0.1.8 dev lo

This can be useful when you have a service that binds a port on an interface, and want to run a different program on the same port and network. I use it to enable both bind and dnsmasq to co-exist on the same server.

If you are using /etc/network/interfaces to configure your interfaces, then update the lo stanza to include:

up ip addr add 10.0.1.8 dev lo
  • Thanks. Will this persist reboots? – Peter Smit Nov 29 '17 at 17:02
  • 1
    @PeterSmit Unlikely. – Kusalananda Feb 3 '18 at 8:34
2

As an alternative to using lo:0, you can also use dummy interfaces in Linux as in:

ifconfig dummy0 10.0.0.1/32
ifconfig dummy1 10.1.1.1/24

In addition to others answers:

  • I do not recommend changing the usual/official loopback interface address as a lot of functionality depends on it;
  • however, you can have/create several loopback/dummy interfaces - either lo:0 to lo:255 or dummyX interfaces;
  • it has to be taken into account that lo:0 to lo:255 are aliases, whilst dummyX are full interfaces;
  • moreover, one of the usual tactics in Linux for creating virtual IPs over BGP or OSPF is assigning them to loopback/dummy interfaces AND making pathways to them via routing;
  • again, some daemons have problems with announcing addresses in aliases (for instance, quagga ) - so dummyX interfaces are advised in those cases;
  • I would stress that without routing in the infrastructure, such addresses are only known/capable of being used in the server in question;
  • assigning a private/public address to a loopback interface, without the proper routing can be a temporary low computing cost measure to blacklist communications temporarily with an IP address/network.

For more details, see for instance a BIND anycast setup tutorial done with Quagga/BIRD.

routing clues here: OSPF: Migrating Quagga to BIRD

P.S. Linux by default only creates dummy0 and dummy1 and has to be instructed to create a bigger number of dummy interfaces.

  • 1
    I'm absolutely going to use this with (static) routing. Is there any real difference between dummy and loopback interfaces? – Peter Smit Nov 29 '17 at 17:03
  • @PeterSmit assigning vips to the loopback with be dealing with aliases of an interface, while dummy are full interfaces on their own right. there were issues using interface aliases with quagga...and I do not recommend changing lo . It also happens often you can/have to associate fw rules w/ an actual interface and not an alias. – Rui F Ribeiro Nov 29 '17 at 22:09
1

Yes, but that doesn't mean it's a good idea. If you use an IP that is ever going to be accessed by your system, any data that it tries to send there will be redirected to the local system instead, which can cause all kinds of odd networking issues. This means in particular that you can't safely use anything outside of the following ranges:

127.0.0.0/8
192.0.2.0/24
198.51.100.0/24
203.0.113.0/24
240.0.0.0/4

With the possible exception of any of the following dependent on how your other network interfaces are configured:

10.0.0.0/8
192.168.0.0/16
172.16.0.0/12
169.254.0.0/16

This is a case where RFC 1925, section 2, item 3 applies.

  • Actually, there are more ranges. In my case, it would be in the 100.64.0.0/10 range (Carrier Grade NAT) – Peter Smit Nov 29 '17 at 17:02
  • 1
    There may be more, but most of them are not widely used on client systems (I think the CGN range probably fits that), or they have ill-defined uses that many people may not understand (like 198.18.0.0/15, used for benchmarking), and I wanted to avoid saying something that might not be reasonably safe was in fact safe. – Austin Hemmelgarn Nov 29 '17 at 17:48

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.