3

I'm trying to alias an ip address onto Lo or create a new loopback interface such as lo:1

I've created /etc/sysconfig/network-scripts/ifcfg-lo:10

DEVICE=lo:10
IPADDR=192.168.10.1
NETMASK=255.255.255.0
NETWORK=192.168.10.0
BROADCAST=192.168.10.255
ONBOOT=yes
NAME=lo10

When I do ifup lo:10

[root@xxxx network-scripts]# ifup lo:10
Error: no device found for connection 'lo10'.

Can anyone please shed some light on this issue. I have used this method for aliasing ip addresses on physical interfaces without issues.

This is not a duplicate as Michael has tried to point out as I'm trying the correctly documented way and would rather not use the rc.local as suggested in what he feels the same question.

MarkMcN
  • 31
  • 1
  • 1
  • 3

1 Answers1

2

The only way I have been able to get this to work is to issue a

systemctl network restart

Then you get this

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.11.1/24 brd 192.168.11.255 scope global lo0:10

You can though just add an IP address to lo nd you don't need to create a new interface to do it.

ip addr add 192.168.12.1/24 dev lo 

and you get this

    inet 192.168.12.1/24 scope global lo
   valid_lft forever preferred_lft forever

On CentOS the ifup script contains this snipet

if [ -x /sbin/ifup-local ]; then
    /sbin/ifup-local ${DEVICE}
fi

So you can create a file called /etc/sysconfig/network-scripts/ifup-local and have it do things for you once the interface is up

#!/bin/sh
if [[ "$1" == "lo" ]]
then
  ip addr add 192.168.2.1/24 dev lo
else
  # do something else  
fi
user9517
  • 115,471
  • 20
  • 215
  • 297